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 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); }
internal static void Accept(ISelectable selectable, StylesheetStatement statement) { if (selectable == null) { return; } switch (statement) { case AssignmentStatement assignment: if (selectable is IStyleable styleable) { styleable.Set(assignment.Key, assignment.Value); } break; case StyleDeclaration style: SelectorHelper.Visit(selectable, style.Selector, (current, discard1, discard2) => { foreach (var localStatement in style.Statements) { Accept(current, localStatement); } }); break; default: throw new NotSupportedException(); } }
public async void OnPost_ValidInputsWithTitleAndBody_ExpectSaveToRepositories() { //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.NewPoemPageSelectors); //Assert var queryPoem = _appFactory.DbContext.GetQueryable <Poem>(); var poemResult = queryPoem.FirstOrDefault(p => p.Name == newPoem.Name); Assert.NotNull(poemResult); Assert.Equal(newPoem.Notes, poemResult.Notes); Assert.Equal(newPoem.ConceivedDateUTC.ToString("yyyy-MM-dd HH:mm"), poemResult.ConceivedDateUTC.ToString("yyyy-MM-dd HH:mm")); var queryRevision = _appFactory.DbContext.GetQueryable <PoemRevision>(); var revisionResult = queryRevision.FirstOrDefault(r => r.Title == inputs["NewRevision.Title"]); Assert.NotNull(revisionResult); Assert.Equal(inputs["NewRevision.Body"], revisionResult.Body); }
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); } }
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)); }
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)); }
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); }
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); }
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); }
public void VisitScript(object root, string selector, object callback, params object[] predicates) { if (predicates == null) { predicates = Empty; } var selectable = asSelectable(root); if (selectable != null) { SelectorHelper.Visit( selectable, selector, (current, parent, root1) => dynamicInvoker.Invoke(callback, current), (i, s) => i >= 0 && i < predicates.Length && dynamicInvoker.Invoke(predicates[i], s) is true); } }
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); } }
/// <summary> /// 获取所有的机组信息列表【目录】 /// </summary> /// <returns></returns> public string GetAllJZId() { SelectorHelper shelper = new SelectorHelper(); string sql = "SELECT * FROM `web`.`机组表`"; DataTable dTable = data.GetTable(sql); for (int i = 0; i < dTable.Rows.Count; i++) { string name = dTable.Rows[i]["机组编号"].ToString(); if (i == 0) { shelper.AddItem(name, name, true); } else { shelper.AddItem(name, name, false); } } return(shelper.ToString()); }
/// <summary> /// 获取部分机组信息列表【目录】 /// </summary> /// <returns></returns> public string GetJZ(string jt, string gc) { SelectorHelper shelper = new SelectorHelper(); string sql = "SELECT * FROM `web`.`机组表` where 集团名称='" + jt + "' and 工厂名称='" + gc + "'"; DataTable dTable = data.GetTable(sql); for (int i = 0; i < dTable.Rows.Count; i++) { string name = dTable.Rows[i]["工厂名称"].ToString(); if (i == 0) { shelper.AddItem(name, name, true); } else { shelper.AddItem(name, name, false); } } return(shelper.ToString()); }
/// <summary> /// 获取某个集团所有的工厂信息列表【目录】 /// </summary> /// <param name="name">集团名称</param> /// <returns></returns> public string GetGC(string name) { SelectorHelper shelper = new SelectorHelper(); string sql = "SELECT * FROM `web`.`工厂表` where 集团名称='" + name + "'"; DataTable dTable = data.GetTable(sql); for (int i = 0; i < dTable.Rows.Count; i++) { string n = dTable.Rows[i]["工厂名称"].ToString(); if (i == 0) { shelper.AddItem(n, n, true); } else { shelper.AddItem(n, n, false); } } return(shelper.ToString()); }
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); }
/// <summary> /// 获取所有专家名【目录】 /// </summary> /// <returns>用户信息列表的json字符串形式</returns> public string GetAllZJUName() { SelectorHelper shelper = new SelectorHelper(); string sql = "SELECT * FROM `web`.`用户表` where 角色名称='专家'"; DataTable dTable = data.GetTable(sql); for (int i = 0; i < dTable.Rows.Count; i++) { string name = dTable.Rows[i]["用户名"].ToString(); if (i == 0) { shelper.AddItem(name, name, true); } else { shelper.AddItem(name, name, false); } } return(shelper.ToString()); }
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); }
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); }
void QueryBudgetAccount_FBBasePageLoaded(object sender, EventArgs e) { SelectorHelper.InitSelectorInfoCompleted += new EventHandler(SelectorHelper_InitSelectorInfoCompleted); SelectorHelper.InitSelectorInfo(); }