示例#1
0
        public void DocumentOnProcessInlinesBegin_DoesNotReplaceExistingLinkReferenceDefinitions()
        {
            // Arrange
            const string     dummyLinkLabelContent = "dummyLinkLabelContent";
            InlineProcessor  dummyInlineProcessor  = MarkdigTypesFactory.CreateInlineProcessor();
            FlexiFigureBlock dummyFlexiFigureBlock = CreateFlexiFigureBlock(linkLabelContent: dummyLinkLabelContent);

            dummyInlineProcessor.Document.SetData(FlexiFigureBlockFactory.REFERENCE_LINKABLE_FLEXI_FIGURE_BLOCKS_KEY,
                                                  new List <FlexiFigureBlock> {
                dummyFlexiFigureBlock
            });
            var dummyLinkReferenceDefinition = new LinkReferenceDefinition();

            dummyInlineProcessor.Document.SetLinkReferenceDefinition(dummyLinkLabelContent, dummyLinkReferenceDefinition);
            FlexiFigureBlockFactory testSubject = CreateFlexiFigureBlockFactory();

            // Act
            testSubject.DocumentOnProcessInlinesBegin(dummyInlineProcessor, null);

            // Assert
            Dictionary <string, LinkReferenceDefinition> linkReferenceDefinitions =
                (dummyInlineProcessor.Document.GetData(typeof(LinkReferenceDefinitionGroup)) as LinkReferenceDefinitionGroup)?.Links;

            Assert.Single(linkReferenceDefinitions);
            Assert.Same(dummyLinkReferenceDefinition, linkReferenceDefinitions.Values.First()); // Doesn't get replaced
        }
示例#2
0
        public void DocumentOnProcessInlinesBegin_CreatesAndAddsALinkReferenceDefinitionForEachReferenceLinkableFlexiFigureBlock()
        {
            // Arrange
            const string     dummyLinkLabelContent = "dummyLinkLabelContent";
            const string     dummyID               = "dummyID";
            const string     dummyName             = "dummyName";
            FlexiFigureBlock dummyFlexiFigureBlock = CreateFlexiFigureBlock(name: dummyName, linkLabelContent: dummyLinkLabelContent, id: dummyID);
            InlineProcessor  dummyInlineProcessor  = MarkdigTypesFactory.CreateInlineProcessor();

            dummyInlineProcessor.Document.SetData(FlexiFigureBlockFactory.REFERENCE_LINKABLE_FLEXI_FIGURE_BLOCKS_KEY, new List <FlexiFigureBlock> {
                dummyFlexiFigureBlock
            });
            FlexiFigureBlockFactory testSubject = CreateFlexiFigureBlockFactory();

            // Act
            testSubject.DocumentOnProcessInlinesBegin(dummyInlineProcessor, null);

            // Assert
            Dictionary <string, LinkReferenceDefinition> linkReferenceDefinitions = (dummyInlineProcessor.Document.GetData(typeof(LinkReferenceDefinitionGroup)) as LinkReferenceDefinitionGroup)?.Links;

            Assert.Single(linkReferenceDefinitions);
            LinkReferenceDefinition resultLinkReferenceDefinition = linkReferenceDefinitions.Values.First();

            Assert.Equal(dummyLinkLabelContent, resultLinkReferenceDefinition.Label);
            Assert.Equal($"#{dummyID}", resultLinkReferenceDefinition.Url);
            Assert.Equal(dummyName, resultLinkReferenceDefinition.Title);
        }
        public void WriteBlock_WritesBlock(FlexiFigureBlock dummyFlexiFigureBlock,
                                           string expectedResult)
        {
            // Arrange
            var dummyStringWriter = new StringWriter();
            var dummyHtmlRenderer = new HtmlRenderer(dummyStringWriter);
            ExposedFlexiFigureBlockRenderer testSubject = CreateExposedFlexiFigureBlockRenderer();

            // Act
            testSubject.ExposedWriteBlock(dummyHtmlRenderer, dummyFlexiFigureBlock);
            string result = dummyStringWriter.ToString();

            // Assert
            Assert.Equal(expectedResult, result, ignoreLineEndingDifferences: true);
        }
