Exemple #1
0
        public async void OnGet_WithPublishedRevision_VerifyHtmlElements()
        {
            //Arrange
            var poem = new PoemBuilder().Default().Build();

            poem.PoemRevisions     = new RevisionBuilder(poem).Random().BuildCollection(size: 3);
            poem.PublishedRevision = poem.PoemRevisions.FirstOrDefault();
            var client = CreateClientAndTestData(poem);

            //Act
            var response = await client.GetAsync("/EditPoem?Id=" + poem.Id.ToString());

            var pageContent = await ResponseHelper.GetDocumentAsync(response);

            var selectors = new SelectorHelper(pageContent, PageElements.EditPoemPageSelectors);

            //Assert
            var publishRevisionSelectList = selectors.Get <IHtmlSelectElement>
                                                ((int)PageElements.EditPoemElementEnum.PublishRevisionSelectList);
            var publishRevisionValidationMsg = selectors.Get <IHtmlElement>
                                                   ((int)PageElements.EditPoemElementEnum.PublishRevisionValidationMsg);
            var titleInput = selectors.Get <IHtmlInputElement>
                                 ((int)PageElements.EditPoemElementEnum.TitleInputField);
            var bodyInput = selectors.Get <IHtmlTextAreaElement>
                                ((int)PageElements.EditPoemElementEnum.BodyInputField);
            var pastRevisionSelectList = selectors.Get <IHtmlSelectElement>
                                             ((int)PageElements.EditPoemElementEnum.PastRevisionSelectList);

            Assert.NotNull(publishRevisionSelectList);
            Assert.NotNull(publishRevisionValidationMsg);
            Assert.NotNull(titleInput);
            Assert.NotNull(bodyInput);
            Assert.NotNull(pastRevisionSelectList);

            Assert.NotEmpty(publishRevisionSelectList.SelectedOptions);
            var selectedOption = publishRevisionSelectList.SelectedOptions.FirstOrDefault();

            Assert.Equal(poem.PublishedRevision.Id.ToString(), selectedOption.Value);

            var revisionList      = new RevisionList(poem.PoemRevisions);
            var publishedRevision = revisionList.Where(r => r.Id == poem.PublishedRevision.Id).FirstOrDefault();

            Assert.Equal(publishedRevision.DisplayName, selectedOption.Text);

            Assert.Equal(revisionList.Count + 2, publishRevisionSelectList.Length);
            Assert.Equal(revisionList.Count, pastRevisionSelectList.Length);
        }
Exemple #2
0
        private void AssertEditPoemPage(IHtmlDocument pageContent, PoemDTO poem, RevisionList revisions = null)
        {
            var selectors = new SelectorHelper(pageContent, PageElements.EditPoemPageSelectors);

            var idInput = selectors.Get <IHtmlInputElement>
                              ((int)PageElements.EditPoemElementEnum.IdHiddenField);
            var nameInput = selectors.Get <IHtmlInputElement>
                                ((int)PageElements.EditPoemElementEnum.NameInputField);
            var notesInput = selectors.Get <IHtmlTextAreaElement>
                                 ((int)PageElements.EditPoemElementEnum.NotesInputField);
            var conceivedDateInput = selectors.Get <IHtmlInputElement>
                                         ((int)PageElements.EditPoemElementEnum.ConceivedDateInputField);
            var publishRevisionSelectList = selectors.Get <IHtmlSelectElement>
                                                ((int)PageElements.EditPoemElementEnum.PublishRevisionSelectList);
            var pastRevisionSelectList = selectors.Get <IHtmlSelectElement>
                                             ((int)PageElements.EditPoemElementEnum.PastRevisionSelectList);

            Assert.Equal(poem.Id.ToString(), idInput.Value);
            Assert.Equal(poem.Name, nameInput.Value);
            Assert.Equal(poem.Notes, notesInput.Value);
            Assert.Equal(poem.ConceivedDateLocal.ToString("yyyy-MM-dd"),
                         conceivedDateInput.Value);
            if (poem.PublishedRevisionId == null || poem.PublishedRevisionId == Guid.Empty)
            {
                Assert.Empty(publishRevisionSelectList.SelectedOptions);
            }
            else
            {
                Assert.NotEmpty(publishRevisionSelectList.SelectedOptions);
                var selectedOption = publishRevisionSelectList.SelectedOptions.FirstOrDefault();
                Assert.Equal(poem.PublishedRevisionId.ToString(),
                             selectedOption.Value);
                var publishedRevision = revisions.Where(r => r.Id == poem.PublishedRevisionId).FirstOrDefault();
                Assert.Equal(publishedRevision.DisplayName, selectedOption.Text);
            }

            if (revisions != null && revisions.Any())
            {
                Assert.Equal(revisions.Count + 2, publishRevisionSelectList.Length);
                Assert.NotNull(pastRevisionSelectList);
                Assert.Equal(revisions.Count, pastRevisionSelectList.Length);
            }
        }