コード例 #1
0
        public void Executive_GivenValidAmount_UpdateAccounts()
        {
            var fromAccount = new AccountBuilder().WithBalance(0.01m).Build();
            var toAccount   = new AccountBuilder().WithBalance(0m).Build();
            var amount      = 0.01m;

            var mockRepository = new Mock <IAccountRepository>();

            mockRepository
            .Setup(repo => repo.GetAccountById(fromAccount.Id))
            .Returns(fromAccount);

            mockRepository
            .Setup(repo => repo.GetAccountById(toAccount.Id))
            .Returns(toAccount);

            var sut = new TransferMoney(mockRepository.Object);

            sut.Execute(fromAccount.Id, toAccount.Id, amount);

            mockRepository.Verify(repo => repo.Update(It.Is <Account>(account =>
                                                                      account.Id == fromAccount.Id &&
                                                                      account.Balance == 0m)));

            mockRepository.Verify(repo => repo.Update(It.Is <Account>(account =>
                                                                      account.Id == toAccount.Id &&
                                                                      account.Balance == 0.01m)));
        }
コード例 #2
0
        public void CanPayInAmount_GivenValidAmount_ReturnSuccessfulResult()
        {
            var sut = new AccountBuilder().WithPaidIn(Account.PayInLimit - 0.01m).Build();

            var result = sut.CanPayInAmount(0.01m);

            Assert.True(result.Success);
        }
コード例 #3
0
        public void CanPayInAmount_GivenAmountLessThanZero_ReturnFailedResult()
        {
            var sut = new AccountBuilder().Build();

            var result = sut.CanPayInAmount(-0.01m);

            Assert.False(result.Success);
        }
コード例 #4
0
        public void CanPayInAmount_GivenPayInLimitIsExceeded_ReturnFailedResult()
        {
            var sut = new AccountBuilder().WithPaidIn(Account.PayInLimit).Build();

            var result = sut.CanPayInAmount(0.01m);

            Assert.False(result.Success);
        }
コード例 #5
0
        public void CanWithdrawAmount_GivenMinimumAllowedBalanceIsExceeded_ReturnFailedResult()
        {
            var sut = new AccountBuilder().WithBalance(0m).Build();

            var result = sut.CanWithdrawAmount(0.01m);

            Assert.False(result.Success);
        }
コード例 #6
0
        public void CanWithdrawAmount_GivenValidAmount_ReturnSuccessfulResult()
        {
            var sut = new AccountBuilder().WithBalance(0.01m).Build();

            var result = sut.CanWithdrawAmount(0.01m);

            Assert.True(result.Success);
        }
コード例 #7
0
        public void WithdrawAmount_GivenValidAmount_UpdateBalanceAndWithdrawnAmounts()
        {
            var sut = new AccountBuilder().WithBalance(0.02m).Build();

            sut.WithdrawAmount(0.01m);

            Assert.Equal(0.01m, sut.Balance);
            Assert.Equal(-0.01m, sut.Withdrawn);
        }
コード例 #8
0
        public void PayInAmount_GivenValidAmount_UpdateBalanceAndPaidInAmount()
        {
            var sut = new AccountBuilder().WithBalance(0).Build();

            sut.PayInAmount(0.01m);

            Assert.Equal(0.01m, sut.Balance);
            Assert.Equal(0.01m, sut.PaidIn);
        }
コード例 #9
0
        public void PayInAmount_GivenPayInLimitDifferenceThresholdNotExceeded_DoNotNotifyUser()
        {
            var notificationServiceMock = new Mock <INotificationService>();
            var user = new User(notificationServiceMock.Object);

            var sut = new AccountBuilder()
                      .WithUser(user)
                      .WithPaidIn(Account.PayInLimit - Account.PayInLimitDifferenceThreshold - 0.01m)
                      .Build();

            sut.PayInAmount(0.01m);

            notificationServiceMock.Verify(service => service.NotifyApproachingPayInLimit(It.IsAny <string>()), Times.Never);
        }
コード例 #10
0
        public void WithdrawAmount_GivenBalanceIsAboveLowBalanceThreshold_DoNotNotifyUser()
        {
            var notificationServiceMock = new Mock <INotificationService>();
            var user = new User(notificationServiceMock.Object);

            var sut = new AccountBuilder()
                      .WithBalance(Account.LowBalanceThreshold + 0.01m)
                      .WithUser(user)
                      .Build();

            sut.WithdrawAmount(0.01m);

            notificationServiceMock.Verify(service => service.NotifyFundsLow(It.IsAny <string>()), Times.Never);
        }
コード例 #11
0
        public void WithdrawAmount_GivenBalanceIsBelowLowBalanceThreshold_NotifyUser()
        {
            var notificationServiceMock = new Mock <INotificationService>();
            var user = new User(notificationServiceMock.Object);

            user.Email = "*****@*****.**";

            var sut = new AccountBuilder()
                      .WithBalance(0.02m)
                      .WithUser(user)
                      .Build();

            sut.WithdrawAmount(0.01m);

            notificationServiceMock.Verify(service => service.NotifyFundsLow(user.Email));
        }
コード例 #12
0
        public void PayInAmount_GivenPayInLimitDifferenceThresholdExceeded_NotifyUser()
        {
            var notificationServiceMock = new Mock <INotificationService>();
            var user = new User(notificationServiceMock.Object);

            user.Email = "*****@*****.**";

            var sut = new AccountBuilder()
                      .WithUser(user)
                      .WithPaidIn(Account.PayInLimit - Account.PayInLimitDifferenceThreshold)
                      .Build();

            sut.PayInAmount(0.01m);

            notificationServiceMock.Verify(service => service.NotifyApproachingPayInLimit(user.Email));
        }
コード例 #13
0
        public void Execute_GivenInvalidAmount_ThrowException()
        {
            var fromAccount = new AccountBuilder().WithBalance(0).Build();
            var toAccount   = new AccountBuilder().Build();
            var amount      = 0.01m;

            var mockRepository = new Mock <IAccountRepository>();

            mockRepository
            .Setup(repo => repo.GetAccountById(fromAccount.Id))
            .Returns(fromAccount);

            mockRepository
            .Setup(repo => repo.GetAccountById(toAccount.Id))
            .Returns(toAccount);

            var sut = new TransferMoney(mockRepository.Object);

            Assert.Throws <InvalidOperationException>(() => sut.Execute(fromAccount.Id, toAccount.Id, amount));
        }
コード例 #14
0
        public void WithdrawAmount_GivenInvalidAmount_ThrowException()
        {
            var sut = new AccountBuilder().WithBalance(0m).Build();

            Assert.Throws <InvalidOperationException>(() => sut.WithdrawAmount(0.01m));
        }
コード例 #15
0
        public void PayInAmount_GivenInvalidAmount_ThrowException()
        {
            var sut = new AccountBuilder().WithPaidIn(Account.PayInLimit).Build();

            Assert.Throws <InvalidOperationException>(() => sut.PayInAmount(0.01m));
        }