public async Task TransactionExistForSpecifiedAccountButAreTooOld_ReturnEmptyList() { // arrange var mockDateTime = new Mock <IDateTime>(); var systemTime = DateTime.UtcNow; mockDateTime .Setup(m => m.Now) .Returns(systemTime); var mockApplicationDbContext = new Mock <IApplicationDbContext>(); var accountNumber = "ABC123"; List <Account> accounts = new List <Account>() { new() { AccountNumber = accountNumber }, new() { AccountNumber = "DEF123" } }; var stubAccounts = new StubListOfEntities <Account>(accounts); mockApplicationDbContext .Setup(m => m.Accounts) .Returns(stubAccounts); var transactionDateNotOldThenOneMonth = systemTime.AddMonths(-2); var transactions = new List <Transaction>() { new() { AccountNumber = accountNumber, TransactionDate = transactionDateNotOldThenOneMonth } }; var stubTransactions = new StubListOfEntities <Transaction>(transactions); mockApplicationDbContext .Setup(m => m.Transactions) .Returns(stubTransactions); var sut = new GetTransactionsQueryHandler(mockApplicationDbContext.Object, mockDateTime.Object); // act var result = await sut.Handle(new GetTransactionsQuery() { AccountNumber = accountNumber }, CancellationToken.None); // assert result.Should().BeEmpty(); }
public async Task MoreTransactionWithSameCategoryExistForSpecifiedAccount_OneItemWithTotalAmmountIsReturned() { // arrange var mockDateTime = new Mock <IDateTime>(); var systemTime = DateTime.UtcNow; mockDateTime .Setup(m => m.Now) .Returns(systemTime); var mockApplicationDbContext = new Mock <IApplicationDbContext>(); Account account = new() { AccountNumber = "ABC123", Currency = Currency.EUR }; List <Account> accounts = new List <Account>() { account, new() { AccountNumber = "DEF123" } }; var stubAccounts = new StubListOfEntities <Account>(accounts); mockApplicationDbContext .Setup(m => m.Accounts) .Returns(stubAccounts); var transactionDateNotOldThenOneMonth = systemTime.AddHours(-2); var transactions = new List <Transaction>() { new() { AccountNumber = account.AccountNumber, TransactionDate = transactionDateNotOldThenOneMonth, Amount = 200, CategoryId = (int)TransactionCategory.Entertainment, TransactionId = 10 }, new() { AccountNumber = account.AccountNumber, TransactionDate = transactionDateNotOldThenOneMonth, Amount = 300, CategoryId = (int)TransactionCategory.Entertainment, TransactionId = 11 } }; var stubTransactions = new StubListOfEntities <Transaction>(transactions); mockApplicationDbContext .Setup(m => m.Transactions) .Returns(stubTransactions); var sut = new GetTransactionsQueryHandler(mockApplicationDbContext.Object, mockDateTime.Object); // act var result = await sut.Handle(new GetTransactionsQuery() { AccountNumber = account.AccountNumber }, CancellationToken.None); // assert result.Should().NotBeNullOrEmpty(); result.Count.Should().Be(1); result.Any(a => a.CategoryName == TransactionCategory.Entertainment.ToString()).Should().BeTrue(); result.Any(a => a.TotalAmount == 500).Should().BeTrue(); } } }