Exemplo n.º 1
0
		public void Should_Replace_Known_Tokens_When_Logged_In_As_Admin()
		{
			// Arrange
			string menuMarkup = "* %categories%\r\n\r\n%allpages%\r\n%mainpage%\r\n%newpage%\r\n%managefiles%\r\n%sitesettings%\r\n";
			string expectedHtml = "<ul><li><a href=\"/pages/alltags\">Categories</a></li></ul>" +
								  "<a href=\"/pages/allpages\">All pages</a>" +
								  "<a href=\"/\">Main Page</a>" +
								  "<a href=\"/pages/new\">New page</a>" +
								  "<a href=\"/filemanager\">Manage files</a>" +
								  "<a href=\"/settings\">Site settings</a>";

			RepositoryMock repository = new RepositoryMock();
			repository.SiteSettings = new SiteSettings();
			repository.SiteSettings.MarkupType = "Markdown";
			repository.SiteSettings.MenuMarkup = menuMarkup;

			UserContextStub userContext = new UserContextStub();
			userContext.IsAdmin = true;
			userContext.IsLoggedIn = true;

			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), actualHtml);
		}
Exemplo n.º 2
0
 public MenuParser(MarkupConverter markupConverter, IRepository repository, SiteCache siteCache, IUserContext userContext)
 {
     _markupConverter = markupConverter;
     _repository = repository;
     _siteCache = siteCache;
     _userContext = userContext;
 }
Exemplo n.º 3
0
        public PageViewModel(PageContent pageContent, MarkupConverter converter)
        {
            if (pageContent == null)
                throw new ArgumentNullException("pageContent");

            if (pageContent.Page == null)
                throw new ArgumentNullException("pageContent.Page");

            if (converter == null)
                throw new ArgumentNullException("converter");

            Id = pageContent.Page.Id;
            Title = pageContent.Page.Title;
            PreviousTitle = pageContent.Page.Title;
            CreatedBy = pageContent.Page.CreatedBy;
            CreatedOn = pageContent.Page.CreatedOn;
            IsLocked = pageContent.Page.IsLocked;
            ModifiedBy = pageContent.Page.ModifiedBy;
            ModifiedOn = pageContent.Page.ModifiedOn;
            RawTags = pageContent.Page.Tags;
            Content = pageContent.Text;
            VersionNumber = pageContent.VersionNumber;

            PageHtml pageHtml = converter.ToHtml(pageContent.Text);
            ContentAsHtml = pageHtml.Html;
            IsCacheable = pageHtml.IsCacheable;
            PluginHeadHtml = pageHtml.HeadHtml;
            PluginFooterHtml = pageHtml.FooterHtml;
            PluginPreContainer = pageHtml.PreContainerHtml;
            PluginPostContainer = pageHtml.PostContainerHtml;

            CreatedOn = DateTime.SpecifyKind(CreatedOn, DateTimeKind.Utc);
            ModifiedOn = DateTime.SpecifyKind(ModifiedOn, DateTimeKind.Utc);
            AllTags = new List<TagViewModel>();
        }
Exemplo n.º 4
0
		public MenuParser(MarkupConverter markupConverter, ISettingsRepository settingsRepository, SiteCache siteCache, IUserContext userContext)
		{
			_markupConverter = markupConverter;
			_settingsRepository = settingsRepository;
			_siteCache = siteCache;
			_userContext = userContext;
		}
