コード例 #1
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>();
        }
コード例 #2
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>();
        }