示例#4
0
        public void SetupReferenceLinking_AddsFlexiFigureBlockToReferenceLinkableFlexiFigureBlocksIfReferenceLinkableIsTrue()
        {
            // Arrange
            BlockProcessor   dummyBlockProcessor           = MarkdigTypesFactory.CreateBlockProcessor();
            FlexiFigureBlock dummyFlexiFigureBlock         = CreateFlexiFigureBlock();
            var dummyReferenceLinkableFlexiFigureBlocks    = new List <FlexiFigureBlock>();
            Mock <FlexiFigureBlockFactory> mockTestSubject = CreateMockFlexiFigureBlockFactory();

            mockTestSubject.CallBase = true;
            mockTestSubject.Setup(t => t.GetOrCreateReferenceLinkableFlexiFigureBlocks(dummyBlockProcessor.Document)).Returns(dummyReferenceLinkableFlexiFigureBlocks);

            // Act
            mockTestSubject.Object.SetupReferenceLinking(dummyFlexiFigureBlock, true, dummyBlockProcessor);

            // Assert
            _mockRepository.VerifyAll();
            Assert.Single(dummyReferenceLinkableFlexiFigureBlocks);
            Assert.Same(dummyFlexiFigureBlock, dummyReferenceLinkableFlexiFigureBlocks[0]);
        }
        public void WriteBlock_OnlyWritesChildrenIfEnableHtmlForBlockIsFalse()
        {
            // Arrange
            const string dummyContent = "dummyContent";
            var          dummyContentContainerInline = new ContainerInline();

            dummyContentContainerInline.AppendChild(new LiteralInline(dummyContent));
            var dummyContentParagraphBlock = new ParagraphBlock()
            {
                Inline = dummyContentContainerInline
            };
            var dummyContentPartBlock = new PlainContainerBlock(null);

            dummyContentPartBlock.Add(dummyContentParagraphBlock);
            const string dummyCaption = "dummyCaption";
            var          dummyCaptionContainerInline = new ContainerInline();

            dummyCaptionContainerInline.AppendChild(new LiteralInline(dummyCaption));
            var dummyCaptionPartBlock = new PlainLeafBlock(null);

            dummyCaptionPartBlock.Inline = dummyCaptionContainerInline;
            FlexiFigureBlock dummyFlexiFigureBlock = CreateFlexiFigureBlock(contentPart: dummyContentPartBlock, captionPart: dummyCaptionPartBlock);
            var dummyStringWriter = new StringWriter();
            var dummyHtmlRenderer = new HtmlRenderer(dummyStringWriter)
            {
                EnableHtmlForBlock = false
            };
            ExposedFlexiFigureBlockRenderer testSubject = CreateExposedFlexiFigureBlockRenderer();

            // Act
            testSubject.ExposedWriteBlock(dummyHtmlRenderer, dummyFlexiFigureBlock);
            string result = dummyStringWriter.ToString();

            // Assert
            Assert.Equal($"{dummyContent}\n{dummyCaption}\n", result, ignoreLineEndingDifferences: true);
        }
 public void ExposedWriteBlock(HtmlRenderer htmlRenderer, FlexiFigureBlock flexiFigureBlock)
 {
     WriteBlock(htmlRenderer, flexiFigureBlock);
 }