Exemplo n.º 5
0
        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));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Creates a new instance of MocksAndStubsContainer.
        /// </summary>
        /// <param name="useCacheMock">The 'Roadkill' MemoryCache is used by default, but as this is static it can have problems with 
        /// the test runner unless you clear the Container.MemoryCache on setup each time, but then doing that doesn't give a realistic 
        /// reflection of how the MemoryCache is used inside an ASP.NET environment.</param>
        public MocksAndStubsContainer(bool useCacheMock = false)
        {
            ApplicationSettings = new ApplicationSettings();
            ApplicationSettings.Installed = true;
            ApplicationSettings.AttachmentsFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "attachments");

            // Cache
            MemoryCache = useCacheMock ? new CacheMock() : CacheMock.RoadkillCache;
            ListCache = new ListCache(ApplicationSettings, MemoryCache);
            SiteCache = new SiteCache(ApplicationSettings, MemoryCache);
            PageViewModelCache = new PageViewModelCache(ApplicationSettings, MemoryCache);

            // Repository
            Repository = new RepositoryMock();
            Repository.SiteSettings = new SiteSettings();
            Repository.SiteSettings.MarkupType = "Creole";

            PluginFactory = new PluginFactoryMock();
            MarkupConverter = new MarkupConverter(ApplicationSettings, Repository, PluginFactory);

            // Dependencies for PageService. Be careful to make sure the class using this Container isn't testing the mock.
            SettingsService = new SettingsService(ApplicationSettings, Repository);
            UserService = new UserServiceMock(ApplicationSettings, Repository);
            UserContext = new UserContext(UserService);
            SearchService = new SearchServiceMock(ApplicationSettings, Repository, PluginFactory);
            SearchService.PageContents = Repository.PageContents;
            SearchService.Pages = Repository.Pages;
            HistoryService = new PageHistoryService(ApplicationSettings, Repository, UserContext, PageViewModelCache, PluginFactory);

            PageService = new PageService(ApplicationSettings, Repository, SearchService, HistoryService, UserContext, ListCache, PageViewModelCache, SiteCache, PluginFactory);

            // EmailTemplates
            EmailClient = new EmailClientMock();
        }
Exemplo n.º 7
0
        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));
        }
Exemplo n.º 8
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);
            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));
        }
Exemplo n.º 9
0
		public HomeController(ApplicationSettings settings, UserServiceBase userManager, MarkupConverter markupConverter,
			PageService pageService, SearchService searchService, IUserContext context, SettingsService settingsService)
			: base(settings, userManager, context, settingsService) 
		{
			_markupConverter = markupConverter;
			_searchService = searchService;
			PageService = pageService;
		}
Exemplo n.º 10
0
		public PageHistoryService(ApplicationSettings settings, IRepository repository, IUserContext context,
			PageViewModelCache pageViewModelCache, IPluginFactory pluginFactory)
			: base(settings, repository)
		{
			_markupConverter = new MarkupConverter(settings, repository, pluginFactory);
			_context = context;
			_pageViewModelCache = pageViewModelCache;
		}
Exemplo n.º 11
0
		public PageHistoryService(ApplicationSettings settings, ISettingsRepository settingsRepository, IPageRepository pageRepository, IUserContext context, 
			PageViewModelCache pageViewModelCache, IPluginFactory pluginFactory)
		{
			_markupConverter = new MarkupConverter(settings, settingsRepository, pageRepository, pluginFactory);
			_context = context;
			_pageViewModelCache = pageViewModelCache;

			SettingsRepository = settingsRepository;
			PageRepository = pageRepository;
		}
Exemplo n.º 12
0
		public void Setup()
		{
			_container = new MocksAndStubsContainer();

			_pluginFactory = _container.PluginFactory;
			_appSettings = _container.ApplicationSettings;
			_appSettings.Installed = true;
			_repository = _container.Repository;
			_markupConverter = _container.MarkupConverter;
			_markupConverter.UrlResolver = new UrlResolverMock();
		}
Exemplo n.º 13
0
		public void parser_should_not_be_null_for_markuptypes()
		{
			// Arrange, act
			_settingsRepository.SiteSettings.MarkupType = "Creole";

			// Assert
			_markupConverter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory);
			Assert.NotNull(_markupConverter.Parser);

			_settingsRepository.SiteSettings.MarkupType = "Markdown";
			_markupConverter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory);
			Assert.NotNull(_markupConverter.Parser);
		}
Exemplo n.º 14
0
		public void Setup()
		{
			_container = new MocksAndStubsContainer();

			_applicationSettings = _container.ApplicationSettings;
			_applicationSettings.UseHtmlWhiteList = true;
			_applicationSettings.CustomTokensPath = Path.Combine(Settings.WEB_PATH, "App_Data", "customvariables.xml");

			_pluginFactory = _container.PluginFactory;
			_repository = _container.Repository;
			_markupConverter = _container.MarkupConverter;
			_markupConverter.UrlResolver = new UrlResolverMock();
		}
