public void ClearPages_Should_Set_TempData_Message_And_Clear_Cache_And_Clear_All_Pages() { // Arrange _repository.AddNewPage(new Page() { Id = 1 }, "text", "admin", DateTime.UtcNow); _repository.AddNewPage(new Page() { Id = 2 }, "text", "admin", DateTime.UtcNow); _pageCache.Add(1, new PageViewModel()); _listCache.Add("list.somekey", new List <string>()); _siteCache.AddMenu("should not be cleared"); // Act RedirectToRouteResult result = _toolsController.ClearPages() as RedirectToRouteResult; // Assert Assert.That(result, Is.Not.Null, "RedirectToRouteResult"); Assert.That(result.RouteValues["action"], Is.EqualTo("Index")); Assert.That(_toolsController.TempData["SuccessMessage"], Is.EqualTo(SiteStrings.SiteSettings_Tools_ClearDatabase_Message)); Assert.That(_cache.Count(), Is.EqualTo(1)); Assert.That(_repository.AllPages().Count(), Is.EqualTo(0)); }
public void Code_Blocks_Should_Allow_Quotes() { // Issue #82 // Arrange Page page = new Page() { Id = 1, Title = "My first page" }; RepositoryMock repositoryStub = new RepositoryMock(); repositoryStub.AddNewPage(page, "My first page", "admin", DateTime.UtcNow); ApplicationSettings settings = new ApplicationSettings(); settings.Installed = true; settings.UpgradeRequired = false; MarkupConverter converter = new MarkupConverter(settings, repositoryStub, _pluginFactory); string markdownText = "Here is some `// code with a 'quote' in it and another \"quote\"`\n\n" + " var x = \"some tabbed code\";\n\n"; // 2 line breaks followed by 4 spaces (tab stop) at the start indicates a code block string expectedHtml = "<p>Here is some <code>// code with a 'quote' in it and another \"quote\"</code></p>\n\n" + "<pre><code>var x = \"some tabbed code\";\n" + "</code></pre>\n"; // Act string actualHtml = converter.ToHtml(markdownText); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml)); }
public void Code_Blocks_Should_Allow_Quotes() { // Issue #82 // Arrange Page page = new Page() { Id = 1, Title = "My first page" }; RepositoryMock repositoryStub = new RepositoryMock(); repositoryStub.AddNewPage(page, "My first page", "admin", DateTime.UtcNow); repositoryStub.SiteSettings = new SiteSettings() { MarkupType = "Markdown" }; ApplicationSettings settings = new ApplicationSettings(); settings.Installed = true; settings.UpgradeRequired = false; MarkupConverter converter = new MarkupConverter(settings, repositoryStub, _pluginFactory); string markdownText = "Here is some `// code with a 'quote' in it and another \"quote\"`\n\n" + " var x = \"some tabbed code\";\n\n"; // 2 line breaks followed by 4 spaces (tab stop) at the start indicates a code block string expectedHtml = "<p>Here is some <code>// code with a 'quote' in it and another \"quote\"</code></p>\n\n" + "<pre><code>var x = \"some tabbed code\";\n" + "</code></pre>\n"; // Act string actualHtml = converter.ToHtml(markdownText); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml)); }
public void Images_Should_Support_Dimensions() { // Arrange Page page = new Page() { Id = 1, Title = "My first page" }; RepositoryMock repositoryStub = new RepositoryMock(); repositoryStub.AddNewPage(page, "My first page", "admin", DateTime.UtcNow); repositoryStub.SiteSettings = new SiteSettings() { MarkupType = "Markdown" }; ApplicationSettings settings = new ApplicationSettings(); settings.Installed = true; settings.UpgradeRequired = false; MarkupConverter converter = new MarkupConverter(settings, repositoryStub, _pluginFactory); string markdownText = "Here is an image:![Image](/Image1.png) \n\n" + "And another with equal dimensions ![Square](/Image1.png =250x) \n\n" + "And this one is a rectangle ![Rectangle](/Image1.png =250x350)"; string expectedHtml = "<p>Here is an image:<img src=\"/Attachments/Image1.png\" border=\"0\" alt=\"Image\" width=\"\" height=\"\" /> </p>\n\n" + "<p>And another with equal dimensions <img src=\"/Attachments/Image1.png\" border=\"0\" alt=\"Square\" width=\"250px\" height=\"\" /> </p>\n\n" + "<p>And this one is a rectangle <img src=\"/Attachments/Image1.png\" border=\"0\" alt=\"Rectangle\" width=\"250px\" height=\"350px\" /></p>\n"; // Act string actualHtml = converter.ToHtml(markdownText); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml)); }
public void Internal_Links_Should_Resolve_With_Id() { // Bug #87 // Arrange Page page = new Page() { Id = 1, Title = "My first page"}; RepositoryMock repositoryStub = new RepositoryMock(); repositoryStub.AddNewPage(page, "My first page", "admin", DateTime.UtcNow); repositoryStub.SiteSettings = new SiteSettings() { MarkupType = "Markdown" }; ApplicationSettings settings = new ApplicationSettings(); settings.Installed = true; settings.UpgradeRequired = false; UrlResolverMock resolver = new UrlResolverMock(); resolver.InternalUrl = "blah"; MarkupConverter converter = new MarkupConverter(settings, repositoryStub, _pluginFactory); converter.UrlResolver = resolver; string markdownText = "[Link](My-first-page)"; string invalidMarkdownText = "[Link](My first page)"; // Act string expectedHtml = "<p><a href=\"blah\">Link</a></p>\n"; string expectedInvalidLinkHtml = "<p>[Link](My first page)</p>\n"; string actualHtml = converter.ToHtml(markdownText); string actualHtmlInvalidLink = converter.ToHtml(invalidMarkdownText); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml)); Assert.That(actualHtmlInvalidLink, Is.EqualTo(expectedInvalidLinkHtml)); }
public void Should_Replace_Markdown_With_Internal_Link() { // Arrange string menuMarkup = "* [First link](my-page)\r\n"; string expectedHtml = "<ul><li><a href=\"/wiki/1/my-page\">First link</a></li></ul>"; RepositoryMock repository = new RepositoryMock(); repository.AddNewPage(new Page() { Title = "my page", Id = 1 }, "text", "user", DateTime.Now); repository.SiteSettings = new SiteSettings(); repository.SiteSettings.MarkupType = "Markdown"; repository.SiteSettings.MenuMarkup = menuMarkup; UserContextStub userContext = new UserContextStub(); ApplicationSettings applicationSettings = new ApplicationSettings(); applicationSettings.Installed = true; CacheMock cache = new CacheMock(); SiteCache siteCache = new SiteCache(applicationSettings, cache); MarkupConverter converter = new MarkupConverter(applicationSettings, repository, _pluginFactory); MenuParser parser = new MenuParser(converter, repository, siteCache, userContext); // Act string actualHtml = parser.GetMenu(); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml)); }
/// <summary> /// Adds a page to the mock repository (which is just a list of Page and PageContent objects in memory). /// </summary> public PageViewModel AddToMockedRepository(int id, string createdBy, string title, string tags, DateTime createdOn, string textContent = "") { Page page = new Page(); page.Id = id; page.CreatedBy = createdBy; page.Title = title; page.Tags = tags; page.CreatedOn = createdOn; if (string.IsNullOrEmpty(textContent)) { textContent = title + "'s text"; } PageContent content = _repository.AddNewPage(page, textContent, createdBy, createdOn); PageViewModel model = new PageViewModel() { Id = id, Title = title, Content = textContent, RawTags = tags, CreatedBy = createdBy, CreatedOn = createdOn }; return(model); }
public void External_Links_With_Anchor_Tag_Should_Retain_The_Anchor() { // Issue #172 // Arrange _repository.AddNewPage(new Page() { Id = 1, Title = "foo" }, "foo", "admin", DateTime.Today); _markupConverter = new MarkupConverter(_applicationSettings, _repository, _pluginFactory); string expectedHtml = "<p><a href=\"http://www.google.com/?blah=xyz#myanchor\">Some link text</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[http://www.google.com/?blah=xyz#myanchor|Some link text]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml); }
public void PageToolbar_Should_Return_PartialView() { // Arrange _repository.AddNewPage(new Page() { Title = "Title" }, "text", "admin", DateTime.UtcNow); // Act ActionResult result = _wikiController.PageToolbar(1); // Assert PartialViewResult partialResult = result.AssertResultIs <PartialViewResult>(); partialResult.AssertPartialViewRendered(); }
public void Internal_Links_Should_Resolve_With_Id() { // Bug #87 // Arrange Page page = new Page() { Id = 1, Title = "My first page" }; RepositoryMock repositoryStub = new RepositoryMock(); repositoryStub.AddNewPage(page, "My first page", "admin", DateTime.UtcNow); repositoryStub.SiteSettings = new SiteSettings() { MarkupType = "Markdown" }; ApplicationSettings settings = new ApplicationSettings(); settings.Installed = true; settings.UpgradeRequired = false; UrlResolverMock resolver = new UrlResolverMock(); resolver.InternalUrl = "blah"; MarkupConverter converter = new MarkupConverter(settings, repositoryStub, _pluginFactory); converter.UrlResolver = resolver; string markdownText = "[Link](My-first-page)"; string invalidMarkdownText = "[Link](My first page)"; // Act string expectedHtml = "<p><a href=\"blah\">Link</a></p>\n"; string expectedInvalidLinkHtml = "<p>[Link](My first page)</p>\n"; string actualHtml = converter.ToHtml(markdownText); string actualHtmlInvalidLink = converter.ToHtml(invalidMarkdownText); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml)); Assert.That(actualHtmlInvalidLink, Is.EqualTo(expectedInvalidLinkHtml)); }
public void CompareVersions_Has_Last_Two_Versions() { // Arrange DateTime createdDate = DateTime.Today.AddDays(-1); Page page = NewPage("admin"); PageContent v1Content = _repository.AddNewPage(page, "v1 text", "admin", createdDate); PageContent v2Content = _repository.AddNewPageContentVersion(page, "v2 text", "admin", createdDate.AddHours(1), 2); PageContent v3Content = _repository.AddNewPageContentVersion(page, "v3 text", "admin", createdDate.AddHours(2), 3); PageContent v4Content = _repository.AddNewPageContentVersion(page, "v4 text", "admin", createdDate.AddHours(3), 4); // Act List <PageViewModel> versionList = _historyService.CompareVersions(v4Content.Id).ToList(); // Assert Assert.That(versionList.Count, Is.EqualTo(2)); Assert.That(versionList[0].Id, Is.EqualTo(v3Content.Page.Id)); Assert.That(versionList[1].Id, Is.EqualTo(v4Content.Page.Id)); }
public void Images_Should_Support_Dimensions_And_Titles() { // Arrange Page page = new Page() { Id = 1, Title = "My first page" }; RepositoryMock repositoryStub = new RepositoryMock(); repositoryStub.AddNewPage(page, "My first page", "admin", DateTime.UtcNow); repositoryStub.SiteSettings = new SiteSettings() { MarkupType = "Markdown" }; ApplicationSettings settings = new ApplicationSettings(); settings.Installed = true; settings.UpgradeRequired = false; MarkupConverter converter = new MarkupConverter(settings, repositoryStub, _pluginFactory); string markdownText = "Here is an image with a title:![Image](/Image1.png \"Image\") \n\n" + "And another with equal dimensions ![Square](/Image1.png \"Square\" =250x) \n\n" + "And this one is a rectangle ![Rectangle](/Image1.png \"Rectangle\" =250x350)"; string expectedHtml = "<p>Here is an image with a title:<img src=\"/Attachments/Image1.png\" border=\"0\" alt=\"Image\" width=\"\" height=\"\" title=\"Image\" /> </p>\n\n" + "<p>And another with equal dimensions <img src=\"/Attachments/Image1.png\" border=\"0\" alt=\"Square\" width=\"250px\" height=\"\" title=\"Square\" /> </p>\n\n" + "<p>And this one is a rectangle <img src=\"/Attachments/Image1.png\" border=\"0\" alt=\"Rectangle\" width=\"250px\" height=\"350px\" title=\"Rectangle\" /></p>\n"; // Act string actualHtml = converter.ToHtml(markdownText); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml)); }
public void ExportAsXml_Should_Return_Non_Empty_Stream() { // Arrange _repository.AddNewPage(new Page() { Id = 1 }, "text", "admin", DateTime.UtcNow); _repository.AddNewPage(new Page() { Id = 2 }, "text", "admin", DateTime.UtcNow); // Act Stream stream = _wikiExporter.ExportAsXml(); // Assert Assert.That(stream.Length, Is.GreaterThan(1)); }
public void About_Should_Return_ViewResult_And_Page_With_About_Tag_As_Model() { // Arrange Page aboutPage = new Page() { Id = 1, Title = "about", Tags = "about" }; _repository.AddNewPage(aboutPage, "text", "nobody", DateTime.Now); // Act ViewResult result = _helpController.About() as ViewResult; // Assert Assert.That(result, Is.Not.Null); PageViewModel model = result.ModelFromActionResult <PageViewModel>(); Assert.NotNull(model, "Null model"); Assert.That(model.Id, Is.EqualTo(aboutPage.Id)); Assert.That(model.Title, Is.EqualTo(aboutPage.Title)); }
public void Should_Export_Pages_With_Content() { // Arrange RepositoryMock repository = new RepositoryMock(); repository.SiteSettings.PluginLastSaveDate = DateTime.Today; DateTime page1CreatedOn = new DateTime(2013, 01, 01, 12, 00, 00); DateTime page1ModifiedOn = new DateTime(2013, 01, 01, 13, 00, 00); DateTime page2CreatedOn = new DateTime(2013, 01, 02, 12, 00, 00); DateTime page2ModifiedOn = new DateTime(2013, 01, 02, 13, 00, 00); DateTime page3CreatedOn = new DateTime(2013, 01, 03, 12, 00, 00); DateTime page3ModifiedOn = new DateTime(2013, 01, 03, 13, 00, 00); Guid page1ContentId = new Guid("13a8ad19-b203-46f5-be10-11e0ebf6f812"); Guid page2ContentId = new Guid("143b0023-329a-49b9-97a4-5094a0e378a2"); Guid page3ContentId = new Guid("15ee19ef-c093-47de-97d2-83dec406d92d"); string page1Text = @"the text ;''' "" more text """ ; string page2Text = @"the text ;''' #### sdfsdfsdf #### "" blah text """ ; string page3Text = @"the text ;''' #### dddd **dddd** #### "" pppp text """ ; Page page1 = new Page() { CreatedBy = "created-by-user1", CreatedOn = page1CreatedOn, Id = 1, IsLocked = true, ModifiedBy = "modified-by-user2", ModifiedOn = page1ModifiedOn, Tags = "tag1,tag2,tag3", Title = "Page 1 title" }; Page page2 = new Page() { CreatedBy = "created-by-user2", CreatedOn = page2CreatedOn, Id = 2, IsLocked = true, ModifiedBy = "modified-by-user2", ModifiedOn = page2ModifiedOn, Tags = "tagA,tagB,tagC", Title = "Page 2 title" }; Page page3 = new Page() { CreatedBy = "created-by-user3", CreatedOn = page3CreatedOn, Id = 3, IsLocked = false, ModifiedBy = "modified-by-user3", ModifiedOn = page3ModifiedOn, Tags = "tagX,tagY,tagZ", Title = "Page 3 title" }; PageContent pageContent1 = repository.AddNewPage(page1, page1Text, "modified-by-user1", page1ModifiedOn); pageContent1.Id = page1ContentId; PageContent pageContent2 = repository.AddNewPage(page2, page2Text, "modified-by-user2", page2ModifiedOn); pageContent2.Id = page2ContentId; PageContent pageContent3 = repository.AddNewPage(page3, page3Text, "modified-by-user3", page3ModifiedOn); pageContent3.Id = page3ContentId; SqlExportBuilder builder = new SqlExportBuilder(repository, new PluginFactoryMock()); builder.IncludeConfiguration = false; builder.IncludePages = true; string expectedSql = ReadEmbeddedResource("expected-pages-export.sql"); // Act string actualSql = builder.Export(); // Assert Assert.That(actualSql, Is.EqualTo(expectedSql), actualSql); }
public void Should_Replace_Markdown_With_Internal_Link() { // Arrange string menuMarkup = "* [First link](my-page)\r\n"; string expectedHtml = "<ul><li><a href=\"/wiki/1/my-page\">First link</a></li></ul>"; RepositoryMock repository = new RepositoryMock(); repository.AddNewPage(new Page() { Title = "my page", Id = 1 }, "text", "user", DateTime.Now); repository.SiteSettings = new SiteSettings(); repository.SiteSettings.MarkupType = "Markdown"; repository.SiteSettings.MenuMarkup = menuMarkup; UserContextStub userContext = new UserContextStub(); ApplicationSettings applicationSettings = new ApplicationSettings(); applicationSettings.Installed = true; CacheMock cache = new CacheMock(); SiteCache siteCache = new SiteCache(applicationSettings, cache); MarkupConverter converter = new MarkupConverter(applicationSettings, repository, _pluginFactory); MenuParser parser = new MenuParser(converter, repository, siteCache, userContext); // Act string actualHtml = parser.GetMenu(); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml)); }
public void Should_Export_Pages_With_Content() { // Arrange RepositoryMock repository = new RepositoryMock(); repository.SiteSettings.PluginLastSaveDate = DateTime.Today; DateTime page1CreatedOn = new DateTime(2013, 01, 01, 12, 00, 00); DateTime page1ModifiedOn = new DateTime(2013, 01, 01, 13, 00, 00); DateTime page2CreatedOn = new DateTime(2013, 01, 02, 12, 00, 00); DateTime page2ModifiedOn = new DateTime(2013, 01, 02, 13, 00, 00); DateTime page3CreatedOn = new DateTime(2013, 01, 03, 12, 00, 00); DateTime page3ModifiedOn = new DateTime(2013, 01, 03, 13, 00, 00); Guid page1ContentId = new Guid("13a8ad19-b203-46f5-be10-11e0ebf6f812"); Guid page2ContentId = new Guid("143b0023-329a-49b9-97a4-5094a0e378a2"); Guid page3ContentId = new Guid("15ee19ef-c093-47de-97d2-83dec406d92d"); string page1Text = @"the text ;''' "" more text """; string page2Text = @"the text ;''' #### sdfsdfsdf #### "" blah text """; string page3Text = @"the text ;''' #### dddd **dddd** #### "" pppp text """; Page page1 = new Page() { CreatedBy = "created-by-user1", CreatedOn = page1CreatedOn, Id = 1, IsLocked = true, ModifiedBy = "modified-by-user2", ModifiedOn = page1ModifiedOn, Tags = "tag1,tag2,tag3", Title = "Page 1 title" }; Page page2 = new Page() { CreatedBy = "created-by-user2", CreatedOn = page2CreatedOn, Id = 2, IsLocked = true, ModifiedBy = "modified-by-user2", ModifiedOn = page2ModifiedOn, Tags = "tagA,tagB,tagC", Title = "Page 2 title" }; Page page3 = new Page() { CreatedBy = "created-by-user3", CreatedOn = page3CreatedOn, Id = 3, IsLocked = false, ModifiedBy = "modified-by-user3", ModifiedOn = page3ModifiedOn, Tags = "tagX,tagY,tagZ", Title = "Page 3 title" }; PageContent pageContent1 = repository.AddNewPage(page1, page1Text, "modified-by-user1", page1ModifiedOn); pageContent1.Id = page1ContentId; PageContent pageContent2 = repository.AddNewPage(page2, page2Text, "modified-by-user2", page2ModifiedOn); pageContent2.Id = page2ContentId; PageContent pageContent3 = repository.AddNewPage(page3, page3Text, "modified-by-user3", page3ModifiedOn); pageContent3.Id = page3ContentId; SqlExportBuilder builder = new SqlExportBuilder(repository, new PluginFactoryMock()); builder.IncludeConfiguration = false; builder.IncludePages = true; string expectedSql = ReadEmbeddedResource("expected-pages-export.sql"); // Act string actualSql = builder.Export(); // Assert Assert.That(actualSql, Is.EqualTo(expectedSql), actualSql); }