public void SetUp() { // Setup the repository Repository = GetRepository(); Clearup(); // Create 5 Pages with 2 versions of content each _createdDate = DateTime.Today.ToUniversalTime().AddDays(-1); _editedDate = _createdDate.AddHours(1); _page1 = NewPage("admin", "homepage, newpage"); _pageContent1 = Repository.AddNewPage(_page1, "text", "admin", _createdDate); _page1 = _pageContent1.Page; _pageContent2 = Repository.AddNewPageContentVersion(_page1, "v2", "admin", _editedDate, 2); _page1 = _pageContent2.Page; // update the modified date Page page2 = NewPage("editor1"); PageContent pageContent2 = Repository.AddNewPage(page2, "text", "editor1", _createdDate); Repository.AddNewPageContentVersion(pageContent2.Page, "v2", "editor1", _editedDate, 1); Page page3 = NewPage("editor2"); PageContent pageContent3 = Repository.AddNewPage(page3, "text", "editor2", _createdDate); Repository.AddNewPageContentVersion(pageContent3.Page, "v2", "editor2", _editedDate, 1); Page page4 = NewPage("editor3"); PageContent pageContent4 = Repository.AddNewPage(page4, "text", "editor3", _createdDate); Repository.AddNewPageContentVersion(pageContent4.Page, "v2", "editor3", _editedDate, 1); Page page5 = NewPage("editor4"); PageContent pageContent5 = Repository.AddNewPage(page5, "text", "editor4", _createdDate); Repository.AddNewPageContentVersion(pageContent5.Page, "v2", "editor4", _editedDate, 1); }
public void getpagebytitle() { // Arrange string title = "page title"; Page expectedPage = NewPage("admin", "tag1", title); PageContent newContent = Repository.AddNewPage(expectedPage, "sometext", "admin", _createdDate); expectedPage.Id = newContent.Page.Id; // get the new identity // Act Page actualPage = Repository.GetPageByTitle(title); // Assert Assert.That(actualPage.Id, Is.EqualTo(expectedPage.Id)); Assert.That(actualPage.CreatedBy, Is.EqualTo(expectedPage.CreatedBy)); Assert.That(actualPage.CreatedOn, Is.EqualTo(expectedPage.CreatedOn)); Assert.That(actualPage.IsLocked, Is.EqualTo(expectedPage.IsLocked)); Assert.That(actualPage.ModifiedBy, Is.EqualTo(expectedPage.ModifiedBy)); Assert.That(actualPage.ModifiedOn, Is.EqualTo(expectedPage.ModifiedOn)); Assert.That(actualPage.Tags, Is.EqualTo(expectedPage.Tags)); Assert.That(actualPage.Title, Is.EqualTo(expectedPage.Title)); }
public void SetUp() { // Setup the repository CheckDatabaseProcessIsRunning(); Repository = GetRepository(); Clearup(); // Create 5 Pages with 2 versions of content each var todayUtc = DateTime.Today.ToUniversalTime(); // that's 11pm the previous day _createdDate = todayUtc.AddDays(-1); // that's 11pm, two days ago _editedDate = _createdDate.AddHours(1); // that's 12pm, two days ago _page1 = NewPage("admin", "homepage, newpage"); _pageContent1 = Repository.AddNewPage(_page1, "text", "admin", _createdDate); _page1 = _pageContent1.Page; _pageContent2 = Repository.AddNewPageContentVersion(_page1, "v2", "admin", _editedDate, 2); _page1 = _pageContent2.Page; // update the modified date Page page2 = NewPage("editor1"); PageContent pageContent2 = Repository.AddNewPage(page2, "text", "editor1", _createdDate); Repository.AddNewPageContentVersion(pageContent2.Page, "v2", "editor1", _editedDate, 1); Page page3 = NewPage("editor2"); PageContent pageContent3 = Repository.AddNewPage(page3, "text", "editor2", _createdDate); Repository.AddNewPageContentVersion(pageContent3.Page, "v2", "editor2", _editedDate, 1); Page page4 = NewPage("editor3"); PageContent pageContent4 = Repository.AddNewPage(page4, "text", "editor3", _createdDate); Repository.AddNewPageContentVersion(pageContent4.Page, "v2", "editor3", _editedDate, 1); Page page5 = NewPage("editor4"); PageContent pageContent5 = Repository.AddNewPage(page5, "text", "editor4", _createdDate); Repository.AddNewPageContentVersion(pageContent5.Page, "v2", "editor4", _editedDate, 1); }
protected PageContent AddPage(string title, string content) { using (IPageRepository repository = GetRepository()) { Page page = new Page(); page.Title = title; page.Tags = "tag1, tag2"; page.CreatedBy = "admin"; page.CreatedOn = DateTime.UtcNow; page.ModifiedOn = DateTime.UtcNow; page.ModifiedBy = "admin"; return(repository.AddNewPage(page, content, "admin", DateTime.UtcNow)); } }
/// <summary> /// Extracts and saves all textual content for a page. /// </summary> /// <param name="pageName"></param> /// <param name="page">The page the content belongs to.</param> /// <param name="nameTitleMapping">Mapping between name and title</param> private void AddContent(string pageName, Page page, Dictionary <string, string> nameTitleMapping) { using (SqlConnection connection = new SqlConnection(_connectionString)) { using (SqlCommand command = connection.CreateCommand()) { connection.Open(); command.CommandText = @"SELECT *, (SELECT MAX(Revision) FROM PageContent PC WHERE PC.Page = PageContent.Page) AS MaxRevision FROM PageContent WHERE [Page]=@Page ORDER BY LastModified" ; SqlParameter parameter = new SqlParameter(); parameter.ParameterName = "@Page"; parameter.SqlDbType = System.Data.SqlDbType.VarChar; parameter.Value = pageName; command.Parameters.Add(parameter); bool hasContent = false; using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { PageContent content = new PageContent(); string editedBy = reader["User"].ToString(); DateTime editedOn = ConvertToUtcDateTime(reader["LastModified"]); string text = reader["Content"].ToString(); text = CleanContent(text, nameTitleMapping); int versionNumber = (int.Parse(reader["Revision"].ToString())) + 1; if (versionNumber == 0) { versionNumber = (int.Parse(reader["MaxRevision"].ToString())) + 2; } PageRepository.AddNewPageContentVersion(page, text, editedBy, editedOn, versionNumber); hasContent = true; } } // For broken content, make sure the page has something if (!hasContent) { PageRepository.AddNewPage(page, "", "unknown", DateTime.UtcNow); } } } }