示例#7
0
        public void Create_CreatesFlexiFigureBlock()
        {
            // Arrange
            const int      dummyColumn            = 2;
            var            dummyLine              = new StringSlice("dummyText", 3, 8);
            const string   dummyBlockName         = "dummyBlockName";
            const string   dummyResolvedBlockName = "dummyResolvedBlockName";
            const int      dummyFigureNumber      = 5;
            const bool     dummyGenerateID        = true;
            const string   dummyID = "dummyID";
            const bool     dummyReferenceLinkable         = true;
            const bool     dummyResolvedReferenceLinkable = false;
            const string   dummyLinkLabelContent          = "dummyLinkLabelContent";
            const bool     dummyLinkLabelContentSpecified = true;
            const bool     dummyRenderName = true;
            const string   dummyName       = "dummyName";
            const string   dummyResolvedLinkLabelContent = "dummyResolvedLinkLabelContent";
            BlockProcessor dummyBlockProcessor           = MarkdigTypesFactory.CreateBlockProcessor();

            dummyBlockProcessor.Column = dummyColumn;
            dummyBlockProcessor.Line   = dummyLine;
            Mock <BlockParser> dummyBlockParser = _mockRepository.Create <BlockParser>();
            var dummyAttributes = new ReadOnlyDictionary <string, string>(new Dictionary <string, string>());
            Mock <IFlexiFigureBlockOptions> mockFlexiFigureBlockOptions = _mockRepository.Create <IFlexiFigureBlockOptions>();

            mockFlexiFigureBlockOptions.Setup(f => f.BlockName).Returns(dummyBlockName);
            mockFlexiFigureBlockOptions.Setup(f => f.GenerateID).Returns(dummyGenerateID);
            mockFlexiFigureBlockOptions.Setup(f => f.ReferenceLinkable).Returns(dummyReferenceLinkable);
            mockFlexiFigureBlockOptions.Setup(f => f.RenderName).Returns(dummyRenderName);
            mockFlexiFigureBlockOptions.Setup(f => f.LinkLabelContent).Returns(dummyLinkLabelContent);
            mockFlexiFigureBlockOptions.Setup(f => f.Attributes).Returns(dummyAttributes);
            Mock <IOptionsService <IFlexiFigureBlockOptions, IFlexiFigureBlocksExtensionOptions> > mockOptionsService = _mockRepository.
                                                                                                                        Create <IOptionsService <IFlexiFigureBlockOptions, IFlexiFigureBlocksExtensionOptions> >();

            mockOptionsService.Setup(f => f.CreateOptions(dummyBlockProcessor)).
            Returns((mockFlexiFigureBlockOptions.Object, (IFlexiFigureBlocksExtensionOptions)null));
            Mock <FlexiFigureBlockFactory> mockTestSubject = CreateMockFlexiFigureBlockFactory(mockOptionsService.Object);

            mockTestSubject.CallBase = true;
            mockTestSubject.Setup(t => t.ResolveBlockName(dummyBlockName)).Returns(dummyResolvedBlockName);
            mockTestSubject.Setup(t => t.GetFlexiFigureBlockNumber(dummyBlockProcessor)).Returns(dummyFigureNumber);
            mockTestSubject.Setup(t => t.ResolveID(dummyGenerateID, dummyFigureNumber, dummyAttributes)).Returns(dummyID);
            mockTestSubject.Setup(t => t.ResolveReferenceLinkable(dummyReferenceLinkable, dummyID)).Returns(dummyResolvedReferenceLinkable);
            mockTestSubject.Setup(t => t.IsLinkLabelContentSpecified(dummyLinkLabelContent)).Returns(dummyLinkLabelContentSpecified);
            mockTestSubject.Setup(t => t.ResolveName(dummyResolvedReferenceLinkable, dummyLinkLabelContentSpecified, dummyRenderName, dummyFigureNumber)).Returns(dummyName);
            mockTestSubject.Setup(t => t.ResolveLinkLabelContent(dummyResolvedReferenceLinkable, dummyLinkLabelContentSpecified, dummyName, dummyLinkLabelContent)).Returns(dummyResolvedLinkLabelContent);

            // Act
            FlexiFigureBlock result = mockTestSubject.Object.Create(dummyBlockProcessor, dummyBlockParser.Object);

            // Assert
            _mockRepository.VerifyAll();
            Assert.Equal(dummyResolvedBlockName, result.BlockName);
            Assert.Equal(dummyName, result.Name);
            Assert.Equal(dummyRenderName, result.RenderName);
            Assert.Equal(dummyResolvedLinkLabelContent, result.LinkLabelContent);
            Assert.Equal(dummyID, result.ID);
            Assert.Same(dummyAttributes, result.Attributes);
            Assert.Same(dummyBlockParser.Object, result.Parser);
            Assert.Equal(dummyColumn, result.Column);
            Assert.Equal(dummyLine.Start, result.Span.Start);
            Assert.Equal(0, result.Span.End);
        }