Skip to content

Commit

Permalink
Fix: implements currency change
Browse files Browse the repository at this point in the history
  • Loading branch information
GreRut committed Nov 11, 2024
1 parent 891b2f2 commit 728f4e6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion EventSourcing.Test/AccountAggregateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ public async void CurrencyChangeEvent_Should_ChangeAccountCurrency()
var result = AccountAggregate.GenerateAggregate(events);

// Assert
result.Should().Be(expectedAccount);
result.Should().BeEquivalentTo(expectedAccount);
}

[Fact]
Expand Down
8 changes: 7 additions & 1 deletion EventSourcing/AccountAggregate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ private void Apply(Event accountEvent)
case ClosureEvent closure:
Apply(closure);
break;
case CurrencyChangeEvent currencyChange:
Apply(currencyChange);
break;
default:
throw new EventTypeNotSupportedException("162 ERROR_EVENT_NOT_SUPPORTED");
}
Expand Down Expand Up @@ -119,13 +122,16 @@ private void Apply(ActivationEvent activation)

private void Apply(CurrencyChangeEvent currencyChange)
{
throw new NotImplementedException();
Currency = currencyChange.NewCurrency;
Balance = currencyChange.NewBalance;
Status = AccountStatus.Disabled;
}

private void Apply(ClosureEvent closure)
{
if (AccountLog == null)
AccountLog = new List<LogMessage>();
//Eventually refactor
var logMessage = new LogMessage("CLOSURE", "Reason: Customer request, Closing Balance: '5000'", closure.Timestamp);
AccountLog.Add(logMessage);
Status = AccountStatus.Closed;
Expand Down
4 changes: 2 additions & 2 deletions EventSourcing/Events/CurrencyChangeEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ public record CurrencyChangeEvent : Event
[JsonPropertyName("newBalance")]
public required decimal NewBalance { get; init; }

[JsonPropertyName("currency")]
public required CurrencyType Currency { get; init; }
[JsonPropertyName("newCurrency")]
public required CurrencyType NewCurrency { get; init; }
}

0 comments on commit 728f4e6

Please sign in to comment.