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 NoMatchingPublishedPoem_ExpectNullReturned() { //Arrange var poemList = new PoemBuilder().Default().BuildCollection(size: 2); poemList.FirstOrDefault().PublishedRevision = poemList.FirstOrDefault().PoemRevisions.FirstOrDefault(); poemList.Last().PublishedRevision = poemList.Last().PoemRevisions.FirstOrDefault(); //Act var testResult = ApplySpecificationToList(poemList, Guid.Empty); //Assert Assert.Null(testResult); }
public async void OnGet_ExpectPoemDisplayed() { //Arrange var client = _appFactory.CreateClient(); var poems = new PoemBuilder().Default().BuildCollection(size: 2); var poemToGet = poems.Last(); var publishedRevision = poemToGet.PoemRevisions.FirstOrDefault(); poemToGet.PublishedRevision = publishedRevision; _appFactory.DbContext.AddRange(poems); _appFactory.DbContext.SaveChanges(); //Act var response = await client.GetAsync("/Poem?id=" + poemToGet.Id.ToString()); var pageContent = await ResponseHelper.GetDocumentAsync(response); var selectors = new SelectorHelper(pageContent, PageElements.PoemPageSelectors); var title = selectors.Get <IHtmlElement>((int)PageElements.PoemPageElementEnum.PoemTitle); var body = selectors.Get <IHtmlElement>((int)PageElements.PoemPageElementEnum.PoemBody); //Assert Assert.NotNull(title); Assert.NotNull(body); Assert.Equal(publishedRevision.Title, title.TextContent); Assert.Equal(publishedRevision.Body, body.TextContent); }
public async void OnGet_DefaultPage_ReturnsPublishedPoemFromRepository() { //Arrange var client = _appFactory.CreateClient(); var poems = new PoemBuilder().Default().BuildCollection(size: 2); var publishedPoem = poems.Last(); var publishedRevision = publishedPoem.PoemRevisions.FirstOrDefault(); publishedPoem.PublishedRevision = publishedRevision; var nonPublishedPoem = poems.FirstOrDefault(); nonPublishedPoem.PublishedRevision = null; _appFactory.DbContext.AddRange(poems); _appFactory.DbContext.SaveChanges(); //Act var response = await client.GetAsync("/"); var pageContent = await ResponseHelper.GetDocumentAsync(response); var selectors = new SelectorHelper(pageContent, PageElements.IndexPageSelectors); var title = selectors.Get <IHtmlElement>((int)PageElements.IndexPageElementEnum.PoemTitle); var body = selectors.Get <IHtmlElement>((int)PageElements.IndexPageElementEnum.PoemBody); //Assert Assert.NotNull(title); Assert.NotNull(body); Assert.Equal(publishedRevision.Title, title.TextContent); Assert.Equal(publishedRevision.Body, body.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 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 NoPublishedPoem_ExpectEmptyListReturned() { //Arrange var poemList = new PoemBuilder().Default().BuildCollection(size: 2); poemList.FirstOrDefault().PublishedRevision = null; poemList.Last().PublishedRevision = null; //Act var testResult = ApplySpecificationToList(poemList); //Assert Assert.Empty(testResult); }
public void MatchingPoemIsNotPublished_ExpectNullReturned() { //Arrange var poemList = new PoemBuilder().Default().BuildCollection(size: 2); poemList.FirstOrDefault().PublishedRevision = poemList.FirstOrDefault().PoemRevisions.FirstOrDefault(); var poemToGet = poemList.Last(); poemToGet.PublishedRevision = null; //Act var testResult = ApplySpecificationToList(poemList, poemToGet.Id); //Assert Assert.Null(testResult); }
public void HasPublishedPoem_ExpectPoemReturned() { //Arrange var poemList = new PoemBuilder().Default().BuildCollection(size: 2); poemList.FirstOrDefault().PublishedRevision = null; var publishedPoem = poemList.Last(); publishedPoem.PublishedRevision = publishedPoem.PoemRevisions.FirstOrDefault(); //Act var testResult = ApplySpecificationToList(poemList); var returnedPoem = testResult.Single(); //Assert Assert.Equal(publishedPoem.Id, returnedPoem.Id); Assert.Equal(publishedPoem.PublishedRevision.Title, returnedPoem.PublishedRevision.Title); }
public void HasPublishedPoem_ExpectPoemReturned() { //Arrange var poemList = new PoemBuilder().Default().BuildCollection(size: 2); poemList.FirstOrDefault().PublishedRevision = null; var matchingPoem = poemList.Last(); matchingPoem.PublishedRevision = matchingPoem.PoemRevisions.FirstOrDefault(); //Act var testResult = ApplySpecificationToList(poemList); //Assert Assert.NotNull(testResult); Assert.Equal(matchingPoem.Id, testResult.Id); Assert.Equal(matchingPoem.PublishedRevision.Id, testResult.PublishedRevision.Id); Assert.Equal(matchingPoem.PublishedRevision.Title, testResult.PublishedRevision.Title); Assert.Equal(matchingPoem.PublishedRevision.Body, testResult.PublishedRevision.Body); }
public void HasMultiplePoems_ExpectOnlyTheLatestPublishedPoemReturned() { //Arrange var poemList = new PoemBuilder().Default().BuildCollection(size: 2); var olderPoem = poemList.FirstOrDefault(); olderPoem.PublishedRevision = olderPoem.PoemRevisions.FirstOrDefault(); olderPoem.LastModifiedDateUTC = DateTime.UtcNow.AddDays(-2); var matchingPoem = poemList.Last(); matchingPoem.PublishedRevision = matchingPoem.PoemRevisions.FirstOrDefault(); matchingPoem.LastModifiedDateUTC = olderPoem.LastModifiedDateUTC.AddDays(1); //Act var testResult = ApplySpecificationToList(poemList); //Assert Assert.NotNull(testResult); Assert.Equal(matchingPoem.Id, testResult.Id); Assert.Equal(matchingPoem.PublishedRevision.Id, testResult.PublishedRevision.Id); Assert.Equal(matchingPoem.PublishedRevision.Title, testResult.PublishedRevision.Title); Assert.Equal(matchingPoem.PublishedRevision.Body, testResult.PublishedRevision.Body); }