示例#1
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));
        }
		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.");
		}
		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);
		}