-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
229 additions
and
28 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
12 changes: 8 additions & 4 deletions
12
...p.Domain/AircraftContext/Aggregates/AircraftAggregate/Commands/CorrectTotalFlightCount.cs
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 |
---|---|---|
@@ -1,16 +1,20 @@ | ||
using FluentResults; | ||
using Skyhop.Domain.AircraftContext.Aggregates.AircraftAggregate.Events; | ||
using Whaally.Domain.Abstractions.Command; | ||
|
||
namespace Skyhop.Domain.AircraftContext.Aggregates.AircraftAggregate.Commands; | ||
|
||
[Immutable] | ||
[GenerateSerializer] | ||
public record CorrectTotalFlightCount( | ||
int FlightCount, | ||
string Reason) : ICommand; | ||
int FlightCount) : ICommand; | ||
|
||
public class CorrectTotalFlightCountHandler : ICommandHandler<Aircraft, CorrectTotalFlightCount> | ||
{ | ||
public IResultBase Evaluate(ICommandHandlerContext<Aircraft> context, CorrectTotalFlightCount command) | ||
=> Result.Ok(); | ||
} | ||
{ | ||
context.StageEvent(new TotalFlightCountCorrected(DateTimeOffset.UtcNow, command.FlightCount)); | ||
|
||
return Result.Ok(); | ||
} | ||
} |
12 changes: 8 additions & 4 deletions
12
...op.Domain/AircraftContext/Aggregates/AircraftAggregate/Commands/CorrectTotalFlightTime.cs
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 |
---|---|---|
@@ -1,16 +1,20 @@ | ||
using FluentResults; | ||
using Skyhop.Domain.AircraftContext.Aggregates.AircraftAggregate.Events; | ||
using Whaally.Domain.Abstractions.Command; | ||
|
||
namespace Skyhop.Domain.AircraftContext.Aggregates.AircraftAggregate.Commands; | ||
|
||
[Immutable] | ||
[GenerateSerializer] | ||
public record CorrectTotalFlightTime( | ||
TimeSpan TotalTime, | ||
string Reason) : ICommand; | ||
TimeSpan TotalTime) : ICommand; | ||
|
||
public class CorrectTotalFlightTimeHandler : ICommandHandler<Aircraft, CorrectTotalFlightTime> | ||
{ | ||
public IResultBase Evaluate(ICommandHandlerContext<Aircraft> context, CorrectTotalFlightTime command) | ||
=> Result.Ok(); | ||
} | ||
{ | ||
context.StageEvent(new TotalFlightTimeCorrected(DateTimeOffset.UtcNow, command.TotalTime)); | ||
|
||
return Result.Ok(); | ||
} | ||
} |
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
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
25 changes: 25 additions & 0 deletions
25
tests/Skyhop.Domain.Tests/AircraftContext/Aggregates/Commands/CorrectTotalFlightCountTest.cs
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,25 @@ | ||
using FluentAssertions; | ||
using Skyhop.Domain.AircraftContext.Aggregates.AircraftAggregate; | ||
using Skyhop.Domain.AircraftContext.Aggregates.AircraftAggregate.Commands; | ||
using Skyhop.Domain.AircraftContext.Aggregates.AircraftAggregate.Events; | ||
using Whaally.Domain.Event; | ||
|
||
namespace Skyhop.Domain.Tests.AircraftContext.Aggregates.Commands; | ||
|
||
public abstract class CorrectTotalFlightCountTest(Aircraft aggregate, CorrectTotalFlightCount command) : SkyhopCommandTest<Aircraft, CorrectTotalFlightCount>( | ||
new CorrectTotalFlightCountHandler(), | ||
aggregate, | ||
command) | ||
{ | ||
public class FromCleanSlate() : CorrectTotalFlightCountTest(new Aircraft(), new CorrectTotalFlightCount(0)) | ||
{ | ||
[Fact] | ||
public void Succeeds() => Result.IsSuccess.Should().BeTrue(); | ||
|
||
[Fact] | ||
public void HasEvent() => Context.Events.Should().ContainSingle(); | ||
|
||
[Fact] | ||
public void EventOfType() => Context.Events.Should().ContainItemsAssignableTo<EventEnvelope<TotalFlightCountCorrected>>(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
tests/Skyhop.Domain.Tests/AircraftContext/Aggregates/Commands/CorrectTotalFlightTimeTest.cs
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 FluentAssertions; | ||
using Skyhop.Domain.AircraftContext.Aggregates.AircraftAggregate; | ||
using Skyhop.Domain.AircraftContext.Aggregates.AircraftAggregate.Commands; | ||
using Skyhop.Domain.AircraftContext.Aggregates.AircraftAggregate.Events; | ||
using Whaally.Domain.Event; | ||
|
||
namespace Skyhop.Domain.Tests.AircraftContext.Aggregates.Commands; | ||
|
||
public abstract class CorrectTotalFlightTimeTest(Aircraft aggregate, CorrectTotalFlightTime command) | ||
: SkyhopCommandTest<Aircraft, CorrectTotalFlightTime>(new CorrectTotalFlightTimeHandler(), aggregate, command) | ||
{ | ||
public class FromCleanSlate() : CorrectTotalFlightTimeTest(new Aircraft(), new CorrectTotalFlightTime(TimeSpan.Zero)) | ||
{ | ||
[Fact] | ||
public void Succeeds() => Result.IsSuccess.Should().BeTrue(); | ||
|
||
[Fact] | ||
public void HasEvent() => Context.Events.Should().ContainSingle(); | ||
|
||
[Fact] | ||
public void EventWithType() => | ||
Context.Events.Should().ContainItemsAssignableTo<EventEnvelope<TotalFlightTimeCorrected>>(); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
tests/Skyhop.Domain.Tests/AircraftContext/Aggregates/Commands/RemoveFlightTest.cs
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,38 @@ | ||
using FluentAssertions; | ||
using Skyhop.Domain.AircraftContext.Aggregates.AircraftAggregate; | ||
using Skyhop.Domain.AircraftContext.Aggregates.AircraftAggregate.Commands; | ||
using Skyhop.Domain.AircraftContext.Aggregates.AircraftAggregate.Events; | ||
using Whaally.Domain.Event; | ||
|
||
namespace Skyhop.Domain.Tests.AircraftContext.Aggregates.Commands; | ||
|
||
public abstract class RemoveFlightTest(Aircraft aggregate, RemoveFlight command) | ||
: SkyhopCommandTest<Aircraft, RemoveFlight>(new RemoveFlightHandler(), aggregate, command) | ||
{ | ||
public class FromCleanSlate() : RemoveFlightTest(new Aircraft(), new RemoveFlight("")) | ||
{ | ||
[Fact] | ||
public void Fails() => Result.IsFailed.Should().BeTrue(); | ||
} | ||
|
||
public class RemoveExistingFlight() : RemoveFlightTest( | ||
new Aircraft | ||
{ | ||
Flights = new() | ||
{ | ||
{ "1", ( Departure: default, Arrival: default )} | ||
} | ||
}, | ||
new RemoveFlight("1")) | ||
{ | ||
[Fact] | ||
public void Succeeds() => Result.IsSuccess.Should().BeTrue(); | ||
|
||
[Fact] | ||
public void WithEvent() => Context.Events.Should().ContainItemsAssignableTo<EventEnvelope<FlightRemoved>>(); | ||
|
||
[Fact] | ||
public void EventHasFlightId() => ((EventEnvelope<FlightRemoved>)Context.Events.Single()) | ||
.Message.FlightId.Should().Be(Command.FlightId); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
tests/Skyhop.Domain.Tests/FlightContext/Sagas/OnAircraftChangedTest.cs
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,44 @@ | ||
using FluentAssertions; | ||
using Skyhop.Domain.AircraftContext.Aggregates.AircraftAggregate; | ||
using Skyhop.Domain.FlightContext.Aggregates.FlightAggregate; | ||
using Skyhop.Domain.FlightContext.Aggregates.FlightAggregate.Commands; | ||
using Skyhop.Domain.FlightContext.Aggregates.FlightAggregate.Events; | ||
using Skyhop.Domain.FlightContext.Sagas; | ||
using Whaally.Domain; | ||
using Whaally.Domain.Event; | ||
|
||
namespace Skyhop.Domain.Tests.FlightContext.Sagas; | ||
|
||
/* | ||
* This test works slightly different due to the saga itself calling multiple other sagas. | ||
* | ||
* To properly test we must instantiate the requested aggregates beforehand, which is why we allow tests to define | ||
* the initializer, allowing them to define aggregates. | ||
*/ | ||
public abstract class OnAircraftChangedTest(Action<Whaally.Domain.Domain> initializer, EventEnvelope<AircraftSet> @event) | ||
: SkyhopSagaTest<AircraftSet>(initializer, new OnAircraftChanged(), @event) | ||
{ | ||
public class FromCleanSlate() : OnAircraftChangedTest( | ||
domain => { }, | ||
new(new AircraftSet("aircraft"), new EventMetadata("flight"))) | ||
{ | ||
[Fact] | ||
public void Succeeds() => Result.IsSuccess.Should().BeTrue(); | ||
|
||
[Fact(Skip = "Missing the infra to set up this test")] | ||
public void HasSingleCommand() => Context.Commands.Should().ContainSingle(); | ||
} | ||
|
||
// WIP figuring out how to best test sagas | ||
// public class AddsFlightToAircraft() : OnAircraftChangedTest( | ||
// domain => | ||
// { | ||
// _ = domain.GetAggregate<Flight>("flight") | ||
// .Result | ||
// .EvaluateAndApply(new Create(), new SetAircraft("aircraft-1")) | ||
// }, | ||
// new(new AircraftSet("aircraft-2"), new EventMetadata("flight"))) | ||
// { | ||
// | ||
// } | ||
} |
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
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