-
-
Notifications
You must be signed in to change notification settings - Fork 522
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
1 parent
1d1d79d
commit 77abd9c
Showing
7 changed files
with
374 additions
and
16 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
18 changes: 18 additions & 0 deletions
18
Sample/HotelManagement/HotelManagement.Tests/GroupCheckouts/GroupCheckoutTests.CheckIn.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,18 @@ | ||
using HotelManagement.GroupCheckouts; | ||
using Ogooreck.BusinessLogic; | ||
using Xunit; | ||
|
||
namespace HotelManagement.Tests.GroupCheckouts; | ||
|
||
public partial class GroupCheckoutTests | ||
{ | ||
[Fact] | ||
public void GivenNonExistingGroupCheckout_WhenInitiate_ThenSucceeds() | ||
{ | ||
var guestStaysIds = new[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() }; | ||
|
||
Spec.Given() | ||
.When(_ => GroupCheckout.Initiate(groupCheckoutId, clerkId, guestStaysIds, now)) | ||
.Then(new GroupCheckoutInitiated(groupCheckoutId, clerkId, guestStaysIds, now)); | ||
} | ||
} |
131 changes: 131 additions & 0 deletions
131
.../HotelManagement.Tests/GroupCheckouts/GroupCheckoutTests.RecordGuestCheckoutCompletion.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,131 @@ | ||
using HotelManagement.GroupCheckouts; | ||
using Ogooreck.BusinessLogic; | ||
using Xunit; | ||
|
||
namespace HotelManagement.Tests.GroupCheckouts; | ||
|
||
public partial class GroupCheckoutTests | ||
{ | ||
[Fact] | ||
public void GivenNonExistingGroupCheckout_WhenRecordGuestCheckoutCompletion_ThenIgnores() | ||
{ | ||
var guestStaysId = Guid.NewGuid(); | ||
|
||
Spec.Given() | ||
.When(state => state.RecordGuestCheckoutCompletion(guestStaysId, now).IsPresent) | ||
.Then(false); | ||
} | ||
|
||
[Fact] | ||
public void GivenInitiatedGroupCheckout_WhenRecordGuestCheckoutCompletion_ThenSucceeds() | ||
{ | ||
var guestStaysIds = new[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() }; | ||
|
||
Spec.Given( | ||
new GroupCheckoutInitiated(groupCheckoutId, clerkId, guestStaysIds, now), | ||
new GuestCheckoutsInitiated(groupCheckoutId, guestStaysIds, now) | ||
) | ||
.When(state => state.RecordGuestCheckoutCompletion(guestStaysIds[0], now).GetOrThrow()) | ||
.Then(new GuestCheckoutCompleted(groupCheckoutId, guestStaysIds[0], now)); | ||
} | ||
|
||
[Fact] | ||
public void GivenInitiatedGroupCheckout_WhenRecordGuestCheckoutCompletionTwice_ThenIgnores() | ||
{ | ||
var guestStaysIds = new[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() }; | ||
|
||
Spec.Given( | ||
new GroupCheckoutInitiated(groupCheckoutId, clerkId, guestStaysIds, now), | ||
new GuestCheckoutsInitiated(groupCheckoutId, guestStaysIds, now), | ||
new GuestCheckoutCompleted(groupCheckoutId, guestStaysIds[0], now) | ||
) | ||
.When(state => state.RecordGuestCheckoutCompletion(guestStaysIds[0], now).IsPresent) | ||
.Then(false); | ||
} | ||
|
||
[Fact] | ||
public void GivenInitiatedGroupCheckout_WhenRecordLastGuestCheckoutCompletion_ThenCompletes() | ||
{ | ||
var guestStaysIds = new[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() }; | ||
|
||
Spec.Given( | ||
new GroupCheckoutInitiated(groupCheckoutId, clerkId, guestStaysIds, now), | ||
new GuestCheckoutsInitiated(groupCheckoutId, guestStaysIds, now), | ||
new GuestCheckoutCompleted(groupCheckoutId, guestStaysIds[0], now), | ||
new GuestCheckoutCompleted(groupCheckoutId, guestStaysIds[1], now) | ||
) | ||
.When(state => state.RecordGuestCheckoutCompletion(guestStaysIds[2], now).GetOrThrow()) | ||
.Then( | ||
new GuestCheckoutCompleted(groupCheckoutId, guestStaysIds[2], now), | ||
new GroupCheckoutCompleted(groupCheckoutId, guestStaysIds, now) | ||
); | ||
} | ||
|
||
|
||
[Fact] | ||
public void GivenInitiatedGroupCheckoutWithFailure_WhenRecordLastGuestCheckoutCompletion_ThenCompletesWithFailure() | ||
{ | ||
var guestStaysIds = new[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() }; | ||
|
||
Spec.Given( | ||
new GroupCheckoutInitiated(groupCheckoutId, clerkId, guestStaysIds, now), | ||
new GuestCheckoutsInitiated(groupCheckoutId, guestStaysIds, now), | ||
new GuestCheckoutCompleted(groupCheckoutId, guestStaysIds[0], now), | ||
new GuestCheckoutFailed(groupCheckoutId, guestStaysIds[1], now) | ||
) | ||
.When(state => state.RecordGuestCheckoutCompletion(guestStaysIds[2], now).GetOrThrow()) | ||
.Then( | ||
new GuestCheckoutCompleted(groupCheckoutId, guestStaysIds[2], now), | ||
new GroupCheckoutFailed( | ||
groupCheckoutId, | ||
new[] { guestStaysIds[0], guestStaysIds[2] }, | ||
new[] { guestStaysIds[1] }, | ||
now | ||
) | ||
); | ||
} | ||
|
||
[Fact] | ||
public void GivenCompletedGroupCheckoutWithFailure_WhenRecordGuestCheckoutCompletion_ThenIgnores() | ||
{ | ||
var guestStaysIds = new[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() }; | ||
|
||
Spec.Given( | ||
new GroupCheckoutInitiated(groupCheckoutId, clerkId, guestStaysIds, now), | ||
new GuestCheckoutsInitiated(groupCheckoutId, guestStaysIds, now), | ||
new GuestCheckoutCompleted(groupCheckoutId, guestStaysIds[0], now), | ||
new GuestCheckoutFailed(groupCheckoutId, guestStaysIds[1], now), | ||
new GuestCheckoutCompleted(groupCheckoutId, guestStaysIds[2], now), | ||
new GroupCheckoutFailed( | ||
groupCheckoutId, | ||
new[] { guestStaysIds[0], guestStaysIds[2] }, | ||
new[] { guestStaysIds[1] }, | ||
now | ||
) | ||
) | ||
.When(state => state.RecordGuestCheckoutCompletion(guestStaysIds[2], now).IsPresent) | ||
.Then(false); | ||
} | ||
|
||
[Fact] | ||
public void GivenCompletedGroupCheckout_WhenRecordGuestCheckoutCompletion_ThenIgnores() | ||
{ | ||
var guestStaysIds = new[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() }; | ||
|
||
Spec.Given( | ||
new GroupCheckoutInitiated(groupCheckoutId, clerkId, guestStaysIds, now), | ||
new GuestCheckoutsInitiated(groupCheckoutId, guestStaysIds, now), | ||
new GuestCheckoutCompleted(groupCheckoutId, guestStaysIds[0], now), | ||
new GuestCheckoutCompleted(groupCheckoutId, guestStaysIds[1], now), | ||
new GuestCheckoutCompleted(groupCheckoutId, guestStaysIds[2], now), | ||
new GroupCheckoutFailed( | ||
groupCheckoutId, | ||
new[] { guestStaysIds[0], guestStaysIds[2] }, | ||
new[] { guestStaysIds[1] }, | ||
now | ||
) | ||
) | ||
.When(state => state.RecordGuestCheckoutCompletion(guestStaysIds[2], now).IsPresent) | ||
.Then(false); | ||
} | ||
} |
136 changes: 136 additions & 0 deletions
136
...ent/HotelManagement.Tests/GroupCheckouts/GroupCheckoutTests.RecordGuestCheckoutFailure.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,136 @@ | ||
using HotelManagement.GroupCheckouts; | ||
using Ogooreck.BusinessLogic; | ||
using Xunit; | ||
|
||
namespace HotelManagement.Tests.GroupCheckouts; | ||
|
||
public partial class GroupCheckoutTests | ||
{ | ||
[Fact] | ||
public void GivenNonExistingGroupCheckout_WhenRecordGuestCheckoutFailure_ThenIgnores() | ||
{ | ||
var guestStaysId = Guid.NewGuid(); | ||
|
||
Spec.Given() | ||
.When(state => state.RecordGuestCheckoutFailure(guestStaysId, now).IsPresent) | ||
.Then(false); | ||
} | ||
|
||
[Fact] | ||
public void GivenInitiatedGroupCheckout_WhenRecordGuestCheckoutFailure_ThenSucceeds() | ||
{ | ||
var guestStaysIds = new[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() }; | ||
|
||
Spec.Given( | ||
new GroupCheckoutInitiated(groupCheckoutId, clerkId, guestStaysIds, now), | ||
new GuestCheckoutsInitiated(groupCheckoutId, guestStaysIds, now) | ||
) | ||
.When(state => state.RecordGuestCheckoutFailure(guestStaysIds[0], now).GetOrThrow()) | ||
.Then(new GuestCheckoutFailed(groupCheckoutId, guestStaysIds[0], now)); | ||
} | ||
|
||
[Fact] | ||
public void GivenInitiatedGroupCheckout_WhenRecordGuestCheckoutFailureTwice_ThenIgnores() | ||
{ | ||
var guestStaysIds = new[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() }; | ||
|
||
Spec.Given( | ||
new GroupCheckoutInitiated(groupCheckoutId, clerkId, guestStaysIds, now), | ||
new GuestCheckoutsInitiated(groupCheckoutId, guestStaysIds, now), | ||
new GuestCheckoutFailed(groupCheckoutId, guestStaysIds[0], now) | ||
) | ||
.When(state => state.RecordGuestCheckoutFailure(guestStaysIds[0], now).IsPresent) | ||
.Then(false); | ||
} | ||
|
||
[Fact] | ||
public void GivenInitiatedGroupCheckout_WhenRecordLastGuestCheckoutFailure_ThenCompletesWithFailure() | ||
{ | ||
var guestStaysIds = new[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() }; | ||
|
||
Spec.Given( | ||
new GroupCheckoutInitiated(groupCheckoutId, clerkId, guestStaysIds, now), | ||
new GuestCheckoutsInitiated(groupCheckoutId, guestStaysIds, now), | ||
new GuestCheckoutFailed(groupCheckoutId, guestStaysIds[0], now), | ||
new GuestCheckoutFailed(groupCheckoutId, guestStaysIds[1], now) | ||
) | ||
.When(state => state.RecordGuestCheckoutFailure(guestStaysIds[2], now).GetOrThrow()) | ||
.Then( | ||
new GuestCheckoutFailed(groupCheckoutId, guestStaysIds[2], now), | ||
new GroupCheckoutFailed( | ||
groupCheckoutId, | ||
Array.Empty<Guid>(), | ||
guestStaysIds, | ||
now | ||
) | ||
); | ||
} | ||
|
||
|
||
[Fact] | ||
public void GivenInitiatedGroupCheckoutWithFailure_WhenRecordLastGuestCheckoutFailure_ThenCompletesWithFailure() | ||
{ | ||
var guestStaysIds = new[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() }; | ||
|
||
Spec.Given( | ||
new GroupCheckoutInitiated(groupCheckoutId, clerkId, guestStaysIds, now), | ||
new GuestCheckoutsInitiated(groupCheckoutId, guestStaysIds, now), | ||
new GuestCheckoutCompleted(groupCheckoutId, guestStaysIds[0], now), | ||
new GuestCheckoutFailed(groupCheckoutId, guestStaysIds[1], now) | ||
) | ||
.When(state => state.RecordGuestCheckoutFailure(guestStaysIds[2], now).GetOrThrow()) | ||
.Then( | ||
new GuestCheckoutCompleted(groupCheckoutId, guestStaysIds[2], now), | ||
new GroupCheckoutFailed( | ||
groupCheckoutId, | ||
new[] { guestStaysIds[0] }, | ||
new[] { guestStaysIds[1], guestStaysIds[2] }, | ||
now | ||
) | ||
); | ||
} | ||
|
||
[Fact] | ||
public void GivenCompletedGroupCheckoutWithFailure_WhenRecordGuestCheckoutFailure_ThenIgnores() | ||
{ | ||
var guestStaysIds = new[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() }; | ||
|
||
Spec.Given( | ||
new GroupCheckoutInitiated(groupCheckoutId, clerkId, guestStaysIds, now), | ||
new GuestCheckoutsInitiated(groupCheckoutId, guestStaysIds, now), | ||
new GuestCheckoutCompleted(groupCheckoutId, guestStaysIds[0], now), | ||
new GuestCheckoutCompleted(groupCheckoutId, guestStaysIds[1], now), | ||
new GuestCheckoutFailed(groupCheckoutId, guestStaysIds[2], now), | ||
new GroupCheckoutFailed( | ||
groupCheckoutId, | ||
new[] { guestStaysIds[0], guestStaysIds[1] }, | ||
new[] { guestStaysIds[2] }, | ||
now | ||
) | ||
) | ||
.When(state => state.RecordGuestCheckoutFailure(guestStaysIds[2], now).IsPresent) | ||
.Then(false); | ||
} | ||
|
||
[Fact] | ||
public void GivenCompletedGroupCheckout_WhenRecordGuestCheckoutFailure_ThenIgnores() | ||
{ | ||
var guestStaysIds = new[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() }; | ||
|
||
Spec.Given( | ||
new GroupCheckoutInitiated(groupCheckoutId, clerkId, guestStaysIds, now), | ||
new GuestCheckoutsInitiated(groupCheckoutId, guestStaysIds, now), | ||
new GuestCheckoutCompleted(groupCheckoutId, guestStaysIds[0], now), | ||
new GuestCheckoutCompleted(groupCheckoutId, guestStaysIds[1], now), | ||
new GuestCheckoutCompleted(groupCheckoutId, guestStaysIds[2], now), | ||
new GroupCheckoutFailed( | ||
groupCheckoutId, | ||
new[] { guestStaysIds[0], guestStaysIds[2] }, | ||
new[] { guestStaysIds[1] }, | ||
now | ||
) | ||
) | ||
.When(state => state.RecordGuestCheckoutFailure(guestStaysIds[2], now).IsPresent) | ||
.Then(false); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...HotelManagement.Tests/GroupCheckouts/GroupCheckoutTests.RecordGuestCheckoutsInitiation.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,28 @@ | ||
using HotelManagement.GroupCheckouts; | ||
using Ogooreck.BusinessLogic; | ||
using Xunit; | ||
|
||
namespace HotelManagement.Tests.GroupCheckouts; | ||
|
||
public partial class GroupCheckoutTests | ||
{ | ||
[Fact] | ||
public void GivenNonExistingGroupCheckout_WhenRecordGuestCheckoutsInitiation_ThenIgnores() | ||
{ | ||
var guestStaysIds = new[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() }; | ||
|
||
Spec.Given() | ||
.When(state => state.RecordGuestCheckoutsInitiation(guestStaysIds, now).IsPresent) | ||
.Then(false); | ||
} | ||
|
||
[Fact] | ||
public void GivenInitiatedGroupCheckout_WhenRecordGuestCheckoutsInitiation_ThenSucceeds() | ||
{ | ||
var guestStaysIds = new[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() }; | ||
|
||
Spec.Given(new GroupCheckoutInitiated(groupCheckoutId, clerkId, guestStaysIds, now)) | ||
.When(state => state.RecordGuestCheckoutsInitiation(guestStaysIds, now).GetOrThrow()) | ||
.Then(new GuestCheckoutsInitiated(groupCheckoutId, guestStaysIds, now)); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
Sample/HotelManagement/HotelManagement.Tests/GroupCheckouts/GroupCheckoutTests.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,28 @@ | ||
using Bogus; | ||
using HotelManagement.GroupCheckouts; | ||
using Ogooreck.BusinessLogic; | ||
|
||
namespace HotelManagement.Tests.GroupCheckouts; | ||
|
||
public partial class GroupCheckoutTests | ||
{ | ||
private readonly HandlerSpecification<GroupCheckout> Spec = Specification.For<GroupCheckout>(Evolve); | ||
private readonly DateTimeOffset now = DateTimeOffset.UtcNow; | ||
private readonly Guid groupCheckoutId = Guid.NewGuid(); | ||
private readonly Guid clerkId = Guid.NewGuid(); | ||
private readonly Faker faker = new(); | ||
|
||
private static GroupCheckout Evolve(GroupCheckout groupCheckout, object @event) | ||
{ | ||
return @event switch | ||
{ | ||
GroupCheckoutInitiated groupCheckoutInitiated => GroupCheckout.Create(groupCheckoutInitiated), | ||
GuestCheckoutsInitiated guestCheckoutsInitiated => groupCheckout.Apply(guestCheckoutsInitiated), | ||
GuestCheckoutCompleted guestCheckoutCompleted => groupCheckout.Apply(guestCheckoutCompleted), | ||
GuestCheckoutFailed guestCheckoutFailed => groupCheckout.Apply(guestCheckoutFailed), | ||
GroupCheckoutCompleted groupCheckoutCompleted => groupCheckout.Apply(groupCheckoutCompleted), | ||
GroupCheckoutFailed groupCheckoutFailed => groupCheckout.Apply(groupCheckoutFailed), | ||
_ => groupCheckout | ||
}; | ||
} | ||
} |
Oops, something went wrong.