Exemplo n.º 15
0
 public RelService(ApplicationSettings settings, IRepository repository, SearchService searchService,
     PageHistoryService historyService, IUserContext context,
     ListCache listCache, PageViewModelCache pageViewModelCache, SiteCache sitecache, IPluginFactory pluginFactory)
     : base(settings, repository)
 {
     _searchService = searchService;
     _markupConverter = new MarkupConverter(settings, repository, pluginFactory);
     _historyService = historyService;
     _context = context;
     _listCache = listCache;
     _pageViewModelCache = pageViewModelCache;
     _siteCache = sitecache;
     _pluginFactory = pluginFactory;
 }
Exemplo n.º 16
0
        public void Attachment_Link_Should_Not_Have_NoFollow_Attribute()
        {
            // Arrange
            _repository.SiteSettings.MarkupType = "Creole";
            _markupConverter = new MarkupConverter(_applicationSettings, _repository, _pluginFactory);

            string expectedHtml = "<p><a href=\"&#x2F;Attachments&#x2F;folder&#x2F;myfile&#x2E;jpg\">Some link text</a> <a href=\"&#x2F;Attachments&#x2F;folder2&#x2F;myfile&#x2E;jpg\">Some link text</a>\n</p>";

            // Act
            string actualHtml = _markupConverter.ToHtml("[[~/folder/myfile.jpg|Some link text]] [[attachment:/folder2/myfile.jpg|Some link text]]");

            // Assert
            Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml);
        }
Exemplo n.º 17
0
        public void External_Links_With_Anchor_Tag_Should_Retain_The_Anchor()
        {
            // Issue #172
            // Arrange
            _repository.SiteSettings.MarkupType = "Creole";
            _repository.AddNewPage(new Page() { Id = 1, Title = "foo" }, "foo", "admin", DateTime.Today);
            _markupConverter = new MarkupConverter(_applicationSettings, _repository, _pluginFactory);

            string expectedHtml = "<p><a rel=\"nofollow\" href=\"http&#x3A;&#x2F;&#x2F;www&#x2E;google&#x2E;com&#x2F;&#x3F;blah&#x3D;xyz&#x23;myanchor\" class=\"external&#x2D;link\">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);
        }
Exemplo n.º 18
0
        public void Html_Should_Not_Be_Sanitized_If_UseHtmlWhiteList_Setting_Is_False()
        {
            // Arrange
            _applicationSettings.UseHtmlWhiteList = false;
            _repository.SiteSettings.MarkupType = "Creole";
            _markupConverter = new MarkupConverter(_applicationSettings, _repository, _pluginFactory);

            string htmlFragment = "<div onclick=\"javascript:alert('ouch');\">test</div>";
            MarkupConverter converter = new MarkupConverter(_applicationSettings, _repository, _pluginFactory);

            // Act
            string actualHtml = converter.ToHtml(htmlFragment);

            // Assert
            string expectedHtml = "<p>" + htmlFragment + "\n</p>";
            Assert.That(actualHtml, Is.EqualTo(expectedHtml));
        }
Exemplo n.º 19
0
		public void Parser_Should_Not_Be_Null_For_MarkupTypes()
		{
			// Arrange, act
			_repository.SiteSettings.MarkupType = "Creole";
			_markupConverter = new MarkupConverter(_applicationSettings, _repository, _pluginFactory);

			// Assert
			Assert.NotNull(_markupConverter.Parser);

			_repository.SiteSettings.MarkupType = "Markdown";
			_markupConverter = new MarkupConverter(_applicationSettings, _repository, _pluginFactory);
			Assert.NotNull(_markupConverter.Parser);

			_repository.SiteSettings.MarkupType = "Mediawiki";
			_markupConverter = new MarkupConverter(_applicationSettings, _repository, _pluginFactory);
			Assert.NotNull(_markupConverter.Parser);
		}
Exemplo n.º 20
0
		public PageService(ApplicationSettings settings, ISettingsRepository settingsRepository, IPageRepository pageRepository, SearchService searchService, 
			PageHistoryService historyService, IUserContext context, 
			ListCache listCache, PageViewModelCache pageViewModelCache, SiteCache sitecache, IPluginFactory pluginFactory)
		{
			_searchService = searchService;
			_markupConverter = new MarkupConverter(settings, settingsRepository, pageRepository, pluginFactory);
			_historyService = historyService;
			_context = context;
			_listCache = listCache;
			_pageViewModelCache = pageViewModelCache;
			_siteCache = sitecache;
			_pluginFactory = pluginFactory;
			_markupLinkUpdater = new MarkupLinkUpdater(_markupConverter.Parser);

			ApplicationSettings = settings;
			SettingsRepository = settingsRepository;
			PageRepository = pageRepository;
		}
