public async Task GetTotalChangesCountAsync_DatesNulls_ChangesCountAsExpected() { // Arrange A.Configure <ItemEntity>() .Fill(i => i.ParentId) .WithRandom(new string[] { null, "not null" }); var items = A.ListOf <ItemEntity>(100); var quribleItems = items.AsQueryable().BuildMock(); var countItemsWithoutParent = items.Count(x => x.ParentId == null); var catalogRepositoryMock = new Mock <ICatalogRepository>(); var changeLogSearchServiceMock = new Mock <IChangeLogSearchService>(); catalogRepositoryMock.Setup(x => x.Items).Returns(quribleItems.Object); var productDocumentChangesProvider = new ProductDocumentChangesProvider(() => catalogRepositoryMock.Object, changeLogSearchServiceMock.Object); // Act var totalCountOfchanges = await productDocumentChangesProvider.GetTotalChangesCountAsync(null, null); // Assert catalogRepositoryMock.VerifyAll(); changeLogSearchServiceMock.VerifyAll(); Assert.Equal(countItemsWithoutParent, totalCountOfchanges); }
public async Task GetTotalChangesCountAsync_DatesNotNull_ChangesCountAsExpected(DateTime?startDate, DateTime?endDate) { // Arrange A.Configure <ItemEntity>() .Fill(i => i.ParentId) .WithRandom(new string[] { null, "not null" }) .Fill(i => i.ModifiedDate, x => DateTime.UtcNow.AddDays(A.Random.Next(DAYS_OF_WEEK * 3))); var items = A.ListOf <ItemEntity>(A.Random.Next(100, 200)); var quribleItems = items.AsQueryable().BuildMock(); var modifiedItemsCount = items.Count(i => i.ParentId == null && (startDate == null || i.ModifiedDate >= startDate) && (endDate == null || i.ModifiedDate <= endDate)); A.Reset(); A.Configure <OperationLog>() .Fill(x => x.OperationType).WithRandom(new EntryState[] { EntryState.Added, EntryState.Modified, EntryState.Deleted }); var operatoins = A.ListOf <OperationLog>(A.Random.Next(100, 200)); var deleteOperations = operatoins.Where(x => x.OperationType == EntryState.Deleted).ToList(); var deleteOperationsCount = deleteOperations.Count; var catalogRepositoryMock = new Mock <ICatalogRepository>(); var changeLogSearchServiceMock = new Mock <IChangeLogSearchService>(); catalogRepositoryMock.Setup(x => x.Items).Returns(quribleItems.Object); changeLogSearchServiceMock.Setup(x => x.SearchAsync(new ChangeLogSearchCriteria() { ObjectType = ProductDocumentChangesProvider.ChangeLogObjectType, OperationTypes = new[] { EntryState.Deleted }, StartDate = startDate, EndDate = endDate, Take = 0 })).ReturnsAsync(new ChangeLogSearchResult() { Results = deleteOperations, TotalCount = deleteOperationsCount }); var productDocumentChangesProvider = new ProductDocumentChangesProvider(() => catalogRepositoryMock.Object, changeLogSearchServiceMock.Object); // Act var totalCountOfchanges = await productDocumentChangesProvider.GetTotalChangesCountAsync(startDate, endDate); // Assert var expectedCount = modifiedItemsCount + deleteOperationsCount; catalogRepositoryMock.VerifyAll(); changeLogSearchServiceMock.VerifyAll(); Assert.Equal(expectedCount, totalCountOfchanges); }