예제 #1
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);
            }
        }