public async Task FindByDateRange_WhenEntersRange_Test() { var startDate = new DateTime(2018, 1, 1); var endDate = new DateTime(2018, 1, 4); var category = CategoryData.CreateCategory(Guid.NewGuid()); var transaction1 = TransactionData.CreateTransaction(Guid.NewGuid(), startDate, category: category); var transaction2 = TransactionData.CreateTransaction(Guid.NewGuid(), startDate.AddDays(1), category: category); var transaction3 = TransactionData.CreateTransaction(Guid.NewGuid(), startDate.AddDays(2), category: category); var transaction4 = TransactionData.CreateTransaction(Guid.NewGuid(), startDate.AddDays(3), category: category); await CommitCreateAsync(category); await CommitCreateAsync(transaction1); await CommitCreateAsync(transaction2); await CommitCreateAsync(transaction3); await CommitCreateAsync(transaction4); var dateRangeQuery = new DateRangeQuery(new DateQuery(startDate), new DateQuery(endDate)); var foundTransactions = await TransactionRepository.FindAsync(new TransactionQuery(dateRangeQuery)); Assert.That(foundTransactions, Is.EquivalentTo(new[] { transaction1, transaction2, transaction3, transaction4 })); }
public void ThrowStaleObjectStateExceptionChangeIfNotExistsTest() { var id = Guid.NewGuid(); var category = CategoryData.CreateCategory(id); var description = "Orange"; Assert.ThrowsAsync <StaleObjectStateException>(async() => { category.ChangeDescription(description); await CommitChangeAsync(category); }); }
public async Task CreateTest() { var id = Guid.NewGuid(); var category = CategoryData.CreateCategory(id); await CommitCreateAsync(category); var expected = category; var actual = await CategoryRepository.GetAsync(id); Assert.AreEqual(expected, actual); }
public async Task FindByTypeTest() { var category1 = CategoryData.CreateCategory(Guid.NewGuid(), type: Domain.Enums.CategoryType.Income); var category2 = CategoryData.CreateCategory(Guid.NewGuid(), type: Domain.Enums.CategoryType.Expenditure); var category3 = CategoryData.CreateCategory(Guid.NewGuid(), type: Domain.Enums.CategoryType.Expenditure); var category4 = CategoryData.CreateCategory(Guid.NewGuid(), type: Domain.Enums.CategoryType.None); await CommitCreateAsync(category1); await CommitCreateAsync(category2); await CommitCreateAsync(category3); await CommitCreateAsync(category4); var foundCategories = await CategoryRepository.FindAsync(new Domain.Queries.CategoryQuery(Domain.Enums.CategoryType.Income)); Assert.That(foundCategories, Is.EquivalentTo(new[] { category1 })); }
public async Task RemoveByIdTest() { var id = Guid.NewGuid(); var category = CategoryData.CreateCategory(id); await CommitCreateAsync(category); var existing = await CategoryRepository.GetAsync(id); Assert.That(existing, Is.Not.Null); await CommitRemoveByIdAsync(id); var notExisting = await CategoryRepository.GetAsync(id); Assert.That(notExisting, Is.Null); }
public async Task ChangeTest() { var id = Guid.NewGuid(); var category = CategoryData.CreateCategory(id); var description = "Orange"; await CommitCreateAsync(category); category.ChangeDescription(description); await CommitChangeAsync(category); var expected = category; var actual = await CategoryRepository.GetAsync(id); Assert.AreEqual(expected, actual); }
private async Task <Domain.DomainModels.Category[]> CreateCategoriesAsync() { var category1 = CategoryData.CreateCategory(Guid.NewGuid(), name: "Business", description: "Site", type: Domain.Enums.CategoryType.Income); var category2 = CategoryData.CreateCategory(Guid.NewGuid(), name: "Products", description: "Apple", type: Domain.Enums.CategoryType.Expenditure); var category3 = CategoryData.CreateCategory(Guid.NewGuid(), name: "Products", description: "Orange", type: Domain.Enums.CategoryType.Expenditure); var category4 = CategoryData.CreateCategory(Guid.NewGuid(), name: string.Empty, description: string.Empty, type: Domain.Enums.CategoryType.None); await CommitCreateAsync(category1); await CommitCreateAsync(category2); await CommitCreateAsync(category3); await CommitCreateAsync(category4); return(new[] { category1, category2, category3, category4 }); }
public async Task GetCategoryStatisticByDateRangeTest() { var category1 = CategoryData.CreateCategory(Guid.NewGuid(), "Products", "Orange", Enums.CategoryType.Expenditure); var category2 = CategoryData.CreateCategory(Guid.NewGuid(), "Products", "Cheese", Enums.CategoryType.Expenditure); var startDate = new DateTime(2018, 1, 1); var endDate = new DateTime(2018, 1, 2); var transaction0 = TransactionData.CreateTransaction(Guid.NewGuid(), startDate, 200, category1); var transaction1 = TransactionData.CreateTransaction(Guid.NewGuid(), endDate, 100, category2); var transaction2 = TransactionData.CreateTransaction(Guid.NewGuid(), new DateTime(2017, 1, 1)); var transaction3 = TransactionData.CreateTransaction(Guid.NewGuid(), new DateTime(2019, 1, 1)); await _transactionRepository.CreateAsync(transaction0); await _transactionRepository.CreateAsync(transaction1); await _transactionRepository.CreateAsync(transaction2); await _transactionRepository.CreateAsync(transaction3); var query = new CategoryStatisticQuery( new DateRangeQuery(new DateQuery(startDate), new DateQuery(endDate)), Enums.CategoryType.Expenditure); var statistic = await _statisticService.GetCategoryStatisticAsync(query); var expected = new CategoryStatistic(new[] { new CategoryStatisticItem(category1, 200), new CategoryStatisticItem(category2, 100) }, 300); var actual = statistic; Assert.That(expected, Is.EqualTo(actual)); }