public void HasMultiplePublishedPoems_ExpectAllReturnedAndModifiedDateInDescOrder() { //Arrange var poemList = new PoemBuilder().Random().BuildCollection(size: 2); poemList.First().PublishedRevision = poemList.First().PoemRevisions.FirstOrDefault(); poemList.First().LastModifiedDateUTC = DateTime.UtcNow.AddDays(-2); poemList.Last().PublishedRevision = poemList.Last().PoemRevisions.FirstOrDefault(); poemList.Last().LastModifiedDateUTC = DateTime.UtcNow.AddDays(-1); //Act var testResult = ApplySpecificationToList(poemList); //Assert var expectResult = poemList.OrderByDescending(p => p.LastModifiedDateUTC); Assert.Equal(expectResult, testResult); }
public void PoemsWithAscModifiedDate_ExpectListOrderedDesc() { //Arrange var poems = new PoemBuilder().Default().BuildCollection(size: 3).ToList(); poems[0].LastModifiedDateUTC = DateTime.UtcNow.AddDays(-3); poems[1].LastModifiedDateUTC = DateTime.UtcNow.AddDays(-2); poems[2].LastModifiedDateUTC = DateTime.UtcNow.AddDays(-1); var queryable = poems.AsQueryable(); var expectResult = poems.OrderByDescending(p => p.LastModifiedDateUTC); //Act var spec = ListPoemsByLastModifiedDateSpec.CreateSpecification(); var testResult = queryable.OrderByDescending(spec.OrderByDesc); //Assert Assert.Equal(expectResult, testResult); }
public void ListWithConceivedDateInAscOrder_ExpectReturnedListInDescOrder() { //Arrange var poems = new PoemBuilder().Default().BuildCollection(size: 3).ToList(); poems[0].ConceivedDateUTC = DateTime.UtcNow.AddDays(-3); poems[1].ConceivedDateUTC = DateTime.UtcNow.AddDays(-2); poems[2].ConceivedDateUTC = DateTime.UtcNow.AddDays(-1); var queryable = poems.AsQueryable(); var expectResult = poems.OrderByDescending(p => p.ConceivedDateUTC); //Act var spec = new ListPoemsByConceivedDateSpec(); var testResult = queryable.OrderByDescending(spec.OrderByDesc); //Assert Assert.Equal(expectResult, testResult); }
public async void OnGet_ReturnsAllPublishedPoemModifiedDateInDescOrder() { //Arrange var client = _appFactory.CreateClient(); var poems = new PoemBuilder().Random().BuildCollection(size: 2); poems.First().PublishedRevision = poems.First().PoemRevisions.FirstOrDefault(); poems.First().LastModifiedDateUTC = DateTime.UtcNow.AddDays(-2); poems.Last().PublishedRevision = poems.Last().PoemRevisions.FirstOrDefault(); poems.Last().LastModifiedDateUTC = DateTime.UtcNow.AddDays(-1); _appFactory.DbContext.AddRange(poems); _appFactory.DbContext.SaveChanges(); //Act var response = await client.GetAsync("/ListPoemsByDate"); var pageContent = await ResponseHelper.GetDocumentAsync(response); var selectors = new SelectorHelper(pageContent, PageElements.ListPageSelectors); var links = selectors.GetAll <IHtmlAnchorElement>((int)PageElements.ListPageElementEnum.PoemLink); var titles = selectors.GetAll <IHtmlElement>((int)PageElements.ListPageElementEnum.PoemTitle); //Assert var expectResults = poems.OrderByDescending(p => p.LastModifiedDateUTC); Assert.Equal(expectResults.Count(), titles.Count()); Assert.Equal(expectResults.Count(), links.Count()); for (int n = 0; n < expectResults.Count(); n++) { Assert.Equal(expectResults.ElementAt(n).PublishedRevision.Title, titles.ElementAt(n).TextContent); Assert.Contains(expectResults.ElementAt(n).Id.ToString(), links.ElementAt(n).Href); } }