Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        public async void OnPost_ValidInputs_ExpectRedirectToListPoemsPage()
        {
            //Arrange
            var client = _appFactory.CreateAuthorizedClient();

            var form = await GetNewPoemForm(client);

            var newPoem = new PoemBuilder().Random().Build();

            var inputs = CreateFormInputs(newPoem);

            //Act
            var response = await PostRequestHelper.PostWithUpdateInputsAsync(client, form, inputs);

            var selectors = new SelectorHelper(response, PageElements.ListPoemsPageSelectors);
            var poemNames = selectors.GetAll <IHtmlElement>((int)PageElements.ListPoemsPageElementEnum.PoemName);

            //Assert
            var name = poemNames.FirstOrDefault(p => p.TextContent == newPoem.Name);

            Assert.NotNull(name);
        }