diff --git a/EventSourcing.Test/AccountAggregateTest.cs b/EventSourcing.Test/AccountAggregateTest.cs index 5a7e153..2fd52df 100644 --- a/EventSourcing.Test/AccountAggregateTest.cs +++ b/EventSourcing.Test/AccountAggregateTest.cs @@ -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] diff --git a/EventSourcing/AccountAggregate.cs b/EventSourcing/AccountAggregate.cs index 312bd3f..b7687c2 100644 --- a/EventSourcing/AccountAggregate.cs +++ b/EventSourcing/AccountAggregate.cs @@ -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"); } @@ -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(); + //Eventually refactor var logMessage = new LogMessage("CLOSURE", "Reason: Customer request, Closing Balance: '5000'", closure.Timestamp); AccountLog.Add(logMessage); Status = AccountStatus.Closed; diff --git a/EventSourcing/Events/CurrencyChangeEvent.cs b/EventSourcing/Events/CurrencyChangeEvent.cs index 0aabdf8..0716eaa 100644 --- a/EventSourcing/Events/CurrencyChangeEvent.cs +++ b/EventSourcing/Events/CurrencyChangeEvent.cs @@ -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; } }