public void SuccessfulWithdrawUpdatesFromAccount([Values(1, 2000, 4000)] decimal amount)
        {
            withdrawMoney.Execute(
                TestAccountFactory.Ids.DefaultFrom,
                amount);

            // Ensure that the account is updated
            AccountRepositoryMock.Verify(x => x.Update(It.IsAny <Account>()), Times.Exactly(1));

            UpdatedAccounts.TryGetValue(TestAccountFactory.Ids.DefaultFrom, out var fromAfter).Should().BeTrue();

            // Ensure that the from balance and withdrawn properties have correct values after the withdrawal
            fromAfter.Balance.Should().Be(TestAccountFactory.DefaultBalance - amount);
            fromAfter.Withdrawn.Should().Be(TestAccountFactory.DefaultWithdrawn - amount);
        }
        public void ExceptionThrownOnNonPositiveAmount([Values(-1, 0)] decimal amount)
        {
            Action transferAction = () => withdrawMoney.Execute(
                TestAccountFactory.Ids.DefaultFrom,
                amount);

            transferAction.Should().Throw <InvalidOperationException>();

            // Ensure that no notifications were sent
            NotificationServiceMock.Verify(x => x.NotifyApproachingPayInLimit(It.IsAny <string>()), Times.Never);
            NotificationServiceMock.Verify(x => x.NotifyFundsLow(It.IsAny <string>()), Times.Never);

            // Ensure that the account was not updated
            AccountRepositoryMock.Verify(x => x.Update(It.IsAny <Account>()), Times.Never);
        }
        public void ExceptionThrownOnInsufficientFunds()
        {
            var amount = TestAccountFactory.DefaultBalance + 1m;

            Action withdrawalAction = () => withdrawMoney.Execute(
                TestAccountFactory.Ids.DefaultFrom,
                amount);

            withdrawalAction.Should().Throw <InvalidOperationException>();

            // Ensure that no notifications were sent
            NotificationServiceMock.Verify(x => x.NotifyApproachingPayInLimit(It.IsAny <string>()), Times.Never);
            NotificationServiceMock.Verify(x => x.NotifyFundsLow(It.IsAny <string>()), Times.Never);

            // Ensure that the account was not updated
            AccountRepositoryMock.Verify(x => x.Update(It.IsAny <Account>()), Times.Never);
        }
Пример #4
0
        public void ExceptionThrownOnFromToSameAccount()
        {
            var amount = 1m;

            Action transferAction = () => transferMoney.Execute(
                TestAccountFactory.Ids.DefaultFrom,
                TestAccountFactory.Ids.DefaultFrom,
                amount);

            transferAction.Should().Throw <InvalidOperationException>();

            // Ensure that no notifications were sent
            NotificationServiceMock.Verify(x => x.NotifyApproachingPayInLimit(It.IsAny <string>()), Times.Never);
            NotificationServiceMock.Verify(x => x.NotifyFundsLow(It.IsAny <string>()), Times.Never);

            // Ensure that neither account was updated
            AccountRepositoryMock.Verify(x => x.Update(It.IsAny <Account>()), Times.Never);
        }
Пример #5
0
        public void SuccessfulTransferUpdatesFromAndToAccounts([Values(1, 2000, 4000)] decimal amount)
        {
            transferMoney.Execute(
                TestAccountFactory.Ids.DefaultFrom,
                TestAccountFactory.Ids.DefaultTo,
                amount);

            // Ensure that both accounts are updated
            AccountRepositoryMock.Verify(x => x.Update(It.IsAny <Account>()), Times.Exactly(2));

            UpdatedAccounts.TryGetValue(TestAccountFactory.Ids.DefaultFrom, out var fromAfter).Should().BeTrue();
            UpdatedAccounts.TryGetValue(TestAccountFactory.Ids.DefaultTo, out var toAfter).Should().BeTrue();

            // Ensure that the balance and withdrawn properties have correct values after the transfer
            fromAfter.Balance.Should().Be(TestAccountFactory.DefaultBalance - amount);
            fromAfter.Withdrawn.Should().Be(TestAccountFactory.DefaultWithdrawn - amount);
            toAfter.Balance.Should().Be(TestAccountFactory.DefaultBalance + amount);
        }