Skip to content

Commit

Permalink
Added implementation of choreography
Browse files Browse the repository at this point in the history
  • Loading branch information
oskardudycz committed Sep 3, 2024
1 parent 40496b2 commit e446375
Show file tree
Hide file tree
Showing 53 changed files with 192 additions and 305 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public async Task CheckingOutGuestWithSettledBalance_FailsWithGuestCheckoutFaile
}

// Then
publishedEvents.ShouldReceiveSingleEvent(new GuestCheckoutFailed(guestStayId, GuestCheckoutFailed.FailureReason.BalanceNotSettled, now));
publishedEvents.ShouldReceiveSingleEvent(new GuestCheckOutFailed(guestStayId, GuestCheckOutFailed.FailureReason.BalanceNotSettled, now));
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public record GuestCheckoutCompleted(
DateTimeOffset CompletedAt
): GroupCheckoutEvent;

public record GuestCheckoutFailed(
public record GuestCheckOutFailed(
Guid GroupCheckoutId,
Guid GuestStayId,
DateTimeOffset FailedAt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public record GuestCheckedOut(
Guid? GroupCheckOutId = null
): GuestStayAccountEvent;

public record GuestCheckoutFailed(
public record GuestCheckOutFailed(
Guid GuestStayId,
GuestCheckoutFailed.FailureReason Reason,
GuestCheckOutFailed.FailureReason Reason,
DateTimeOffset FailedAt,
Guid? GroupCheckOutId = null
): GuestStayAccountEvent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Concurrent;
using FluentAssertions;

namespace BusinessProcesses.Core;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ public async Task GroupCheckoutForMultipleGuestStayWithOneSettledAndRestUnsettle
new GuestCheckedOut(guestStays[0], now, groupCheckoutId),
new GroupCheckoutEvent.GuestCheckoutCompleted(groupCheckoutId, guestStays[0], now),
new CheckOutGuest(guestStays[1], now, groupCheckoutId),
new GuestCheckoutFailed(guestStays[1], GuestCheckoutFailed.FailureReason.BalanceNotSettled, now,
new GuestCheckOutFailed(guestStays[1], GuestCheckOutFailed.FailureReason.BalanceNotSettled, now,
groupCheckoutId),
new GroupCheckoutEvent.GuestCheckoutFailed(groupCheckoutId, guestStays[1], now),
new GroupCheckoutEvent.GuestCheckOutFailed(groupCheckoutId, guestStays[1], now),
new CheckOutGuest(guestStays[2], now, groupCheckoutId),
new GuestCheckoutFailed(guestStays[2], GuestCheckoutFailed.FailureReason.BalanceNotSettled, now,
new GuestCheckOutFailed(guestStays[2], GuestCheckOutFailed.FailureReason.BalanceNotSettled, now,
groupCheckoutId),
new GroupCheckoutEvent.GuestCheckoutFailed(groupCheckoutId, guestStays[2], now),
new GroupCheckoutEvent.GuestCheckOutFailed(groupCheckoutId, guestStays[2], now),
new GroupCheckoutEvent.GroupCheckoutFailed(
groupCheckoutId,
[guestStays[0]],
Expand Down Expand Up @@ -184,17 +184,17 @@ public async Task GroupCheckoutForMultipleGuestStayWithAllUnsettled_ShouldFail()
[
new GroupCheckoutEvent.GroupCheckoutInitiated(groupCheckoutId, clerkId, guestStays, now),
new CheckOutGuest(guestStays[0], now, groupCheckoutId),
new GuestCheckoutFailed(guestStays[0], GuestCheckoutFailed.FailureReason.BalanceNotSettled, now,
new GuestCheckOutFailed(guestStays[0], GuestCheckOutFailed.FailureReason.BalanceNotSettled, now,
groupCheckoutId),
new GroupCheckoutEvent.GuestCheckoutFailed(groupCheckoutId, guestStays[0], now),
new GroupCheckoutEvent.GuestCheckOutFailed(groupCheckoutId, guestStays[0], now),
new CheckOutGuest(guestStays[1], now, groupCheckoutId),
new GuestCheckoutFailed(guestStays[1], GuestCheckoutFailed.FailureReason.BalanceNotSettled, now,
new GuestCheckOutFailed(guestStays[1], GuestCheckOutFailed.FailureReason.BalanceNotSettled, now,
groupCheckoutId),
new GroupCheckoutEvent.GuestCheckoutFailed(groupCheckoutId, guestStays[1], now),
new GroupCheckoutEvent.GuestCheckOutFailed(groupCheckoutId, guestStays[1], now),
new CheckOutGuest(guestStays[2], now, groupCheckoutId),
new GuestCheckoutFailed(guestStays[2], GuestCheckoutFailed.FailureReason.BalanceNotSettled, now,
new GuestCheckOutFailed(guestStays[2], GuestCheckOutFailed.FailureReason.BalanceNotSettled, now,
groupCheckoutId),
new GroupCheckoutEvent.GuestCheckoutFailed(groupCheckoutId, guestStays[2], now),
new GroupCheckoutEvent.GuestCheckOutFailed(groupCheckoutId, guestStays[2], now),
new GroupCheckoutEvent.GroupCheckoutFailed(
groupCheckoutId,
[],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public async Task CheckingOutGuestWithSettledBalance_FailsWithGuestCheckoutFaile
}

// Then
publishedMessages.ShouldReceiveSingleMessage(new GuestCheckoutFailed(guestStayId, GuestCheckoutFailed.FailureReason.BalanceNotSettled, now));
publishedMessages.ShouldReceiveSingleMessage(new GuestCheckOutFailed(guestStayId, GuestCheckOutFailed.FailureReason.BalanceNotSettled, now));
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public record GuestCheckoutCompleted(
DateTimeOffset CompletedAt
): GroupCheckoutEvent;

public record GuestCheckoutFailed(
public record GuestCheckOutFailed(
Guid GroupCheckoutId,
Guid GuestStayId,
DateTimeOffset FailedAt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public record GuestCheckedOut(
Guid? GroupCheckOutId = null
): GuestStayAccountEvent;

public record GuestCheckoutFailed(
public record GuestCheckOutFailed(
Guid GuestStayId,
GuestCheckoutFailed.FailureReason Reason,
GuestCheckOutFailed.FailureReason Reason,
DateTimeOffset FailedAt,
Guid? GroupCheckOutId = null
): GuestStayAccountEvent
Expand Down Expand Up @@ -98,11 +98,11 @@ public void CheckOut(DateTimeOffset now, Guid? groupCheckoutId = null)
{
if (status != GuestStayAccountStatus.Opened || !IsSettled)
{
Enqueue(new GuestCheckoutFailed(
Enqueue(new GuestCheckOutFailed(
Id,
status != GuestStayAccountStatus.Opened
? GuestCheckoutFailed.FailureReason.NotOpened
: GuestCheckoutFailed.FailureReason.BalanceNotSettled,
? GuestCheckOutFailed.FailureReason.NotOpened
: GuestCheckOutFailed.FailureReason.BalanceNotSettled,
now,
groupCheckoutId
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ public async Task GroupCheckoutForMultipleGuestStayWithOneSettledAndRestUnsettle
new GuestCheckedOut(guestStays[0], now, groupCheckoutId),
new GroupCheckoutEvent.GuestCheckoutCompleted(groupCheckoutId, guestStays[0], now),
new CheckOutGuest(guestStays[1], now, groupCheckoutId),
new GuestCheckoutFailed(guestStays[1], GuestCheckoutFailed.FailureReason.BalanceNotSettled, now,
new GuestCheckOutFailed(guestStays[1], GuestCheckOutFailed.FailureReason.BalanceNotSettled, now,
groupCheckoutId),
new GroupCheckoutEvent.GuestCheckoutFailed(groupCheckoutId, guestStays[1], now),
new GroupCheckoutEvent.GuestCheckOutFailed(groupCheckoutId, guestStays[1], now),
new CheckOutGuest(guestStays[2], now, groupCheckoutId),
new GuestCheckoutFailed(guestStays[2], GuestCheckoutFailed.FailureReason.BalanceNotSettled, now,
new GuestCheckOutFailed(guestStays[2], GuestCheckOutFailed.FailureReason.BalanceNotSettled, now,
groupCheckoutId),
new GroupCheckoutEvent.GuestCheckoutFailed(groupCheckoutId, guestStays[2], now),
new GroupCheckoutEvent.GuestCheckOutFailed(groupCheckoutId, guestStays[2], now),
new GroupCheckoutEvent.GroupCheckoutFailed(
groupCheckoutId,
[guestStays[0]],
Expand Down Expand Up @@ -184,17 +184,17 @@ public async Task GroupCheckoutForMultipleGuestStayWithAllUnsettled_ShouldFail()
[
new GroupCheckoutEvent.GroupCheckoutInitiated(groupCheckoutId, clerkId, guestStays, now),
new CheckOutGuest(guestStays[0], now, groupCheckoutId),
new GuestCheckoutFailed(guestStays[0], GuestCheckoutFailed.FailureReason.BalanceNotSettled, now,
new GuestCheckOutFailed(guestStays[0], GuestCheckOutFailed.FailureReason.BalanceNotSettled, now,
groupCheckoutId),
new GroupCheckoutEvent.GuestCheckoutFailed(groupCheckoutId, guestStays[0], now),
new GroupCheckoutEvent.GuestCheckOutFailed(groupCheckoutId, guestStays[0], now),
new CheckOutGuest(guestStays[1], now, groupCheckoutId),
new GuestCheckoutFailed(guestStays[1], GuestCheckoutFailed.FailureReason.BalanceNotSettled, now,
new GuestCheckOutFailed(guestStays[1], GuestCheckOutFailed.FailureReason.BalanceNotSettled, now,
groupCheckoutId),
new GroupCheckoutEvent.GuestCheckoutFailed(groupCheckoutId, guestStays[1], now),
new GroupCheckoutEvent.GuestCheckOutFailed(groupCheckoutId, guestStays[1], now),
new CheckOutGuest(guestStays[2], now, groupCheckoutId),
new GuestCheckoutFailed(guestStays[2], GuestCheckoutFailed.FailureReason.BalanceNotSettled, now,
new GuestCheckOutFailed(guestStays[2], GuestCheckOutFailed.FailureReason.BalanceNotSettled, now,
groupCheckoutId),
new GroupCheckoutEvent.GuestCheckoutFailed(groupCheckoutId, guestStays[2], now),
new GroupCheckoutEvent.GuestCheckOutFailed(groupCheckoutId, guestStays[2], now),
new GroupCheckoutEvent.GroupCheckoutFailed(
groupCheckoutId,
[],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Bogus;
using BusinessProcesses.Core;
using BusinessProcesses.Version2_ImmutableEntities.GroupCheckouts;
using BusinessProcesses.Version2_ImmutableEntities.GuestStayAccounts;
using Xunit;
using Xunit.Abstractions;
Expand All @@ -10,7 +9,6 @@ namespace BusinessProcesses.Version2_ImmutableEntities;

using static GuestStayAccountEvent;
using static GuestStayAccountCommand;
using static GroupCheckoutCommand;

public class EntityDefinitionTests
{
Expand Down Expand Up @@ -130,7 +128,7 @@ public async Task CheckingOutGuestWithSettledBalance_FailsWithGuestCheckoutFaile
}

// Then
publishedMessages.ShouldReceiveSingleMessage(new GuestCheckoutFailed(guestStayId, GuestCheckoutFailed.FailureReason.BalanceNotSettled, now));
publishedMessages.ShouldReceiveSingleMessage(new GuestCheckOutFailed(guestStayId, GuestCheckOutFailed.FailureReason.BalanceNotSettled, now));
}

private readonly Database database = new();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using BusinessProcesses.Version2_ImmutableEntities.Core;

namespace BusinessProcesses.Version2_ImmutableEntities.GroupCheckouts;

using static GroupCheckoutEvent;

public abstract record GroupCheckoutEvent
{
public record GroupCheckoutInitiated(
Expand All @@ -19,7 +15,7 @@ public record GuestCheckoutCompleted(
DateTimeOffset CompletedAt
): GroupCheckoutEvent;

public record GuestCheckoutFailed(
public record GuestCheckOutFailed(
Guid GroupCheckoutId,
Guid GuestStayId,
DateTimeOffset FailedAt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public record GuestCheckedOut(
Guid? GroupCheckOutId = null
): GuestStayAccountEvent;

public record GuestCheckoutFailed(
public record GuestCheckOutFailed(
Guid GuestStayId,
GuestCheckoutFailed.FailureReason Reason,
GuestCheckOutFailed.FailureReason Reason,
DateTimeOffset FailedAt,
Guid? GroupCheckOutId = null
): GuestStayAccountEvent
Expand Down Expand Up @@ -73,9 +73,9 @@ public PaymentRecorded RecordPayment(decimal amount, DateTimeOffset now)
public GuestStayAccountEvent CheckOut(DateTimeOffset now, Guid? groupCheckoutId = null)
{
if (Status != GuestStayAccountStatus.Opened)
return new GuestCheckoutFailed(
return new GuestCheckOutFailed(
Id,
GuestCheckoutFailed.FailureReason.NotOpened,
GuestCheckOutFailed.FailureReason.NotOpened,
now,
groupCheckoutId
);
Expand All @@ -86,9 +86,9 @@ public GuestStayAccountEvent CheckOut(DateTimeOffset now, Guid? groupCheckoutId
now,
groupCheckoutId
)
: new GuestCheckoutFailed(
: new GuestCheckOutFailed(
Id,
GuestCheckoutFailed.FailureReason.BalanceNotSettled,
GuestCheckOutFailed.FailureReason.BalanceNotSettled,
now,
groupCheckoutId
);
Expand All @@ -106,7 +106,7 @@ public GuestStayAccount Evolve(GuestStayAccountEvent @event) =>
ChargeRecorded charge => this with { Balance = Balance - charge.Amount },
PaymentRecorded payment => this with { Balance = Balance + payment.Amount },
GuestCheckedOut => this with { Status = GuestStayAccountStatus.CheckedOut },
GuestCheckoutFailed => this,
GuestCheckOutFailed => this,
_ => this
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public async ValueTask CheckOutGuest(CheckOutGuest command, CancellationToken ct
await eventBus.Publish([checkedOut], ct);
return;
}
case GuestCheckoutFailed checkOutFailed:
case GuestCheckOutFailed checkOutFailed:
{
await eventBus.Publish([checkOutFailed], ct);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public void GuestStayAccountEventTypes_AreDefined()
new ChargeRecorded(guestStayId, 100, DateTimeOffset.Now),
new PaymentRecorded(guestStayId, 100, DateTimeOffset.Now),
new GuestCheckedOut(guestStayId, DateTimeOffset.Now, groupCheckoutId),
new GuestStayAccountEvent.GuestCheckoutFailed(guestStayId,
GuestStayAccountEvent.GuestCheckoutFailed.FailureReason.NotOpened, DateTimeOffset.Now,
new GuestStayAccountEvent.GuestCheckOutFailed(guestStayId,
GuestStayAccountEvent.GuestCheckOutFailed.FailureReason.NotOpened, DateTimeOffset.Now,
groupCheckoutId)
};

Expand All @@ -46,7 +46,7 @@ public void GroupCheckoutEventTypes_AreDefined()
{
new GroupCheckoutInitiated(groupCheckoutId, clerkId, guestStayIds, DateTimeOffset.Now),
new GuestCheckoutCompleted(groupCheckoutId, guestStayIds[0], DateTimeOffset.Now),
new GroupCheckoutEvent.GuestCheckoutFailed(groupCheckoutId, guestStayIds[1], DateTimeOffset.Now),
new GroupCheckoutEvent.GuestCheckOutFailed(groupCheckoutId, guestStayIds[1], DateTimeOffset.Now),
new GroupCheckoutFailed(groupCheckoutId, [guestStayIds[0]], [guestStayIds[1]], DateTimeOffset.Now),
new GroupCheckoutCompleted(groupCheckoutId, guestStayIds, DateTimeOffset.Now)
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public record GuestCheckoutCompleted(
DateTimeOffset CompletedAt
): GroupCheckoutEvent;

public record GuestCheckoutFailed(
public record GuestCheckOutFailed(
Guid GroupCheckoutId,
Guid GuestStayId,
DateTimeOffset FailedAt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public record GuestCheckedOut(
Guid? GroupCheckOutId = null
): GuestStayAccountEvent;

public record GuestCheckoutFailed(
public record GuestCheckOutFailed(
Guid GuestStayId,
GuestCheckoutFailed.FailureReason Reason,
GuestCheckOutFailed.FailureReason Reason,
DateTimeOffset FailedAt,
Guid? GroupCheckOutId = null
): GuestStayAccountEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public async Task CheckingOutGuestWithSettledBalance_FailsWithGuestCheckoutFaile
}

// Then
publishedEvents.ShouldReceiveSingleEvent(new GuestCheckoutFailed(guestStayId, GuestCheckoutFailed.FailureReason.BalanceNotSettled, now));
publishedEvents.ShouldReceiveSingleEvent(new GuestCheckOutFailed(guestStayId, GuestCheckOutFailed.FailureReason.BalanceNotSettled, now));
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public record GuestCheckoutCompleted(
DateTimeOffset CompletedAt
): GroupCheckoutEvent;

public record GuestCheckoutFailed(
public record GuestCheckOutFailed(
Guid GroupCheckoutId,
Guid GuestStayId,
DateTimeOffset FailedAt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public record GuestCheckedOut(
Guid? GroupCheckOutId = null
): GuestStayAccountEvent;

public record GuestCheckoutFailed(
public record GuestCheckOutFailed(
Guid GuestStayId,
GuestCheckoutFailed.FailureReason Reason,
GuestCheckOutFailed.FailureReason Reason,
DateTimeOffset FailedAt,
Guid? GroupCheckOutId = null
): GuestStayAccountEvent
Expand Down Expand Up @@ -98,11 +98,11 @@ public void CheckOut(DateTimeOffset now, Guid? groupCheckoutId = null)
{
if (status != GuestStayAccountStatus.Opened || !IsSettled)
{
Enqueue(new GuestCheckoutFailed(
Enqueue(new GuestCheckOutFailed(
Id,
status != GuestStayAccountStatus.Opened
? GuestCheckoutFailed.FailureReason.NotOpened
: GuestCheckoutFailed.FailureReason.BalanceNotSettled,
? GuestCheckOutFailed.FailureReason.NotOpened
: GuestCheckOutFailed.FailureReason.BalanceNotSettled,
now,
groupCheckoutId
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public async Task CheckingOutGuestWithSettledBalance_FailsWithGuestCheckoutFaile
}

// Then
publishedEvents.ShouldReceiveSingleEvent(new GuestCheckoutFailed(guestStayId, GuestCheckoutFailed.FailureReason.BalanceNotSettled, now));
publishedEvents.ShouldReceiveSingleEvent(new GuestCheckOutFailed(guestStayId, GuestCheckOutFailed.FailureReason.BalanceNotSettled, now));
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using EntitiesDefinition.Solution2_ImmutableEntities.Core;

namespace EntitiesDefinition.Solution2_ImmutableEntities.GroupCheckouts;

using static GroupCheckoutEvent;

public abstract record GroupCheckoutEvent
{
public record GroupCheckoutInitiated(
Expand All @@ -19,7 +15,7 @@ public record GuestCheckoutCompleted(
DateTimeOffset CompletedAt
): GroupCheckoutEvent;

public record GuestCheckoutFailed(
public record GuestCheckOutFailed(
Guid GroupCheckoutId,
Guid GuestStayId,
DateTimeOffset FailedAt
Expand Down
Loading

0 comments on commit e446375

Please sign in to comment.