-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-introduce hybrid repo, add some tests for it
- Loading branch information
1 parent
24e6efa
commit 1e1a445
Showing
11 changed files
with
264 additions
and
45 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using System.Net; | ||
using System.Net.Http.Json; | ||
using CustomerApi.Controllers.Movies; | ||
using CustomerApi.Uris; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace CustomerApi.Tests.MovieController; | ||
|
||
public class MovieTests | ||
{ | ||
[Fact] | ||
public async Task Valid_ReturnsOkWhenUsingEventStream() | ||
{ | ||
using var customerApi = new TestCustomerApi(); | ||
await customerApi.Given.AnExistingMovie(MovieUri.Parse("/movies/ExistingMovie"), "The Matrix"); | ||
|
||
var client = customerApi.CreateClient(); | ||
|
||
var response = await client.GetAsync("/movies/ExistingMovie/by-event"); | ||
|
||
response.StatusCode.Should().Be(HttpStatusCode.OK); | ||
} | ||
|
||
[Fact] | ||
public async Task Valid_ReturnsNotFoundWhenUsingSnapshotThatIsNotEnabled() | ||
{ | ||
using var customerApi = new TestCustomerApi(); | ||
await customerApi.Given.AnExistingMovie(MovieUri.Parse("/movies/ExistingMovie"), "The Matrix"); | ||
|
||
var client = customerApi.CreateClient(); | ||
|
||
var response = await client.GetAsync("/movies/ExistingMovie/by-snapshot"); | ||
|
||
response.StatusCode.Should().Be(HttpStatusCode.NotFound); | ||
} | ||
|
||
[Fact] | ||
public async Task Valid_ReturnsOkWhenUsingHybridAndSnapshotIsNotEnabled() | ||
{ | ||
using var customerApi = new TestCustomerApi(); | ||
await customerApi.Given.AnExistingMovie(MovieUri.Parse("/movies/ExistingMovie"), "The Matrix"); | ||
|
||
var client = customerApi.CreateClient(); | ||
|
||
var response = await client.GetAsync("/movies/ExistingMovie/by-event"); | ||
|
||
response.StatusCode.Should().Be(HttpStatusCode.OK); | ||
} | ||
|
||
[Fact] | ||
public async Task Valid_SavesSnapshotWhenUsingHybridRepoToApply() | ||
{ | ||
using var customerApi = new TestCustomerApi(); | ||
var client = customerApi.CreateClient(); | ||
|
||
var response = await client.PostAsJsonAsync("/movies/create-hybrid", new { name = "Hot Fuzz" }); | ||
|
||
response.StatusCode.Should().Be(HttpStatusCode.Created); | ||
response.Headers.Location.Should().NotBeNull(); | ||
var movieUri = MovieUri.Parse(response.Headers.Location!.ToString()); | ||
await customerApi.Then.TheMovieSnapshotShouldMatch(movieUri, snapshot => snapshot.Name == "Hot Fuzz"); | ||
} | ||
|
||
[Fact] | ||
public async Task Valid_ReturnsOkWhenUsingHybridToQueryLatestChanges() | ||
{ | ||
using var customerApi = new TestCustomerApi(); | ||
var movieUri = MovieUri.Parse("/movies/ExistingMovie"); | ||
await customerApi.Given.AnExistingMovieWithAProjectedSnapshot(movieUri, "The Matrix"); | ||
await customerApi.Given.AnExistingMovieNameIsChangedButNotProjected(movieUri, "The Matrix Reloaded"); | ||
|
||
var client = customerApi.CreateClient(); | ||
|
||
var response = await client.GetAsync("/movies/ExistingMovie/by-hybrid-query"); | ||
|
||
response.StatusCode.Should().Be(HttpStatusCode.OK); | ||
var movie = await response.Content.ReadFromJsonAsync<MovieQueryResponse>(); | ||
movie.Should().NotBeNull(); | ||
movie!.Name.Should().Be("The Matrix Reloaded"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
namespace CustomerApi.Controllers.Movies; | ||
|
||
public record CreateMovieRequest(string Name); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
using CustomerApi.Uris; | ||
|
||
namespace CustomerApi.Controllers.Movies; | ||
|
||
public record MovieQueryResponse(MovieUri MovieUri, string Name); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using CustomerApi.Uris; | ||
|
||
namespace CustomerApi.Events.Movies; | ||
|
||
public class MovieNameChanged : MovieEvent | ||
{ | ||
public string Name { get; } | ||
|
||
public MovieNameChanged(MovieUri movieUri, string name, DateTimeOffset? timestamp = null) | ||
: base(movieUri, timestamp) | ||
{ | ||
Name = name; | ||
} | ||
|
||
public override void Apply(MovieReadModel model) | ||
{ | ||
model.Name = Name; | ||
} | ||
|
||
public override string GetDescription() | ||
{ | ||
return $"Movie {MovieUri} name changed to {Name}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.