Esempio n. 1
0
        static void Main(string[] args)
        {
            var log = new LoggerConfiguration()
                      .WriteTo.ColoredConsole(outputTemplate: "{Timestamp:HH:mm} [{Level}] ({Name:l}) {Message}{NewLine}{Exception}")
                      .MinimumLevel.Debug()
                      .CreateLogger();

            Log.Logger = log;

            log.Information("Event sourcing sample");

            var accountId = Guid.NewGuid();

            var repo = RepositoryFactory.CreateAsync().Result;

            log.Information("Initialising provider");
            StorageProviderInitialiser.InitAsync().Wait();
            log.Information("Provider initialised");

            log.Information("Tearing down provider");
            var cleaner = TearDownFactory.CreateAsync().Result;

            cleaner.TearDownAsync().Wait();
            log.Information("StorageProviderFactory torn down");

            var handler = new BankAccountCommandHandlers(repo);

            log.Information("Running set of commands");

            handler.HandleAsync(new CreateAccountCommand(Guid.NewGuid(), accountId, "Joe Bloggs")).Wait();
            handler.HandleAsync(new DepositFundsCommand(Guid.NewGuid(), accountId, 10)).Wait();
            handler.HandleAsync(new DepositFundsCommand(Guid.NewGuid(), accountId, 35)).Wait();
            handler.HandleAsync(new WithdrawFundsCommand(Guid.NewGuid(), accountId, 25)).Wait();
            handler.HandleAsync(new DepositFundsCommand(Guid.NewGuid(), accountId, 5)).Wait();
            handler.HandleAsync(new WithdrawFundsCommand(Guid.NewGuid(), accountId, 10)).Wait();

            log.Information("Commands Run");

            log.Information("Get aggregate from store");

            var fromStore = repo.GetByIdAsync <BankAccount>(accountId).Result;

            log.Information($"Bank account ID: {fromStore.Id}");
            log.Information($"Balance: {fromStore.CurrentBalance}");
            log.Information($"Last committed version: {fromStore.LastCommittedVersion}");
            log.Information($"Transaction Count: {fromStore.Transactions.Count}");

            log.Information("Event sourcing sample ran");

            System.Console.ReadLine();
        }
Esempio n. 2
0
 private static Task SetupAsync()
 {
     return(StorageProviderInitialiser.InitAsync());
 }
 public EventStorageProviderTests()
 {
     _provider = EventStorageProviderFactory.CreateAsync().Result;
     StorageProviderInitialiser.InitAsync().Wait();
 }