Exemple #1
0
        public void WriteCard_WritesCard(FlexiCardBlock dummyFlexiCardBlock, string dummyBlockName, string expectedResult)
        {
            // Arrange
            var dummyStringWriter = new StringWriter();
            var dummyHtmlRenderer = new HtmlRenderer(dummyStringWriter);
            FlexiCardsBlockRenderer testSubject = CreateFlexiCardsBlockRenderer();

            // Act
            testSubject.WriteCard(dummyHtmlRenderer, dummyFlexiCardBlock, dummyBlockName);
            string result = dummyStringWriter.ToString();

            // Assert
            Assert.Equal(expectedResult, result, ignoreLineEndingDifferences: true);
        }
Exemple #2
0
        public void Create_CreatesFlexiCardBlock()
        {
            // Arrange
            const int                      dummyColumn                = 2;
            var                            dummyLine                  = new StringSlice("dummyText", 3, 8);
            const string                   dummyUrl                   = "dummyUrl";
            const string                   dummyBackgroundIcon        = "dummyBackgroundIcon";
            IFlexiCardBlockOptions         dummyDefaultCardOptions    = _mockRepository.Create <IFlexiCardBlockOptions>().Object;
            Mock <IFlexiCardsBlockOptions> mockFlexiCardsBlockOptions = _mockRepository.Create <IFlexiCardsBlockOptions>();

            mockFlexiCardsBlockOptions.Setup(f => f.DefaultCardOptions).Returns(dummyDefaultCardOptions);
            Mock <BlockParser>   dummyBlockParser          = _mockRepository.Create <BlockParser>();
            ProxyFlexiCardsBlock dummyProxyFlexiCardsBlock = CreateProxyFlexiCardsBlock(mockFlexiCardsBlockOptions.Object, blockParser: dummyBlockParser.Object);
            BlockProcessor       dummyBlockProcessor       = MarkdigTypesFactory.CreateBlockProcessor();

            // Following 3 lines set dummyBlockProcessor.CurrentContainer
            dummyBlockParser.Setup(b => b.TryContinue(dummyBlockProcessor, dummyProxyFlexiCardsBlock)).Returns(BlockState.ContinueDiscard);
            dummyBlockProcessor.Open(dummyProxyFlexiCardsBlock);
            dummyBlockProcessor.ProcessLine(new StringSlice(string.Empty));
            dummyBlockProcessor.Column = dummyColumn;
            dummyBlockProcessor.Line   = dummyLine;
            var dummyAttributes = new ReadOnlyDictionary <string, string>(new Dictionary <string, string>());
            Mock <IFlexiCardBlockOptions> mockFlexiCardBlockOptions = _mockRepository.Create <IFlexiCardBlockOptions>();

            mockFlexiCardBlockOptions.Setup(f => f.Url).Returns(dummyUrl);
            mockFlexiCardBlockOptions.Setup(f => f.BackgroundIcon).Returns(dummyBackgroundIcon);
            mockFlexiCardBlockOptions.Setup(f => f.Attributes).Returns(dummyAttributes);
            Mock <IBlockOptionsFactory <IFlexiCardBlockOptions> > mockFlexiCardBlockOptionsFactory = _mockRepository.
                                                                                                     Create <IBlockOptionsFactory <IFlexiCardBlockOptions> >();

            mockFlexiCardBlockOptionsFactory.Setup(f => f.Create(dummyDefaultCardOptions, dummyBlockProcessor)).Returns(mockFlexiCardBlockOptions.Object);
            FlexiCardBlockFactory testSubject = CreateFlexiCardBlockFactory(mockFlexiCardBlockOptionsFactory.Object);

            // Act
            FlexiCardBlock result = testSubject.Create(dummyBlockProcessor, dummyBlockParser.Object);

            // Assert
            _mockRepository.VerifyAll();
            Assert.Equal(dummyUrl, result.Url);
            Assert.Equal(dummyBackgroundIcon, result.BackgroundIcon);
            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);
        }