-
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure that the new aggregate has an id. Proposed fix for #75
- Loading branch information
1 parent
93cbb3b
commit 074fb9a
Showing
5 changed files
with
53 additions
and
10 deletions.
There are no files selected for viewing
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
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,36 @@ | ||
using Eventuous.Tests.Fixtures; | ||
|
||
namespace Eventuous.Tests; | ||
|
||
public class ForgotToSetId : NaiveFixture { | ||
public ForgotToSetId() => Service = new TestService(this.AggregateStore); | ||
|
||
[Fact] | ||
public async Task ShouldFailWithNoId() { | ||
var cmd = new DoIt(Auto.Create<string>()); | ||
var result = await Service.Handle(cmd, default); | ||
result.Success.Should().BeFalse(); | ||
(result as ErrorResult<TestState, TestId>)!.Exception.Should().BeOfType<Exceptions.InvalidIdException>(); | ||
} | ||
|
||
TestService Service { get; } | ||
|
||
class TestService : ApplicationService<TestAggregate, TestState, TestId> { | ||
public TestService(IAggregateStore store) : base(store) | ||
=> OnNew<DoIt>((test, cmd) => test.DoIt(new TestId(cmd.Id))); | ||
} | ||
|
||
record DoIt(string Id); | ||
|
||
class TestAggregate : Aggregate<TestState, TestId> { | ||
public void DoIt(TestId id) => Apply(new TestEvent(id)); | ||
} | ||
|
||
record TestState : AggregateState<TestState, TestId>; | ||
|
||
record TestId : AggregateId { | ||
public TestId(string value) : base(value) { } | ||
} | ||
|
||
record TestEvent(string Id); | ||
} |