Пример #1
0
 public BankAccountBuilder(OId <BankAccount, Guid> id)
 {
     this.id         = id;
     employeeId      = OId.Of <Employee, Guid>(Guid.Parse("309dc64d-bde5-4ee5-9e21-33a517e2fe35"));
     accountHolderId = OId.Of <AccountHolder, Guid>(Guid.Parse("59ed2782-881b-49a9-8230-d0b3bb1c9072"));
     iban            = Iban.Of("DE37200505501340426749");
     accountCurrency = Currency.Euro;
 }
Пример #2
0
        public async Task <OId <BankAccount, Guid> > Handle(CreateBankAccount request, CancellationToken cancellationToken)
        {
            var bankAccountId = OId.Of <BankAccount, Guid>(UniqueId.New());
            var bankAccount   = BankAccount.New(bankAccountId, request.AccountHolderId, request.Iban, request.AccountCurrency, request.EmployeeId, request.TimeStamp);
            await bankAccountRepository.SaveAsync(bankAccount).ConfigureAwait(false);

            return(bankAccountId);
        }
Пример #3
0
        private static Task CreateAccountAsync(IMediator mediator)
        {
            System.Console.Clear();
            System.Console.Write("IBAN: ");
            var iban = Iban.Of(System.Console.ReadLine());
            var createBankAccount = new CreateBankAccount(OId.Of <AccountHolder, Guid>(Guid.NewGuid()),
                                                          OId.Of <Employee, Guid>(EmployeeId),
                                                          Currency.Euro,
                                                          iban,
                                                          TimeStamp.Of(DateTimeOffset.Now.ToUnixTimeSeconds()));

            return(mediator.Send(createBankAccount));
        }
Пример #4
0
        private static Task Deposit(IMediator mediator, AvailableAccountsProjection availableAccountsProjection)
        {
            System.Console.Clear();
            System.Console.Write("IBAN: ");
            var iban = Iban.Of(System.Console.ReadLine());

            System.Console.Write("Amount: ");
            var amount        = decimal.Parse(System.Console.ReadLine());
            var bankAccountId = OId.Of <CoreDomain.BankAccount, Guid>(availableAccountsProjection.GetId(iban));
            var depositMoney  = new DepositMoney(bankAccountId,
                                                 Transaction.Of(Guid.NewGuid()),
                                                 new Money(amount, Currency.Euro),
                                                 TimeStamp.Of(DateTimeOffset.Now.ToUnixTimeSeconds()));

            return(mediator.Send(depositMoney));
        }
Пример #5
0
        public void CreateNewBankAccount_Always_SavesNewBankAccount()
        {
            var       bankAccountRepository = Substitute.For <IBankAccountRepository>();
            var       systemUnderTest       = new CreateBankAccountHandler(bankAccountRepository);
            var       employeeId            = OId.Of <Employee, Guid>(Guid.Parse("309dc64d-bde5-4ee5-9e21-33a517e2fe35"));
            var       accountHolderId       = OId.Of <AccountHolder, Guid>(Guid.Parse("59ed2782-881b-49a9-8230-d0b3bb1c9072"));
            var       iban              = Iban.Of("DE37200505501340426749");
            const int unixTimestamp     = 1;
            var       command           = new CreateBankAccount(accountHolderId, employeeId, Currency.Euro, iban, TimeStamp.Of(unixTimestamp));
            var       expectedAccountId = Guid.Parse("5fd9c8fe-2a2c-4d76-9c57-2460dd516dbf");

            UniqueId.OverrideNewGuid(expectedAccountId);

            systemUnderTest.Handle(command, CancellationToken.None).GetAwaiter().GetResult();

            var expectedEvents = new BankAccountEvent[] { new BankAccountCreated(expectedAccountId, accountHolderId.Value, iban.Value, Currency.Euro.Value, employeeId.Value, unixTimestamp) };

            bankAccountRepository.Received()
            .SaveAsync(Arg.Is <BankAccount>(it => it.IsCorrectBankAccount(aggregate =>
                                                                          aggregate.Id.Value.Equals(expectedAccountId) &&
                                                                          aggregate.Version == 1 &&
                                                                          aggregate.GetUncommittedEvents().SequenceEqual(expectedEvents))));
            UniqueId.ResetOverride();
        }