Skip to content

Commit

Permalink
more event hierarchy tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Modest-as committed Nov 2, 2021
1 parent 8aef04d commit 97c8285
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
33 changes: 33 additions & 0 deletions EventSauce.Tests/Integration/MongoDBTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]";
const string? auth = "auth_id";

var user = new UserAggregate(userId, email, auth);

const string newEmail = "[email protected]";
const string invalidEmail = "faker_email";

user.ChangeEmail(newEmail);
user.ChangeEmailToInvalid(invalidEmail);

var sut = _fixture.GetSutObject();

var repoUser = await sut.GetById<UserAggregate>(userId);

Assert.Null(repoUser);

await sut.Save(user, userId);

repoUser = await sut.GetById<UserAggregate>(userId);

Assert.NotNull(repoUser);

Assert.Equal(userId, repoUser?.Id);
Assert.Equal(invalidEmail, repoUser?.Email);
Assert.Equal(2, repoUser?.Version);
}
}
}
33 changes: 33 additions & 0 deletions EventSauce.Tests/Integration/PostgreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]";
const string? auth = "auth_id";

var user = new UserAggregate(userId, email, auth);

const string newEmail = "[email protected]";
const string invalidEmail = "faker_email";

user.ChangeEmail(newEmail);
user.ChangeEmailToInvalid(invalidEmail);

var sut = _fixture.GetSutObject();

var repoUser = await sut.GetById<UserAggregate>(userId);

Assert.Null(repoUser);

await sut.Save(user, userId);

repoUser = await sut.GetById<UserAggregate>(userId);

Assert.NotNull(repoUser);

Assert.Equal(userId, repoUser?.Id);
Assert.Equal(invalidEmail, repoUser?.Email);
Assert.Equal(2, repoUser?.Version);
}
}
}
14 changes: 14 additions & 0 deletions EventSauce.Tests/Integration/TestAggregate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ public void ChangeEmail(string email)
});
}

public void ChangeEmailToInvalid(string email)
{
IssueEvent(new UserChangeEmailToInvalidEvent
{
Email = email,
IsValid = true
});
}

/// <summary>
/// Apply events need to be defined
/// for each applicable event since this is
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 97c8285

Please sign in to comment.