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

            var response = await client.GetAsync("/NewPoem");

            var pageContent = await ResponseHelper.GetDocumentAsync(response);

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

            //Act
            var confirmationMessage        = selectors.Get <IHtmlElement>((int)PageElements.NewPoemElementEnum.ConfirmationMessage);
            var nameInput                  = selectors.Get <IHtmlElement>((int)PageElements.NewPoemElementEnum.NameInputField);
            var nameValidationMsg          = selectors.Get <IHtmlElement>((int)PageElements.NewPoemElementEnum.NameValidationMsg);
            var noteInput                  = selectors.Get <IHtmlElement>((int)PageElements.NewPoemElementEnum.NotesInputField);
            var conceivedDateInput         = selectors.Get <IHtmlElement>((int)PageElements.NewPoemElementEnum.ConceivedDateInputField);
            var conceivedDateValidationMsg = selectors.Get <IHtmlElement>((int)PageElements.NewPoemElementEnum.ConceivedDateValidationMsg);
            var titleInput                 = selectors.Get <IHtmlElement>((int)PageElements.NewPoemElementEnum.TitleInputField);
            var bodyInput                  = selectors.Get <IHtmlElement>((int)PageElements.NewPoemElementEnum.BodyInputField);

            //Assert
            Assert.NotNull(confirmationMessage);
            Assert.NotNull(nameInput);
            Assert.NotNull(nameValidationMsg);
            Assert.NotNull(noteInput);
            Assert.NotNull(conceivedDateInput);
            Assert.NotNull(conceivedDateValidationMsg);
            Assert.NotNull(titleInput);
            Assert.NotNull(bodyInput);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        private async Task <IHtmlFormElement> GetNewPoemForm(HttpClient client)
        {
            var response = await client.GetAsync("/NewPoem");

            var content = await ResponseHelper.GetDocumentAsync(response);

            var selector = new SelectorHelper(content, PageElements.NewPoemPageSelectors);

            return(selector.Get <IHtmlFormElement>((int)PageElements.NewPoemElementEnum.NewPoemForm));
        }
Ejemplo n.º 6
0
        private async Task <IHtmlFormElement> GetInputFormAsync(HttpClient client, Guid poemId)
        {
            var response = await client.GetAsync("/EditPoem?Id=" + poemId.ToString());

            var pageContent = await ResponseHelper.GetDocumentAsync(response);

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

            return(formFields.Get <IHtmlFormElement>((int)PageElements.EditPoemElementEnum.EditPoemForm));
        }
Ejemplo n.º 7
0
        public async Task OnGet_SinglePoem_ExpectEditPoemLinks()
        {
            //Arrange
            var client = _appFactory.CreateAuthorizedClient();

            var testPoem = new PoemBuilder().Default().Build();

            _appFactory.DbContext.Add(testPoem);
            _appFactory.DbContext.SaveChanges();

            var response = await client.GetAsync("/ListPoemsByLastModifiedDate");

            var pageContent = await ResponseHelper.GetDocumentAsync(response);

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

            //Action
            var link = selectors.Get <IHtmlAnchorElement>(
                (int)PageElements.ListPoemsPageElementEnum.EditLink,
                testPoem.Id.ToString());
            var name = selectors.Get <IHtmlElement>((int)PageElements.ListPoemsPageElementEnum.PoemName);

            //Assert
            Assert.NotNull(name);
            Assert.Equal(testPoem.Name, name.TextContent);

            Assert.NotNull(link);
            //Make sure link actually works
            response = await client.GetAsync(link.Href);

            pageContent = await ResponseHelper.GetDocumentAsync(response);

            var pageSelector = new SelectorHelper(pageContent, PageElements.EditPoemPageSelectors);
            var form         = pageSelector.Get <IHtmlFormElement>((int)PageElements.EditPoemElementEnum.EditPoemForm);

            Assert.NotNull(form);
        }
Ejemplo n.º 8
0
        public async void OnGet_WithMockAuth_ExpectSignoutWidget()
        {
            //Arrange
            var client = _appFactory.CreateAuthorizedClient();

            //Act
            var response = await client.GetAsync("/");

            var pageContent = await ResponseHelper.GetDocumentAsync(response);

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

            //Assert
            var signoutWidget = selectors.Get <IHtmlAnchorElement>((int)PageElements.LoginPartialElementEnum.SignOutWidget);

            Assert.NotNull(signoutWidget);
        }
Ejemplo n.º 9
0
        public async void OnGet_WithoutRevision_VerifyHtmlElements()
        {
            //Arrange
            var poem = new PoemBuilder().Default().Build();

            poem.PublishedRevision = null;
            poem.PoemRevisions     = null;
            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 idInput = selectors.Get <IHtmlInputElement>
                              ((int)PageElements.EditPoemElementEnum.IdHiddenField);
            var nameInput = selectors.Get <IHtmlInputElement>
                                ((int)PageElements.EditPoemElementEnum.NameInputField);
            var nameValidationMsg = selectors.Get <IHtmlElement>
                                        ((int)PageElements.EditPoemElementEnum.NameValidationMsg);
            var notesInput = selectors.Get <IHtmlTextAreaElement>
                                 ((int)PageElements.EditPoemElementEnum.NotesInputField);
            var conceivedDateInput = selectors.Get <IHtmlInputElement>
                                         ((int)PageElements.EditPoemElementEnum.ConceivedDateInputField);
            var conceivedDateValidationMsg = selectors.Get <IHtmlElement>
                                                 ((int)PageElements.EditPoemElementEnum.ConceivedDateValidationMsg);
            var publishRevisionSelectList = selectors.Get <IHtmlSelectElement>
                                                ((int)PageElements.EditPoemElementEnum.PublishRevisionSelectList);

            Assert.NotNull(idInput);
            Assert.NotNull(nameInput);
            Assert.NotNull(nameValidationMsg);
            Assert.NotNull(notesInput);
            Assert.NotNull(conceivedDateInput);
            Assert.NotNull(nameValidationMsg);
            Assert.NotNull(publishRevisionSelectList);

            Assert.Equal(poem.Id.ToString(), idInput.Value);
            Assert.Equal(poem.Name, nameInput.Value);
            Assert.Equal(poem.Notes, notesInput.Value);
            Assert.Equal(poem.ConceivedDateUTC.ToLocalTime().ToString("yyyy-MM-dd"),
                         conceivedDateInput.Value);
            Assert.Empty(publishRevisionSelectList.SelectedOptions);
        }
Ejemplo n.º 10
0
        public async void OnGet_ExpectReturnCurrentVersionNumber()
        {
            //Arrange
            var client          = _appFactory.CreateAuthorizedClient();
            var assembly        = Assembly.Load("Workshop.Web");
            var expectedVersion = assembly.GetName().Version.ToString();

            //Action
            var response = await client.GetAsync("/GetVersion");

            var pageContent = await ResponseHelper.GetDocumentAsync(response);

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

            var versionReturned = selectors.Get <IHtmlElement>(
                (int)PageElements.GetVersionPageElementEnum.VersionNumber);

            //Assert
            Assert.NotNull(versionReturned);
            Assert.Equal(expectedVersion, versionReturned.TextContent);
        }
Ejemplo n.º 11
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);
            }
        }