improve output
This commit is contained in:
@@ -11,6 +11,8 @@ public abstract record AccountCommand
|
||||
public sealed record WithdrawMoney(Guid AccountId, Money Amount) : AccountCommand;
|
||||
|
||||
public sealed record DepositMoney(Guid AccountId, Money Amount) : AccountCommand;
|
||||
|
||||
public sealed record UnhandledTestCommand() : AccountCommand;
|
||||
}
|
||||
|
||||
public abstract record AccountEvent(Guid AccountId)
|
||||
@@ -31,7 +33,7 @@ public abstract record AccountError
|
||||
|
||||
public sealed record OpeningBalanceMustBeNonNegative : AccountError;
|
||||
|
||||
public sealed record InnerException(Exception exception) : AccountError;
|
||||
public sealed record InnerException(string Message) : AccountError;
|
||||
}
|
||||
|
||||
public static class AccountDecider
|
||||
@@ -75,7 +77,7 @@ public static class AccountDecider
|
||||
|
||||
_ => throw new InvalidOperationException("Unknown command."),
|
||||
},
|
||||
e => new AccountError.InnerException(e)
|
||||
e => new AccountError.InnerException(e.Message)
|
||||
);
|
||||
|
||||
public static Result<AccountState?, AccountError> Evolve(
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace CsharpEs.Library;
|
||||
|
||||
public static class Logging
|
||||
@@ -23,18 +20,7 @@ public static class Logging
|
||||
}
|
||||
|
||||
public static string Format(Object? o) =>
|
||||
o != null
|
||||
? Indent(
|
||||
JsonSerializer.Serialize(
|
||||
o,
|
||||
new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true,
|
||||
Converters = { new JsonStringEnumConverter() },
|
||||
}
|
||||
)
|
||||
)
|
||||
: "(null)";
|
||||
Indent(ObjectDumper.Dump(o, new DumpOptions() { DumpStyle = DumpStyle.CSharp }));
|
||||
|
||||
public static void Output(string src, string message, Object? x)
|
||||
{
|
||||
|
||||
+13
-8
@@ -19,10 +19,13 @@ public class Program
|
||||
{
|
||||
accountId = Guid.NewGuid();
|
||||
demoCommands = demoCommands.AddRange([
|
||||
new AccountCommand.OpenAccount(accountId, new Money(-200m)),
|
||||
// new AccountCommand.OpenAccount(accountId, new Money(200m)),
|
||||
// bring this in to see an error right from the start
|
||||
// new AccountCommand.OpenAccount(accountId, new Money(-200m)),
|
||||
new AccountCommand.OpenAccount(accountId, new Money(200m)),
|
||||
new AccountCommand.WithdrawMoney(accountId, new Money(100m)),
|
||||
new AccountCommand.WithdrawMoney(accountId, new Money(200m)),
|
||||
// or maybe an exception in between?
|
||||
// new AccountCommand.UnhandledTestCommand(),
|
||||
new AccountCommand.DepositMoney(accountId, new Money(500m)),
|
||||
]);
|
||||
}
|
||||
@@ -65,12 +68,14 @@ public class Program
|
||||
.Aggregate(
|
||||
Result<AccountState?, DemoError>.Ok(null),
|
||||
(stateResult, command) =>
|
||||
stateResult.Bind(state =>
|
||||
AccountDecider
|
||||
.Decide(state, command)
|
||||
.MapError(e => (DemoError)new DemoError.Account(e))
|
||||
.Bind(@event => ApplyEvent(readModel, state, @event))
|
||||
)
|
||||
stateResult
|
||||
.Bind(state =>
|
||||
AccountDecider
|
||||
.Decide(state, command)
|
||||
.MapError(e => (DemoError)new DemoError.Account(e))
|
||||
.Bind(@event => ApplyEvent(readModel, state, @event))
|
||||
)
|
||||
.Log("loop", "Intermediate state")
|
||||
)
|
||||
.Bind(s =>
|
||||
readModel
|
||||
|
||||
@@ -6,4 +6,7 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ObjectDumper.NET" Version="4.3.2" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user