Ejemplo n.º 1
0
        public async Task ShouldReturnAllAsync()
        {
            AccountRepositoryMock.Setup(x => x.GetAllAsync())
            .Returns(Task.FromResult(Accounts));

            var response = await TestClient.GetAsync("Account");

            var content = await response.Content.ReadAsStringAsync();

            var result = JsonConvert.DeserializeObject <List <AccountDto> >(content);

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Equal(1, result.Count);
        }
        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);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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);
        }