public async void OnGet_ReturnsAllPublishedPoemTitleInAscOrder() { //Arrange var client = _appFactory.CreateClient(); var poems = new PoemBuilder().Random().BuildCollection(size: 2); poems.First().PublishedRevision = poems.First().PoemRevisions.FirstOrDefault(); poems.Last().PublishedRevision = poems.Last().PoemRevisions.FirstOrDefault(); _appFactory.DbContext.AddRange(poems); _appFactory.DbContext.SaveChanges(); //Act var response = await client.GetAsync("/ListPoemsByTitle"); 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.OrderBy(p => p.PublishedRevision.Title); Assert.Equal(expectResults.Count(), titles.Count()); Assert.Equal(expectResults.Count(), links.Count()); for (int n = 0; n < expectResults.Count(); n++) { Assert.Contains(expectResults.ElementAt(n).Id.ToString(), links.ElementAt(n).Href); Assert.Equal(expectResults.ElementAt(n).PublishedRevision.Title, titles.ElementAt(n).TextContent); } }
public void HasMultiplePublishedPoems_ExpectAllReturnedAndTitleInAscOrder() { //Arrange var poemList = new PoemBuilder().Random().BuildCollection(size: 2); poemList.First().PublishedRevision = poemList.First().PoemRevisions.FirstOrDefault(); poemList.Last().PublishedRevision = poemList.Last().PoemRevisions.FirstOrDefault(); //Act var testResult = ApplySpecificationToList(poemList); //Assert var expectResult = poemList.OrderBy(p => p.PublishedRevision.Title); Assert.Equal(expectResult, testResult); }
public void ListWithNameInDescOrder_ExpectReturnedListInAscOrder() { //Arrange var poems = new PoemBuilder().Default().BuildCollection(size: 3).ToList(); poems[0].Name = "C " + poems[0].Name; poems[1].Name = "B " + poems[1].Name;; poems[2].Name = "A " + poems[2].Name;; var queryable = poems.AsQueryable(); var expectResult = poems.OrderBy(p => p.Name); //Act var spec = new ListPoemsByNameSpec(); var testResult = queryable.OrderBy(spec.OrderBy); //Assert Assert.Equal(expectResult, testResult); }