Exemplo n.º 21
0
		public void Setup()
		{
			_container = new MocksAndStubsContainer();

			_applicationSettings = _container.ApplicationSettings;

			_settingsRepository = _container.SettingsRepository;
			_pageRepository = _container.PageRepository;
			
			_pluginFactory = _container.PluginFactory;
			_settingsService = _container.SettingsService;
			_userService = _container.UserService;
			_historyService = _container.HistoryService;
			_markupConverter = _container.MarkupConverter;
			_searchService = _container.SearchService;

			// Use a stub instead of the MocksAndStubsContainer's default
			_contextStub = new UserContextStub();

			// Customise the page service so we can verify what was called
			_pageServiceMock = new Mock<IPageService>();
			_pageServiceMock.Setup(x => x.GetMarkupConverter()).Returns(new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory));
			_pageServiceMock.Setup(x => x.GetById(It.IsAny<int>(), false)).Returns<int, bool>((int id, bool loadContent) =>
				{
					Page page = _pageRepository.GetPageById(id);
					return new PageViewModel(page);
				});
			_pageServiceMock.Setup(x => x.GetById(It.IsAny<int>(), true)).Returns<int,bool>((int id, bool loadContent) =>
			{
				PageContent content = _pageRepository.GetLatestPageContent(id);

				if (content != null)
					return new PageViewModel(content, _markupConverter);
				else
					return null;
			});
			_pageServiceMock.Setup(x => x.FindByTag(It.IsAny<string>()));
			_pageService = _pageServiceMock.Object;

			_pagesController = new PagesController(_applicationSettings, _userService, _settingsService, _pageService, _searchService, _historyService, _contextStub);
			_mocksContainer = _pagesController.SetFakeControllerContext();
		}
Exemplo n.º 22
0
		public void Setup()
		{
			_pluginFactory = new PluginFactoryMock();

			_pageRepository = new PageRepositoryMock();

			_settingsRepository = new SettingsRepositoryMock();
			_settingsRepository.SiteSettings = new SiteSettings();
			_settingsRepository.SiteSettings.MarkupType = "Markdown";

			_userContext = new UserContextStub();

			_applicationSettings = new ApplicationSettings();
			_applicationSettings.Installed = true;

			_cache = new CacheMock();
			_siteCache = new SiteCache(_cache);

			_converter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory);
			_menuParser = new MenuParser(_converter, _settingsRepository, _siteCache, _userContext);
		}
Exemplo n.º 23
0
		public SearchService(ApplicationSettings settings, ISettingsRepository settingsRepository, IPageRepository pageRepository, IPluginFactory pluginFactory)
		{
			if (settings == null)
				throw new ArgumentNullException(nameof(settings));

			if (settingsRepository == null)
				throw new ArgumentNullException(nameof(settingsRepository));

			if (pageRepository == null)
				throw new ArgumentNullException(nameof(pageRepository));

			if (pluginFactory == null)
				throw new ArgumentNullException(nameof(pluginFactory));

			_markupConverter = new MarkupConverter(settings, settingsRepository, pageRepository, pluginFactory);
			IndexPath = settings.SearchIndexPath;

			ApplicationSettings = settings;
			SettingsRepository = settingsRepository;
			PageRepository = pageRepository;
		}
Exemplo n.º 24
0
		public void imageparsed_should_convert_to_absolute_path()
		{
			// Arrange
			_settingsRepository.SiteSettings.MarkupType = "Markdown";
			UrlResolverMock resolver = new UrlResolverMock();
			resolver.AbsolutePathSuffix = "123";
			_markupConverter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory);
			_markupConverter.UrlResolver = resolver;

			// Act
			bool wasCalled = false;
			_markupConverter.Parser.ImageParsed += (object sender, ImageEventArgs e) =>
			{
				wasCalled = (e.Src == "/Attachments/DSC001.jpg123");
			};

			_markupConverter.ToHtml("![Image title](/DSC001.jpg)");

			// Assert
			Assert.True(wasCalled, "ImageParsed.ImageEventArgs.Src did not match.");
		}
