Example #1
0
        public async Task Transfer_ValidAmounts_CreditAndDebitCorrectly()
        {
            // Arrange
            IDateTime time    = new MockDateTime();
            var       context = FakeContext.Get();

            // Act
            var sut = new CreateAccountTransferCommandHandler(context, time);
            await sut.Handle(new CreateAccountTransferCommand { AccountIdFrom = 1, AccountIdTo = 2, Amount = 250m }, CancellationToken.None);

            // Assert
            var accOne = context.Accounts.Single(a => a.AccountId == 1);
            var accTwo = context.Accounts.Single(a => a.AccountId == 2);

            accOne.Balance.ShouldBe(250m);
            accTwo.Balance.ShouldBe(750m);
        }
Example #2
0
        public async Task Transfer_NegativeAmount_ThrowsException()
        {
            // Arrange
            IDateTime time    = new MockDateTime();
            var       context = FakeContext.Get();

            // Act
            var sut = new CreateAccountTransferCommandHandler(context, time);

            //Assert
            await Assert.ThrowsAsync <NegativeAmountException>(() =>
                                                               sut.Handle(new CreateAccountTransferCommand
            {
                AccountIdFrom = 1, AccountIdTo = 2, Amount = -200m
            }, CancellationToken.None));

            context.Accounts.Single(a => a.AccountId == 1).Balance.ShouldBe(500m);
        }
Example #3
0
        public async Task Transfer_ValidAmounts_CreateTransactions()
        {
            // Arrange
            IDateTime time    = new MockDateTime();
            var       context = FakeContext.Get();

            // Act
            var sut = new CreateAccountTransferCommandHandler(context, time);
            await sut.Handle(new CreateAccountTransferCommand { AccountIdFrom = 1, AccountIdTo = 2, Amount = 250m }, CancellationToken.None);

            // Assert
            var transactionFrom = context.Transactions.Single(t => t.AccountId == 1);
            var transactionTo   = context.Transactions.Single(t => t.AccountId == 2);

            transactionFrom.Operation.ShouldBe(Operation.TransferDebit);
            transactionFrom.Type.ShouldBe(TransactionType.Debit);
            transactionFrom.Amount.ShouldBe(-250m);
            transactionFrom.Balance.ShouldBe(250m);
            transactionTo.Operation.ShouldBe(Operation.Transfer);
            transactionTo.Type.ShouldBe(TransactionType.Credit);
            transactionTo.Amount.ShouldBe(250m);
            transactionTo.Balance.ShouldBe(750m);
        }