public void TransactionQueryHandler_TransactionQueryNotEmptyDatabaseWithQuery_MatchingArray() { //given var repository = LiteDbHelper.CreateMemoryDb(); var handler = new TransactionQueryHandler(repository); Expression <Func <Transaction, bool> > linqQuery = x => x.Title.Contains("1"); var query = new TransactionQuery(linqQuery); var transactions = new[] { new Transaction(new Guid(1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1)) { Title = "t1" }, new Transaction(new Guid(1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 2)) { Title = "t2" } }; repository.Database.GetCollection <Transaction>().InsertBulk(transactions); var matchingTransactions = transactions.AsQueryable().Where(linqQuery).ToArray(); //when var result = handler.Execute(query); //then Assert.Equal(matchingTransactions.Length, result.Length); Assert.Equal(matchingTransactions, result); }
public async void ShouldReturnTransactionsForBankAccount() { var query = new TransactionQuery("ABankAccountId"); var bankAccount = new BankAccount(); var transaction1 = new Transaction { Amount = 12.34m, Type = TransactionType.Deposit, Id = "1", Description = "Description 1" }; var transaction2 = new Transaction { Amount = 99.99m, Type = TransactionType.Deposit, Id = "2", Description = "Description 2" }; var transaction3 = new Transaction { Amount = 5663.99m, Type = TransactionType.Deposit, Id = "3", Description = "Description 3" }; IEnumerable <Transaction> transactions = new List <Transaction> { transaction1, transaction2, transaction3 }; var bankAccountRepository = new Mock <IRepository <Transaction> >(); bankAccountRepository .Setup(mock => mock.Get( It.IsAny <Expression <Func <Transaction, bool> > >(), It.IsAny <Func <IQueryable <Transaction>, IOrderedQueryable <Transaction> > >(), It.IsAny <string>())) .Returns(Task.Run(() => transactions)); var unitOfWork = new Mock <IRepositoryFacade>(); unitOfWork .Setup(mock => mock.TransactionsRepository) .Returns(bankAccountRepository.Object); var handler = new TransactionQueryHandler(unitOfWork.Object); var actualTransactions = await handler.Handle(query, new CancellationToken()); actualTransactions.Should().ContainInOrder(transaction1, transaction2, transaction3); }
public void TransactionQueryHandler_TransactionQueryEmptyDatabase_EmptyArray() { //given var repository = LiteDbHelper.CreateMemoryDb(); var handler = new TransactionQueryHandler(repository); var query = new TransactionQuery(); //when var result = handler.Execute(query); //then Assert.NotNull(result); Assert.Empty(result); }
public void TransactionQueryHandler_TransactionQueryNotEmptyDatabaseWithNoQuery_AllTransactions() { //given var repository = LiteDbHelper.CreateMemoryDb(); var handler = new TransactionQueryHandler(repository); var query = new TransactionQuery(); var transactions = new[] { new Transaction(new Guid(1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1)), new Transaction(new Guid(1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 2)) }; repository.Database.GetCollection <Transaction>().InsertBulk(transactions); //when var result = handler.Execute(query); //then Assert.Equal(transactions.OrderBy(x => x.Id), result.OrderBy(x => x.Id)); }
public WebAPIController() { accountQueriesHandler = new AccountQueriesHandler(); transactionQueryHandler = new TransactionQueryHandler(); customerQueriesHandler = new CustomerQueriesHandler(); }