Skip to content

Commit

Permalink
Fix: multiple logs enabled with a disabled account
Browse files Browse the repository at this point in the history
  • Loading branch information
GreRut committed Nov 11, 2024
1 parent f2e654e commit 626285a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
16 changes: 8 additions & 8 deletions EventSourcing.Test/AccountAggregateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,12 @@ public async void Should_Add_Aditional_DeactivateEvent_ToAccountLog()
new (
Type: "DEACTIVATE",
Message: "Account inactive for 270 days",
Timestamp: DateTime.Parse("2024-10-02T10:30:00Z")
Timestamp: DateTime.Parse("2024-10-02T10:30:00")
),
new (
Type: "DEACTIVATE",
Message: "Security alert: suspicious activity",
Timestamp: DateTime.Parse("2024-10-03T10:30:00Z")
Timestamp: DateTime.Parse("2024-10-03T10:30:00")
),
]
};
Expand Down Expand Up @@ -358,12 +358,12 @@ public async void ActivateEvent_Should_AddEventToAccountLog()
new (
Type: "DEACTIVATE",
Message: "Account inactive for 270 days",
Timestamp: DateTime.Parse("2024-10-02T10:30:00Z")
Timestamp: DateTime.Parse("2024-10-02T10:30:00")
),
new (
Type: "ACTIVATE",
Message: "Account reactivated",
Timestamp: DateTime.Parse("2024-10-03T10:30:00Z")
Timestamp: DateTime.Parse("2024-10-03T10:30:00")
),
]
};
Expand Down Expand Up @@ -391,12 +391,12 @@ public async void ActivateEvent_ShouldNot_AddEventToAccountLog_IfAccountIsAlread
new (
Type: "DEACTIVATE",
Message: "Account inactive for 270 days",
Timestamp: DateTime.Parse("2024-10-02T10:30:00Z")
Timestamp: DateTime.Parse("2024-10-02T10:30:00")
),
new (
Type: "ACTIVATE",
Message: "Account reactivated",
Timestamp: DateTime.Parse("2024-10-03T10:30:00Z")
Timestamp: DateTime.Parse("2024-10-03T10:30:00")
),
]
};
Expand Down Expand Up @@ -445,7 +445,7 @@ public async void ClosureEvent_Should_AddEventToAccountLog()
new (
Type: "CLOSURE",
Message: "Reason: Customer request, Closing Balance: '5000'",
Timestamp: DateTime.Parse("2024-10-02T10:30:00Z")
Timestamp: DateTime.Parse("2024-10-02T10:30:00")
),
]
};
Expand Down Expand Up @@ -508,7 +508,7 @@ public async void CurrencyChangeEvent_Should_AddEventToAccountLog()
new (
Type: "CURRENCY-CHANGE",
Message: "Change currency from 'USD' to 'SEK'",
Timestamp: DateTime.Parse("2024-10-02T10:30:00Z")
Timestamp: DateTime.Parse("2024-10-02T10:30:00")
),
]
};
Expand Down
12 changes: 5 additions & 7 deletions EventSourcing/AccountAggregate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,11 @@ private void Apply(WithdrawalEvent withdrawal)
private void Apply(DeactivationEvent deactivation)
{
Status = AccountStatus.Disabled;
AccountLog = [
new (
Type: "DEACTIVATE",
Message: "Account inactive for 270 days",
Timestamp: DateTime.Parse("2024-10-02T10:30:00")
),
];
if (AccountLog == null)
AccountLog = new List<LogMessage>();
var logMessage = new LogMessage("DEACTIVATE", deactivation.Reason.ToString(), deactivation.Timestamp);
AccountLog.Add(logMessage);

}

private void Apply(ActivationEvent activation)
Expand Down

0 comments on commit 626285a

Please sign in to comment.