public void WriteBlock_OnlyRendersCodeIfEnableHtmlForBlockIsFalse(string dummyCode, string expectedResult) { // Arrange FlexiCodeBlock dummyFlexiCodeBlock = CreateFlexiCodeBlock(code: dummyCode); ExposedFlexiCodeBlockRenderer testSubject = CreateExposedFlexiCodeBlockRenderer(); // Act var dummyStringWriter = new StringWriter(); var dummyHtmlRenderer = new HtmlRenderer(dummyStringWriter) { EnableHtmlForBlock = false }; testSubject.Write(dummyHtmlRenderer, dummyFlexiCodeBlock); string result = dummyStringWriter.ToString(); // Assert Assert.Equal(expectedResult, result, ignoreLineEndingDifferences: true); }
public void CreateCore_CreatesFlexiCodeBlock() { // Arrange const int dummyLine = 6; const int dummyColumn = 2; var dummySpan = new SourceSpan(5, 10); const string dummyBlockName = "dummyBlockName"; const string dummyTitle = "dummyTitle"; const string dummyCopyIcon = "dummyCopyIcon"; const bool dummyRenderHeader = false; const string dummyLanguage = "dummyLanguage"; var dummyLines = new StringLineGroup(2); dummyLines.Add(new StringSlice("dummy")); dummyLines.Add(new StringSlice("line")); const SyntaxHighlighter dummySyntaxHighlighter = SyntaxHighlighter.HighlightJS; var dummyLineNumbers = new ReadOnlyCollection <NumberedLineRange>(new List <NumberedLineRange>()); var dummyResolvedLineNumbers = new ReadOnlyCollection <NumberedLineRange>(new List <NumberedLineRange>()); const string dummyOmittedLinesIcon = "dummyOmittedLinesIcon"; var dummyHighlightedLines = new ReadOnlyCollection <LineRange>(new List <LineRange>()); var dummyResolvedHighlightedLines = new ReadOnlyCollection <LineRange>(new List <LineRange>()); var dummyHighlightedPhrases = new ReadOnlyCollection <PhraseGroup>(new List <PhraseGroup>()); var dummyResolvedHighlightedPhrases = new ReadOnlyCollection <Phrase>(new List <Phrase>()); const FlexiCodeBlockRenderingMode dummyRenderingMode = FlexiCodeBlockRenderingMode.Classic; var dummyAttributes = new ReadOnlyDictionary <string, string>(new Dictionary <string, string>()); Mock <BlockParser> dummyBlockParser = _mockRepository.Create <BlockParser>(); var dummyProxyLeafBlock = new ProxyLeafBlock(null, dummyBlockParser.Object); dummyProxyLeafBlock.Line = dummyLine; dummyProxyLeafBlock.Column = dummyColumn; dummyProxyLeafBlock.Span = dummySpan; dummyProxyLeafBlock.Lines = dummyLines; BlockProcessor dummyBlockProcessor = MarkdigTypesFactory.CreateBlockProcessor(); Mock <IFlexiCodeBlockOptions> mockFlexiCodeBlockOptions = _mockRepository.Create <IFlexiCodeBlockOptions>(); mockFlexiCodeBlockOptions.Setup(f => f.BlockName).Returns(dummyBlockName); mockFlexiCodeBlockOptions.Setup(f => f.Title).Returns(dummyTitle); mockFlexiCodeBlockOptions.Setup(f => f.CopyIcon).Returns(dummyCopyIcon); mockFlexiCodeBlockOptions.Setup(f => f.RenderHeader).Returns(dummyRenderHeader); mockFlexiCodeBlockOptions.Setup(f => f.Language).Returns(dummyLanguage); mockFlexiCodeBlockOptions.Setup(f => f.SyntaxHighlighter).Returns(dummySyntaxHighlighter); mockFlexiCodeBlockOptions.Setup(f => f.LineNumbers).Returns(dummyLineNumbers); mockFlexiCodeBlockOptions.Setup(f => f.OmittedLinesIcon).Returns(dummyOmittedLinesIcon); mockFlexiCodeBlockOptions.Setup(f => f.HighlightedLines).Returns(dummyHighlightedLines); mockFlexiCodeBlockOptions.Setup(f => f.HighlightedPhrases).Returns(dummyHighlightedPhrases); mockFlexiCodeBlockOptions.Setup(f => f.RenderingMode).Returns(dummyRenderingMode); mockFlexiCodeBlockOptions.Setup(f => f.Attributes).Returns(dummyAttributes); Mock <IOptionsService <IFlexiCodeBlockOptions, IFlexiCodeBlocksExtensionOptions> > mockOptionsService = _mockRepository. Create <IOptionsService <IFlexiCodeBlockOptions, IFlexiCodeBlocksExtensionOptions> >(); mockOptionsService.Setup(f => f.CreateOptions(dummyBlockProcessor)). Returns((mockFlexiCodeBlockOptions.Object, null)); Mock <FlexiCodeBlockFactory> mockTestSubject = CreateMockFlexiCodeBlockFactory(mockOptionsService.Object); mockTestSubject.CallBase = true; mockTestSubject.Setup(t => t.ResolveBlockName(dummyBlockName)).Returns(dummyBlockName); mockTestSubject.Setup(t => t.ValidateSyntaxHighlighter(dummySyntaxHighlighter)); mockTestSubject.Setup(t => t.TryCreateSortedLineRanges(dummyLineNumbers, dummyLines.Count)).Returns(dummyResolvedLineNumbers); mockTestSubject.Setup(t => t.ValidateSortedLineNumbers(It.Is <ReadOnlyCollection <NumberedLineRange> >(lineNumbers => lineNumbers == dummyResolvedLineNumbers), dummyLines.Count)); mockTestSubject.Setup(t => t.TryCreateSortedLineRanges(dummyHighlightedLines, dummyLines.Count)).Returns(dummyResolvedHighlightedLines); mockTestSubject. Setup(t => t.ResolveHighlightedPhrases(dummyLines.ToString(), It.Is <ReadOnlyCollection <PhraseGroup> >(highlightedPhrases => highlightedPhrases == dummyHighlightedPhrases))) .Returns(dummyResolvedHighlightedPhrases); mockTestSubject.Setup(t => t.ValidateRenderingMode(dummyRenderingMode)); // Act FlexiCodeBlock result = mockTestSubject.Object.CreateCore(dummyProxyLeafBlock, dummyBlockProcessor); // Assert _mockRepository.VerifyAll(); Assert.Equal(dummyBlockName, result.BlockName); Assert.Equal(dummyTitle, result.Title); Assert.Equal(dummyCopyIcon, result.CopyIcon); Assert.Equal(dummyRenderHeader, result.RenderHeader); Assert.Equal(dummyLanguage, result.Language); Assert.Equal(dummyLines.ToString(), result.Code); Assert.Equal(dummyLines.Count, result.CodeNumLines); Assert.Equal(dummySyntaxHighlighter, result.SyntaxHighlighter); Assert.Same(dummyResolvedLineNumbers, result.LineNumbers); Assert.Same(dummyOmittedLinesIcon, result.OmittedLinesIcon); Assert.Same(dummyResolvedHighlightedLines, result.HighlightedLines); Assert.Same(dummyResolvedHighlightedPhrases, result.HighlightedPhrases); Assert.Equal(dummyRenderingMode, result.RenderingMode); Assert.Same(dummyAttributes, result.Attributes); Assert.Same(dummyBlockParser.Object, result.Parser); Assert.Equal(dummyLine, result.Line); Assert.Equal(dummyColumn, result.Column); Assert.Equal(dummySpan, result.Span); }
public void ExposedWriteBlock(HtmlRenderer htmlRenderer, FlexiCodeBlock flexiCodeBlock) { base.WriteBlock(htmlRenderer, flexiCodeBlock); }