diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 65961cb..40bc0cb 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -32,4 +32,7 @@ jobs: run: dotnet nuget push out/EventSauce.Extensions.Microsoft.DependencyInjection.${{ steps.vars.outputs.tag }}.nupkg -k ${{ secrets.CICD_KEY }} -s https://api.nuget.org/v3/index.json - name: Deploy NuGet Postgre Binaries - run: dotnet nuget push out/EventSauce.Postgre.${{ steps.vars.outputs.tag }}.nupkg -k ${{ secrets.CICD_KEY }} -s https://api.nuget.org/v3/index.json \ No newline at end of file + run: dotnet nuget push out/EventSauce.Postgre.${{ steps.vars.outputs.tag }}.nupkg -k ${{ secrets.CICD_KEY }} -s https://api.nuget.org/v3/index.json + + - name: Deploy NuGet MongoDB Binaries + run: dotnet nuget push out/EventSauce.MongoDB.${{ steps.vars.outputs.tag }}.nupkg -k ${{ secrets.CICD_KEY }} -s https://api.nuget.org/v3/index.json \ No newline at end of file diff --git a/EventSauce.Tests/Integration/MongoDBTests.cs b/EventSauce.Tests/Integration/MongoDBTests.cs index 497d950..447b8ff 100644 --- a/EventSauce.Tests/Integration/MongoDBTests.cs +++ b/EventSauce.Tests/Integration/MongoDBTests.cs @@ -176,5 +176,38 @@ public async Task Aggregate_WhenCreatedChangedAndSavedWithPerformedBy_ShouldRetr Assert.Equal(newEmail, repoUser?.Email); Assert.Equal(1, repoUser?.Version); } + + [Fact] + public async Task Aggregate_WhenCreatedChangedThenChangedToInvalidAndSavedWithPerformedBy_ShouldRetrieve() + { + var userId = User.NewUser(); + + const string? email = "origina@gmail.com"; + const string? auth = "auth_id"; + + var user = new UserAggregate(userId, email, auth); + + const string newEmail = "changed@gmail.com"; + const string invalidEmail = "faker_email"; + + user.ChangeEmail(newEmail); + user.ChangeEmailToInvalid(invalidEmail); + + var sut = _fixture.GetSutObject(); + + var repoUser = await sut.GetById(userId); + + Assert.Null(repoUser); + + await sut.Save(user, userId); + + repoUser = await sut.GetById(userId); + + Assert.NotNull(repoUser); + + Assert.Equal(userId, repoUser?.Id); + Assert.Equal(invalidEmail, repoUser?.Email); + Assert.Equal(2, repoUser?.Version); + } } } diff --git a/EventSauce.Tests/Integration/PostgreTests.cs b/EventSauce.Tests/Integration/PostgreTests.cs index 3e73da1..a2ca0c7 100644 --- a/EventSauce.Tests/Integration/PostgreTests.cs +++ b/EventSauce.Tests/Integration/PostgreTests.cs @@ -180,5 +180,38 @@ public async Task Aggregate_WhenCreatedChangedAndSavedWithPerformedBy_ShouldRetr Assert.Equal(newEmail, repoUser?.Email); Assert.Equal(1, repoUser?.Version); } + + [Fact] + public async Task Aggregate_WhenCreatedChangedThenChangedToInvalidAndSavedWithPerformedBy_ShouldRetrieve() + { + var userId = User.NewUser(); + + const string? email = "origina@gmail.com"; + const string? auth = "auth_id"; + + var user = new UserAggregate(userId, email, auth); + + const string newEmail = "changed@gmail.com"; + const string invalidEmail = "faker_email"; + + user.ChangeEmail(newEmail); + user.ChangeEmailToInvalid(invalidEmail); + + var sut = _fixture.GetSutObject(); + + var repoUser = await sut.GetById(userId); + + Assert.Null(repoUser); + + await sut.Save(user, userId); + + repoUser = await sut.GetById(userId); + + Assert.NotNull(repoUser); + + Assert.Equal(userId, repoUser?.Id); + Assert.Equal(invalidEmail, repoUser?.Email); + Assert.Equal(2, repoUser?.Version); + } } } diff --git a/EventSauce.Tests/Integration/TestAggregate.cs b/EventSauce.Tests/Integration/TestAggregate.cs index 5994428..2b63450 100644 --- a/EventSauce.Tests/Integration/TestAggregate.cs +++ b/EventSauce.Tests/Integration/TestAggregate.cs @@ -26,6 +26,15 @@ public void ChangeEmail(string email) }); } + public void ChangeEmailToInvalid(string email) + { + IssueEvent(new UserChangeEmailToInvalidEvent + { + Email = email, + IsValid = true + }); + } + /// /// Apply events need to be defined /// for each applicable event since this is @@ -55,6 +64,11 @@ public record UserChangeEmailEvent : SaucyEvent public string Email { get; init; } = string.Empty; } + public record UserChangeEmailToInvalidEvent : UserChangeEmailEvent + { + public bool IsValid { get; init; } = false; + } + public record User : SaucyAggregateId { public User(Guid id)