Esempio n. 1
0
        public void DepositMoney_WithCurrencyMismatch_Throws(decimal amount, string currency, string accountCurrency)
        {
            var transaction           = Transaction.Of(Guid.Parse("f0ad5ace-c64f-4f82-9487-a26b376dcf8b"));
            var bankAccountRepository = Substitute.For <IBankAccountRepository>();
            var systemUnderTest       = new DepositMoneyHandler(bankAccountRepository);
            var bankAccount           = RehydrateWithCreatedEvent(DefaultBankAccountId, Currency.Of(accountCurrency));
            var command = new DepositMoney(DefaultBankAccountId, transaction, new Money(amount, Currency.Of(currency)), TimeStamp.Of(1));

            bankAccountRepository.GetByIdAsync(DefaultBankAccountId).Returns(Task.FromResult(bankAccount));

            systemUnderTest.Awaiting(it => systemUnderTest.Handle(command, CancellationToken.None)).Should().Throw <CurrencyMismatchException>();
        }
Esempio n. 2
0
        public void DepositMoney_WithBankAccountNotCreated_Throws()
        {
            var bankAccountRepository = Substitute.For <IBankAccountRepository>();
            var systemUnderTest       = new DepositMoneyHandler(bankAccountRepository);
            var transaction           = Transaction.Of(Guid.Parse("f0ad5ace-c64f-4f82-9487-a26b376dcf8b"));
            var command     = new DepositMoney(DefaultBankAccountId, transaction, new Money(100, Currency.Euro), TimeStamp.Of(1));
            var bankAccount = BankAccount.Rehydrate(DefaultBankAccountId, Enumerable.Empty <BankAccountEvent>());

            bankAccountRepository.GetByIdAsync(DefaultBankAccountId).Returns(Task.FromResult(bankAccount));

            systemUnderTest.Awaiting(it => systemUnderTest.Handle(command, CancellationToken.None)).Should().Throw <ConstraintViolationException>();
        }
Esempio n. 3
0
        public void DepositMoney_WithCorrectCurrency_DepositsMoneyInAccount(decimal amount, string currency)
        {
            var bankAccountRepository = Substitute.For <IBankAccountRepository>();
            var systemUnderTest       = new DepositMoneyHandler(bankAccountRepository);
            var transaction           = Transaction.Of(Guid.Parse("f0ad5ace-c64f-4f82-9487-a26b376dcf8b"));
            var accountCurrency       = Currency.Of(currency);
            var command     = new DepositMoney(DefaultBankAccountId, transaction, new Money(amount, accountCurrency), TimeStamp.Of(1));
            var bankAccount = RehydrateWithCreatedEvent(DefaultBankAccountId, accountCurrency);

            bankAccountRepository.GetByIdAsync(DefaultBankAccountId).Returns(Task.FromResult(bankAccount));

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

            var expectedEvents = new BankAccountEvent[] { new MoneyDeposited(DefaultBankAccountId.Value, transaction.Value, amount, 1) };

            bankAccountRepository.Received()
            .SaveAsync(Arg.Is <BankAccount>(it => it.IsCorrectBankAccount(aggregate =>
                                                                          aggregate.Version == 2 &&
                                                                          aggregate.InitialVersion == 0 &&
                                                                          aggregate.GetUncommittedEvents().SequenceEqual(expectedEvents))));
        }