Exemplo n.º 25
0
		public void Setup()
		{
			_container = new MocksAndStubsContainer();

			_applicationSettings = _container.ApplicationSettings;
			_context = _container.UserContext;
			_pageRepository = _container.PageRepository;
			_pluginFactory = _container.PluginFactory;
			_settingsService = _container.SettingsService;
			_userService = _container.UserService;
			_historyService = _container.HistoryService;
			_pageService = _container.PageService;
			_searchService = _container.SearchService;
			_markupConverter = _container.MarkupConverter;

			_listCache = _container.ListCache;
			_siteCache = _container.SiteCache;
			_pageViewModelCache = _container.PageViewModelCache;
			_memoryCache = _container.MemoryCache;

			_homeController = new HomeController(_applicationSettings, _userService, _markupConverter, _pageService, _searchService, _context, _settingsService);
			_homeController.SetFakeControllerContext();
		}
Exemplo n.º 26
0
        public void Should_Cache_Menu_Html_For_Admin_And_Editor_And_Guest_User()
        {
            // Arrange
            string menuMarkup = "My menu %newpage% %sitesettings%";

            RepositoryMock repository = new RepositoryMock();
            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
            userContext.IsLoggedIn = false;
            userContext.IsAdmin = false;
            parser.GetMenu();

            userContext.IsLoggedIn = true;
            userContext.IsAdmin = false;
            parser.GetMenu();

            userContext.IsLoggedIn = true;
            userContext.IsAdmin = true;
            parser.GetMenu();

            // Assert
            Assert.That(cache.CacheItems.Count, Is.EqualTo(3));
        }
Exemplo n.º 27
0
		public void ImageParsed_Should_Not_Rewrite_Images_As_Internal_That_Start_With_Known_Prefixes(string imageUrl)
		{
			// Arrange
			_settingsRepository.SiteSettings.MarkupType = "Markdown";
			UrlResolverMock resolver = new UrlResolverMock();
			resolver.AbsolutePathSuffix = "123";

			_markupConverter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory);
			_markupConverter.UrlResolver = resolver;

			bool wasCalled = false;
			_markupConverter.Parser.ImageParsed += (object sender, ImageEventArgs e) =>
			{
				wasCalled = (e.Src == imageUrl);
			};

			// Act
			_markupConverter.ToHtml("![Image title](" + imageUrl + ")");

			// Assert
			Assert.True(wasCalled);
		}
Exemplo n.º 28
0
		public void Parser_Should_Throw_Exception_For_MediaWiki()
		{
			// Arrange, act + assert
			_settingsRepository.SiteSettings.MarkupType = "MediaWiki";
			_markupConverter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory);
		}
Exemplo n.º 29
0
		public void should_not_render_toc_with_multiple_curlies()
		{
			// Arrange
			_settingsRepository.SiteSettings.MarkupType = "Creole";
			_markupConverter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory);
			_markupConverter.UrlResolver = new UrlResolverMock();

			string htmlFragment = "Give me a {{TOC}} and a {{{TOC}}} - the should not render a TOC";
			string expected = @"<p>Give me a <div class=""floatnone""><div class=""image&#x5F;frame""><img src=""&#x2F;Attachments&#x2F;TOC""></div></div> and a TOC - the should not render a TOC"
				+ "\n</p>";

			// Act
			string actualHtml = _markupConverter.ToHtml(htmlFragment);

			// Assert
			Assert.That(actualHtml, Is.EqualTo(expected));
		}
Exemplo n.º 30
0
		public void links_starting_with_http_www_mailto_tag_are_no_rewritten_as_internal()
		{
			// Arrange
			_settingsRepository.SiteSettings.MarkupType = "Creole";
			_markupConverter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory);

			string expectedHtml = "<p><a rel=\"nofollow\" href=\"http&#x3A;&#x2F;&#x2F;www&#x2E;blah&#x2E;com\" class=\"external&#x2D;link\">link1</a> <a rel=\"nofollow\" href=\"www&#x2E;blah&#x2E;com\" class=\"external&#x2D;link\">link2</a> <a rel=\"nofollow\" href=\"mailto&#x3A;spam&#x40;gmail&#x2E;com\" class=\"external&#x2D;link\">spam</a>\n</p>";

			// Act
			string actualHtml = _markupConverter.ToHtml("[[http://www.blah.com|link1]] [[www.blah.com|link2]] [[mailto:[email protected]|spam]]");

			// Assert
			Assert.That(actualHtml, Is.EqualTo(expectedHtml));
		}