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 OnPost_AllFieldsModified_ExpectChangesSavedToRepository() { //Arrange var poem = new PoemBuilder().Default().Build(); poem.PublishedRevision = null; var client = CreateClientAndTestData(poem); var form = await GetInputFormAsync(client, poem.Id); var modifiedPoemDTO = PoemDTO.CreateDTOFromEntity(poem); modifiedPoemDTO.Name = "Updated " + poem.Name; modifiedPoemDTO.Notes = poem.Notes + " and more notes"; modifiedPoemDTO.ConceivedDateLocal = poem.ConceivedDateUTC.ToLocalTime().AddDays(-1); modifiedPoemDTO.PublishedRevisionId = poem.PoemRevisions.FirstOrDefault().Id; var newRevision = new RevisionBuilder(poem).Random().Build(); var newRevisionDTO = RevisionDTO.CreateDTOFromEntity(newRevision); var inputs = CreateFormInputs(modifiedPoemDTO, newRevisionDTO); //Act var response = await PostRequestHelper.PostWithUpdateInputsAsync(client, form, inputs); //Assert var revisionList = new RevisionList(poem.PoemRevisions.Append(newRevision)); AssertEditPoemPage(response, modifiedPoemDTO, revisionList); }
public void Check() { // Prepare request p = new PostRequestHelper("http://todomoo.sourceforge.net/updatescheck.php", 30000); Version v = new Version(Application.ProductVersion); p.UserAgent = "Todomoo " + v.Major + "." + v.Minor; p.Accept = "text/plain,text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; // Add POST data (current version, user date and time, machine hashed ID) // NB: Machine ID is hashed due to privacy guarantee, needed only for updates statistics // NB: Local language is for statistics about localizations and translations p.AddPostData("current", v.Major + "." + v.Minor + "." + v.Build + "." + v.Revision); p.AddPostData("user_time", DateTime.Now.ToString("R")); p.AddPostData("machine_id", MD5.Compute(UniqueMachineID.Get())); p.AddPostData("local_lang", System.Globalization.CultureInfo.CurrentUICulture.ToString()); //p.AddPostData("force_new_version", "1"); // DEBUG // Get response try { p.BeginGetResponse(); // Process response when it's ready p.ResponseReady += delegate(System.Net.PostRequestHelper s, string response) { ProcessResponse(response); }; // Error in HTTP response p.Error += delegate(System.Net.PostRequestHelper s, Exception exception) { if (Error != null) { Error(exception.Message); } }; // Error on HTTP request initialization } catch (Exception ex) { if (Error != null) { Error(ex.Message); } } }
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 void OnPost_HasPublishedRevision_ChangeToNotPublish_ExpectChangesSavedToRepository() { //Arrange var poem = new PoemBuilder().Random().Build(); poem.PoemRevisions = new RevisionBuilder(poem).Default().BuildCollection(size: 2); poem.PublishedRevision = poem.PoemRevisions.FirstOrDefault(); var client = CreateClientAndTestData(poem); var form = await GetInputFormAsync(client, poem.Id); var modifiedPoemDTO = PoemDTO.CreateDTOFromEntity(poem); modifiedPoemDTO.PublishedRevisionId = null; var inputs = CreateFormInputs(modifiedPoemDTO); //Act var response = await PostRequestHelper.PostWithUpdateInputsAsync(client, form, inputs); //Assert var revisionList = new RevisionList(poem.PoemRevisions); AssertEditPoemPage(response, modifiedPoemDTO, revisionList); }