public void TryOpen_WrapsNonBlockExceptionsAndBlockExceptionsWithoutBlockContextInBlockExceptionWithsBlockContextIfABlockIsCreated(Exception dummyException)
        {
            // Arrange
            Mock <Block>   mockBlock           = _mockRepository.Create <Block>(null);
            BlockProcessor dummyBlockProcessor = MarkdigTypesFactory.CreateBlockProcessor();

            dummyBlockProcessor.NewBlocks.Push(mockBlock.Object);
            Mock <BlockParser <Block> > mockTestSubject = CreateMockBlockParser <Block>();

            mockTestSubject.CallBase = true;
            mockTestSubject.Protected().Setup("TryOpenBlock", dummyBlockProcessor).Throws(dummyException);

            // Act and assert
            BlockException result = Assert.Throws <BlockException>(() => mockTestSubject.Object.TryOpen(dummyBlockProcessor));

            _mockRepository.VerifyAll();
            Assert.Equal(string.Format(Strings.BlockException_BlockException_InvalidBlock,
                                       mockBlock.Object.GetType().Name,
                                       mockBlock.Object.Line + 1,
                                       mockBlock.Object.Column,
                                       Strings.BlockException_BlockException_ExceptionOccurredWhileProcessingBlock),
                         result.Message,
                         ignoreLineEndingDifferences: true);
            Assert.Same(dummyException, result.InnerException);
        }
        public void Close_WrapsNonBlockExceptionsAndBlockExceptionsWithoutBlockContextInBlockExceptionsWithBlockContext(Exception dummyException)
        {
            // Arrange
            const int      dummyLineIndex      = 4;
            const int      dummyColumn         = 5;
            BlockProcessor dummyBlockProcessor = MarkdigTypesFactory.CreateBlockProcessor();
            Mock <Block>   mockBlock           = _mockRepository.Create <Block>(null);

            mockBlock.Object.Line   = dummyLineIndex; // Line isn't virtual
            mockBlock.Object.Column = dummyColumn;    // Column isn't virtual
            Mock <BlockParser <Block> > mockTestSubject = CreateMockBlockParser <Block>();

            mockTestSubject.CallBase = true;
            mockTestSubject.Protected().Setup("CloseBlock", dummyBlockProcessor, mockBlock.Object).Throws(dummyException);

            // Act and assert
            BlockException result = Assert.Throws <BlockException>(() => mockTestSubject.Object.Close(dummyBlockProcessor, mockBlock.Object));

            _mockRepository.VerifyAll();
            Assert.Equal(string.Format(Strings.BlockException_BlockException_InvalidBlock,
                                       mockBlock.Object.GetType().Name,
                                       dummyLineIndex + 1,
                                       dummyColumn,
                                       Strings.BlockException_BlockException_ExceptionOccurredWhileProcessingBlock),
                         result.Message,
                         ignoreLineEndingDifferences: true);
            Assert.Same(dummyException, result.InnerException);
        }
        public void TryContinueBlock_ReturnsBlockStateBreadDiscardAndUpdatesSpanEndIfLineContainsAClosingFence()
        {
            // Arrange
            const string dummyText = "dummyText";
            const int    dummyOpeningFenceCharCount           = 3;
            Mock <DummyProxyFencedBlock> mockProxyFencedBlock = _mockRepository.Create <DummyProxyFencedBlock>(null);

            mockProxyFencedBlock.Setup(p => p.OpeningFenceCharCount).Returns(dummyOpeningFenceCharCount);
            const int      dummyLineEnd        = 10;
            BlockProcessor dummyBlockProcessor = MarkdigTypesFactory.CreateBlockProcessor();

            dummyBlockProcessor.Line = new StringSlice(dummyText, 0, dummyLineEnd);
            Mock <ExposedFencedBlockParser> mockTestSubject = CreateMockExposedFencedBlockParser();

            mockTestSubject.CallBase = true;
            mockTestSubject.Setup(t => t.LineContainsClosingFence(It.Is <StringSlice>(s => s.Text == dummyText), dummyOpeningFenceCharCount)).Returns(true);

            // Act
            BlockState result = mockTestSubject.Object.ExposedTryContinueBlock(dummyBlockProcessor, mockProxyFencedBlock.Object);

            // Assert
            _mockRepository.VerifyAll();
            Assert.Equal(BlockState.BreakDiscard, result);
            Assert.Equal(dummyLineEnd, mockProxyFencedBlock.Object.Span.End);
        }
        public void TryOpenBlock_ThrowsBlockExceptionIfAnExceptionIsThrownWhileCreatingProxyFencedBlock()
        {
            // Arrange
            int            dummyFenceCharCount = 3;
            const int      dummyLineIndex      = 6;
            const int      dummyIndent         = 2;
            const string   dummyText           = "dummyText";
            BlockProcessor dummyBlockProcessor = MarkdigTypesFactory.CreateBlockProcessor();

            dummyBlockProcessor.Line      = new StringSlice(dummyText);
            dummyBlockProcessor.Column    = dummyIndent;
            dummyBlockProcessor.LineIndex = dummyLineIndex;
            DummyProxyFencedBlock dummyProxyFencedBlock = _mockRepository.Create <DummyProxyFencedBlock>(null).Object;
            Mock <IFencedBlockFactory <Block, DummyProxyFencedBlock> > mockFencedBlockFactory = _mockRepository.Create <IFencedBlockFactory <Block, DummyProxyFencedBlock> >();
            var dummyException = new Exception();
            Mock <ExposedFencedBlockParser> mockTestSubject = CreateMockExposedFencedBlockParser(mockFencedBlockFactory.Object);

            mockFencedBlockFactory.
            Setup(f => f.CreateProxyFencedBlock(dummyIndent, dummyFenceCharCount, dummyBlockProcessor, mockTestSubject.Object)).
            Throws(dummyException);
            mockTestSubject.CallBase = true;
            mockTestSubject.Setup(t => t.LineContainsOpeningFence(It.Is <StringSlice>(s => s.Text == dummyText), out dummyFenceCharCount)).Returns(true);

            // Act and assert
            BlockException result = Assert.Throws <BlockException>(() => mockTestSubject.Object.ExposedTryOpenBlock(dummyBlockProcessor));

            Assert.Equal(string.Format(Strings.BlockException_BlockException_InvalidBlock, nameof(Block), dummyLineIndex + 1, dummyIndent,
                                       Strings.BlockException_Shared_ExceptionOccurredWhileCreatingBlock),
                         result.Message);
            Assert.Same(dummyException, result.InnerException);
            _mockRepository.VerifyAll();
        }
        public void CloseBlock_ReturnsTrueAndReplacesProxyIfThereIsAReplacement()
        {
            // Arrange
            BlockProcessor   dummyBlockProcessor = MarkdigTypesFactory.CreateBlockProcessor();
            Mock <LeafBlock> dummySiblingBlock1  = _mockRepository.Create <LeafBlock>(null);
            Mock <LeafBlock> dummySiblingBlock2  = _mockRepository.Create <LeafBlock>(null);
            var dummyProxyBlock = new DummyProxyBlock(null);
            Mock <ContainerBlock> dummyParentBlock = _mockRepository.Create <ContainerBlock>(null);

            dummyParentBlock.CallBase = true;
            dummyParentBlock.Object.Add(dummySiblingBlock1.Object); // So we can verify replacement position
            dummyParentBlock.Object.Add(dummyProxyBlock);
            dummyParentBlock.Object.Add(dummySiblingBlock2.Object); // So we can verify replacement position
            Mock <Block> dummyReplacementBlock = _mockRepository.Create <Block>(null);
            Mock <ExposedProxyBlockParser <Block, DummyProxyBlock> > testSubject = CreateMockExposedBlockParser();

            testSubject.CallBase = true;
            testSubject.Protected().Setup <Block>("CloseProxy", dummyBlockProcessor, dummyProxyBlock).Returns(dummyReplacementBlock.Object);

            // Act
            bool result = testSubject.Object.ExposedCloseBlock(dummyBlockProcessor, dummyProxyBlock);

            // Assert
            Assert.True(result);
            Assert.Equal(3, dummyParentBlock.Object.Count);
            Assert.Same(dummySiblingBlock1.Object, dummyParentBlock.Object[0]);
            Assert.Same(dummyReplacementBlock.Object, dummyParentBlock.Object[1]); // Replacement must be in position of proxy it replaced
            Assert.Same(dummySiblingBlock2.Object, dummyParentBlock.Object[2]);
        }
Exemple #6
0
        public void TryOpenBlock_IfSuccessfulCreatesNewProxyJsonBlockAndReturnsBlockStateContinue()
        {
            // Arrange
            const BlockState expectedResult    = BlockState.Continue;
            var            dummyLine           = new StringSlice("o{dummy");
            BlockProcessor dummyBlockProcessor = MarkdigTypesFactory.CreateBlockProcessor();

            dummyBlockProcessor.Line = dummyLine;
            var dummyProxyJsonBlock = new ProxyJsonBlock(null, null);
            Mock <IJsonBlockFactory <Block, ProxyJsonBlock> > mockJsonBlockFactory = _mockRepository.Create <IJsonBlockFactory <Block, ProxyJsonBlock> >();

            dummyLine.NextChar(); // TryOpenProxy advances line by 1 char (skips @) before calling ParseLine
            Mock <ExposedJsonBlockParser> mockTestSubject = CreateMockExposedJsonBlockParser(mockJsonBlockFactory.Object);

            mockTestSubject.CallBase = true;
            mockTestSubject.Setup(t => t.ParseLine(dummyLine, dummyProxyJsonBlock)).Returns(expectedResult);
            mockJsonBlockFactory.Setup(b => b.CreateProxyJsonBlock(dummyBlockProcessor, mockTestSubject.Object)).Returns(dummyProxyJsonBlock);

            // Act
            BlockState result = mockTestSubject.Object.ExposedTryOpenBlock(dummyBlockProcessor);

            // Assert
            _mockRepository.VerifyAll();
            Assert.Equal(expectedResult, result);
            Assert.Single(dummyBlockProcessor.NewBlocks);
            Assert.Same(dummyProxyJsonBlock, dummyBlockProcessor.NewBlocks.Peek());
        }
        public void CreateOptions_FromFlexiOptionsBlock_CreatesOptions()
        {
            // Arrange
            BlockProcessor                      dummyBlockProcessor        = MarkdigTypesFactory.CreateBlockProcessor();
            Mock <IDummyBlockOptions>           dummyDefaultBlockOptions   = _mockRepository.Create <IDummyBlockOptions>();
            Mock <IDummyBlockOptions>           dummyNewBlockOptions       = _mockRepository.Create <IDummyBlockOptions>();
            Mock <IDummyBlocksExtensionOptions> mockBlocksExtensionOptions = _mockRepository.Create <IDummyBlocksExtensionOptions>();

            mockBlocksExtensionOptions.Setup(f => f.DefaultBlockOptions).Returns(dummyDefaultBlockOptions.Object);
            Mock <IBlockOptionsFactory <IDummyBlockOptions> > mockBlockOptionsFactory = _mockRepository.Create <IBlockOptionsFactory <IDummyBlockOptions> >();

            mockBlockOptionsFactory.Setup(f => f.Create(dummyDefaultBlockOptions.Object, dummyBlockProcessor)).Returns(dummyNewBlockOptions.Object);
            Mock <IExtensionOptionsFactory <IDummyBlocksExtensionOptions, IDummyBlockOptions> > mockBlocksExtensionOptionsFactory =
                _mockRepository.Create <IExtensionOptionsFactory <IDummyBlocksExtensionOptions, IDummyBlockOptions> >();

            mockBlocksExtensionOptionsFactory.Setup(f => f.Create(dummyBlockProcessor)).Returns(mockBlocksExtensionOptions.Object);
            OptionsService <IDummyBlockOptions, IDummyBlocksExtensionOptions> testSubject = CreateOptionsService(mockBlockOptionsFactory.Object, mockBlocksExtensionOptionsFactory.Object);

            // Act
            (IDummyBlockOptions resultBlockOptions, IDummyBlocksExtensionOptions resultExtensionOptions) = testSubject.CreateOptions(dummyBlockProcessor);

            // Assert
            _mockRepository.VerifyAll();
            Assert.Same(dummyNewBlockOptions.Object, resultBlockOptions);
            Assert.Same(mockBlocksExtensionOptions.Object, resultExtensionOptions);
        }
        public void TryOpenBlock_ReturnsContinueDiscardAndAddsNewProxyFencedBlockToNewBlocksIfLineContainsAnOpeningFence()
        {
            // Arrange
            int            dummyFenceCharCount = 3;
            const int      dummyIndent         = 2;
            const string   dummyText           = "dummyText";
            BlockProcessor dummyBlockProcessor = MarkdigTypesFactory.CreateBlockProcessor();

            dummyBlockProcessor.Line   = new StringSlice(dummyText);
            dummyBlockProcessor.Column = dummyIndent;
            DummyProxyFencedBlock dummyProxyFencedBlock = _mockRepository.Create <DummyProxyFencedBlock>(null).Object;
            Mock <IFencedBlockFactory <Block, DummyProxyFencedBlock> > mockFencedBlockFactory = _mockRepository.Create <IFencedBlockFactory <Block, DummyProxyFencedBlock> >();
            Mock <ExposedFencedBlockParser> mockTestSubject = CreateMockExposedFencedBlockParser(mockFencedBlockFactory.Object);

            mockFencedBlockFactory.
            Setup(f => f.CreateProxyFencedBlock(dummyIndent, dummyFenceCharCount, dummyBlockProcessor, mockTestSubject.Object)).
            Returns(dummyProxyFencedBlock);
            mockTestSubject.CallBase = true;
            mockTestSubject.Setup(t => t.LineContainsOpeningFence(It.Is <StringSlice>(s => s.Text == dummyText), out dummyFenceCharCount)).Returns(true);

            // Act
            BlockState result = mockTestSubject.Object.ExposedTryOpenBlock(dummyBlockProcessor);

            // Assert
            _mockRepository.VerifyAll();
            Assert.Equal(BlockState.ContinueDiscard, result);
            Assert.Same(dummyProxyFencedBlock, dummyBlockProcessor.NewBlocks.Peek());
        }
        public void OnClosed_ThrowsArgumentNullExceptionIfBlockIsNull()
        {
            // Arrange
            ExposedBlockExtension testSubject = CreatedExposedBlockExtension();

            // Act and assert
            Assert.Throws <ArgumentNullException>(() => testSubject.ExposedOnClosed(MarkdigTypesFactory.CreateBlockProcessor(), null));
        }
        public void TryGetFlexiOptionsBlock_ReturnsNullIfAnFlexiOptionsBlockDoesNotExist()
        {
            // Arrange
            BlockProcessor dummyBlockProcessor = MarkdigTypesFactory.CreateBlockProcessor();
            BlockOptionsFactory <IDummyOptions> testSubject = CreateBlockOptionsFactory();

            // Act
            FlexiOptionsBlock result = testSubject.TryGetFlexiOptionsBlock(dummyBlockProcessor);

            // Assert
            Assert.Null(result);
        }
Exemple #11
0
        public void TryOpenBlock_ReturnsBlockStateNoneIfLineDoesNotBeginWithExpectedCharacters(string line)
        {
            // Arrange
            BlockProcessor dummyBlockProcessor = MarkdigTypesFactory.CreateBlockProcessor();

            dummyBlockProcessor.Line = new StringSlice(line);
            ExposedJsonBlockParser testSubject = CreateExposedJsonBlockParser();

            // Act
            BlockState result = testSubject.ExposedTryOpenBlock(dummyBlockProcessor);

            // Assert
            Assert.Equal(BlockState.None, result);
        }
        public void TryOpenBlock_ReturnsBlockStateNoneIfLineHasCodeIndent()
        {
            // Arrange
            BlockProcessor dummyBlockProcessor = MarkdigTypesFactory.CreateBlockProcessor();

            dummyBlockProcessor.Column = 4;                   // Code indent
            dummyBlockProcessor.Line   = new StringSlice(""); // To avoid null reference exception
            ExposedFencedBlockParser testSubject = CreateExposedFencedBlockParser();

            // Act
            BlockState result = testSubject.ExposedTryOpenBlock(dummyBlockProcessor);

            // Assert
            Assert.Equal(BlockState.None, result);
        }
Exemple #13
0
        public void CloseProxy_ThrowsJsonExceptionIfJsonIsIncomplete()
        {
            // Arrange
            const string dummyLines          = "dummyLines";
            var          dummyProxyJsonBlock = new ProxyJsonBlock(null, null);

            dummyProxyJsonBlock.Lines          = new StringLineGroup(dummyLines);
            dummyProxyJsonBlock.NumOpenObjects = 1;
            BlockProcessor         dummyBlockProcessor = MarkdigTypesFactory.CreateBlockProcessor();
            ExposedJsonBlockParser testSubject         = CreateExposedJsonBlockParser();

            // Act and assert
            JsonException result = Assert.Throws <JsonException>(() => testSubject.ExposedCloseProxy(dummyBlockProcessor, dummyProxyJsonBlock));

            Assert.Equal(string.Format(Strings.JsonException_Shared_InvalidJson, dummyLines), result.Message);
        }
        public void CloseBlock_ReturnsFalseIfThereIsNoReplacement()
        {
            // Arrange
            BlockProcessor dummyBlockProcessor = MarkdigTypesFactory.CreateBlockProcessor();
            var            dummyProxyBlock     = new DummyProxyBlock(null);
            Mock <ExposedProxyBlockParser <Block, DummyProxyBlock> > testSubject = CreateMockExposedBlockParser();

            testSubject.CallBase = true;
            testSubject.Protected().Setup <Block>("CloseProxy", dummyBlockProcessor, dummyProxyBlock).Returns((Block)null);

            // Act
            bool result = testSubject.Object.ExposedCloseBlock(dummyBlockProcessor, dummyProxyBlock);

            // Assert
            Assert.False(result);
        }
        public void TryGetFlexiOptionsBlock_IfSuccessfulReturnsFlexiOptionsBlockAndRemovesItFromDocumentData()
        {
            // Arrange
            var            dummyFlexiOptionsBlock = new FlexiOptionsBlock(null);
            BlockProcessor dummyBlockProcessor    = MarkdigTypesFactory.CreateBlockProcessor();

            dummyBlockProcessor.Document.SetData(FlexiOptionsBlockFactory.PENDING_FLEXI_OPTIONS_BLOCK, dummyFlexiOptionsBlock);
            BlockOptionsFactory <IDummyOptions> testSubject = CreateBlockOptionsFactory();

            // Act
            FlexiOptionsBlock result = testSubject.TryGetFlexiOptionsBlock(dummyBlockProcessor);

            // Assert
            Assert.Same(dummyFlexiOptionsBlock, result);
            Assert.Null(dummyBlockProcessor.Document.GetData(FlexiOptionsBlockFactory.PENDING_FLEXI_OPTIONS_BLOCK));
        }
        public void TryOpen_DoesNotInterfereWithBlockExceptionWithLineContextIfNoBlockIsCreated()
        {
            // Arrange
            BlockProcessor dummyBlockProcessor          = MarkdigTypesFactory.CreateBlockProcessor();
            var            dummyBlockException          = new BlockException(1, 0);
            Mock <BlockParser <Block> > mockTestSubject = CreateMockBlockParser <Block>();

            mockTestSubject.CallBase = true;
            mockTestSubject.Protected().Setup("TryOpenBlock", dummyBlockProcessor).Throws(dummyBlockException);

            // Act and assert
            BlockException result = Assert.Throws <BlockException>(() => mockTestSubject.Object.TryOpen(dummyBlockProcessor));

            _mockRepository.VerifyAll();
            Assert.Same(dummyBlockException, result);
            Assert.Null(result.InnerException);
        }
        public void Create_FromFlexiOptionsBlock_ReturnsDefaultBlockOptionsIfThereIsNoFlexiOptionsBlock()
        {
            // Arrange
            BlockProcessor       dummyBlockProcessor = MarkdigTypesFactory.CreateBlockProcessor();
            Mock <IDummyOptions> dummyOptions        = _mockRepository.Create <IDummyOptions>();
            Mock <BlockOptionsFactory <IDummyOptions> > mockTestSubject = CreateMockBlockOptionsFactory();

            mockTestSubject.CallBase = true;
            mockTestSubject.Setup(t => t.TryGetFlexiOptionsBlock(dummyBlockProcessor)).Returns((FlexiOptionsBlock)null);

            // Act
            IDummyOptions result = mockTestSubject.Object.Create(dummyOptions.Object, dummyBlockProcessor);

            // Assert
            Assert.Same(dummyOptions.Object, result);
            _mockRepository.VerifyAll();
        }
Exemple #18
0
        public void Create_ReturnsNewExtensionOptionsIfThereIsNoContextObjectForTheGivenKey()
        {
            // Arrange
            BlockProcessor dummyBlockProcessor = MarkdigTypesFactory.CreateBlockProcessor();
            object         dummyValue          = null;
            Mock <IContextObjectsService> mockContextObjectsService = _mockRepository.Create <IContextObjectsService>();

            mockContextObjectsService.Setup(c => c.TryGetContextObject(typeof(IDummyExtensionOptions), dummyBlockProcessor, out dummyValue)).Returns(false);
            ExtensionOptionsFactory <IDummyExtensionOptions, DummyExtensionOptions, IDummyBlockOptions> testSubject =
                CreateExtensionOptionsFactory(mockContextObjectsService.Object);

            // Act
            IDummyExtensionOptions result = testSubject.Create(dummyBlockProcessor);

            // Assert
            _mockRepository.VerifyAll();
            Assert.IsType <DummyExtensionOptions>(result);
        }
        public void Close_DoesNotInterfereWithBlockExceptionWithBlockContext()
        {
            // Arrange
            BlockProcessor dummyBlockProcessor          = MarkdigTypesFactory.CreateBlockProcessor();
            Mock <Block>   dummyBlock                   = _mockRepository.Create <Block>(null);
            var            dummyBlockException          = new BlockException(dummyBlock.Object); // So it has block context
            Mock <BlockParser <Block> > mockTestSubject = CreateMockBlockParser <Block>();

            mockTestSubject.CallBase = true;
            mockTestSubject.Protected().Setup("CloseBlock", dummyBlockProcessor, dummyBlock.Object).Throws(dummyBlockException);

            // Act and assert
            BlockException result = Assert.Throws <BlockException>(() => mockTestSubject.Object.Close(dummyBlockProcessor, dummyBlock.Object));

            _mockRepository.VerifyAll();
            Assert.Same(dummyBlockException, result);
            Assert.Null(result.InnerException);
        }
        public void OnClosed_DoesNotInterfereWithBlockExceptionsWithBlockContext()
        {
            // Arrange
            BlockProcessor dummyBlockProcessor           = MarkdigTypesFactory.CreateBlockProcessor();
            Mock <Block>   mockBlock                     = _mockRepository.Create <Block>(null);
            var            dummyBlockException           = new BlockException(mockBlock.Object);
            Mock <ExposedBlockExtension> mockTestSubject = CreateMockExposedBlockExtension();

            mockTestSubject.CallBase = true;
            mockTestSubject.Protected().Setup("OnBlockClosed", dummyBlockProcessor, mockBlock.Object).Throws(dummyBlockException);

            // Act and assert
            BlockException result = Assert.Throws <BlockException>(() => mockTestSubject.Object.ExposedOnClosed(dummyBlockProcessor, mockBlock.Object));

            _mockRepository.VerifyAll();
            Assert.Same(dummyBlockException, result);
            Assert.Null(result.InnerException);
        }
        public void CloseProxy_CreatesFencedBlock()
        {
            // Arrange
            Mock <DummyProxyFencedBlock> dummyProxyFencedBlock = _mockRepository.Create <DummyProxyFencedBlock>(null);
            BlockProcessor dummyBlockProcessor = MarkdigTypesFactory.CreateBlockProcessor();
            Mock <Block>   dummyBlock          = _mockRepository.Create <Block>(null);
            Mock <IFencedBlockFactory <Block, DummyProxyFencedBlock> > mockFencedBlockFactory = _mockRepository.Create <IFencedBlockFactory <Block, DummyProxyFencedBlock> >();

            mockFencedBlockFactory.Setup(f => f.Create(dummyProxyFencedBlock.Object, dummyBlockProcessor)).Returns(dummyBlock.Object);
            ExposedFencedBlockParser testSubject = CreateExposedFencedBlockParser(mockFencedBlockFactory.Object);

            // Act
            Block result = testSubject.ExposedCloseProxy(dummyBlockProcessor, dummyProxyFencedBlock.Object);

            // Assert
            _mockRepository.VerifyAll();
            Assert.Same(dummyBlock.Object, result);
        }
Exemple #22
0
        public void TryOpenBlock_ReturnsBlockStateNoneIfInCodeIndent()
        {
            // Arrange
            BlockProcessor dummyBlockProcessor = MarkdigTypesFactory.CreateBlockProcessor();

            // These three lines set IsCodeIndent to true
            dummyBlockProcessor.Column = 0;
            dummyBlockProcessor.RestartIndent();
            dummyBlockProcessor.Column = 4;
            ExposedJsonBlockParser testSubject = CreateExposedJsonBlockParser();

            // Act
            BlockState result = testSubject.ExposedTryOpenBlock(dummyBlockProcessor);

            // Assert
            Assert.True(dummyBlockProcessor.IsCodeIndent);
            Assert.Equal(BlockState.None, result);
        }
Exemple #23
0
        public void Create_ReturnsIExtensionOptionsFromContextObjectsIfItExists()
        {
            // Arrange
            BlockProcessor dummyBlockProcessor = MarkdigTypesFactory.CreateBlockProcessor();
            Mock <IContextObjectsService> mockContextObjectsService = _mockRepository.Create <IContextObjectsService>();
            Mock <IDummyExtensionOptions> dummyExtensionOptions     = _mockRepository.Create <IDummyExtensionOptions>();
            object dummyValue = dummyExtensionOptions.Object;

            mockContextObjectsService.Setup(c => c.TryGetContextObject(typeof(IDummyExtensionOptions), dummyBlockProcessor, out dummyValue)).Returns(true);
            ExtensionOptionsFactory <IDummyExtensionOptions, DummyExtensionOptions, IDummyBlockOptions> testSubject =
                CreateExtensionOptionsFactory(mockContextObjectsService.Object);

            // Act
            IDummyExtensionOptions result = testSubject.Create(dummyBlockProcessor);

            // Assert
            _mockRepository.VerifyAll();
            Assert.Same(dummyValue, result);
        }
        public void TryContinueBlock_ReturnsBlockStateContinueAndUpdatesLineStartIfLineHasCodeIndent()
        {
            // Arrange
            Mock <DummyProxyFencedBlock> dummyProxyFencedBlock = _mockRepository.Create <DummyProxyFencedBlock>(null);
            BlockProcessor dummyBlockProcessor = MarkdigTypesFactory.CreateBlockProcessor();

            dummyBlockProcessor.Column = 4; // Code indent
            Mock <ExposedFencedBlockParser> mockTestSubject = CreateMockExposedFencedBlockParser();

            mockTestSubject.CallBase = true;
            mockTestSubject.Setup(t => t.UpdateLineStart(dummyBlockProcessor, dummyProxyFencedBlock.Object));

            // Act
            BlockState result = mockTestSubject.Object.ExposedTryContinueBlock(dummyBlockProcessor, dummyProxyFencedBlock.Object);

            // Assert
            _mockRepository.VerifyAll();
            Assert.Equal(BlockState.Continue, result);
        }
        public void UpdateLineStart_UpdatesLineStart(string dummyLineText, int dummyOpeningFenceIndent, int dummyLineIndent, int expectedResult)
        {
            // Arrange
            var            dummyLine           = new StringSlice(dummyLineText);
            BlockProcessor dummyBlockProcessor = MarkdigTypesFactory.CreateBlockProcessor();

            dummyBlockProcessor.Line   = dummyLine;
            dummyBlockProcessor.Column = dummyLineIndent;
            Mock <DummyProxyFencedBlock> mockProxyFencedBlock = _mockRepository.Create <DummyProxyFencedBlock>(null);

            mockProxyFencedBlock.Setup(p => p.OpeningFenceIndent).Returns(dummyOpeningFenceIndent);
            ExposedFencedBlockParser testSubject = CreateExposedFencedBlockParser();

            // Act
            testSubject.UpdateLineStart(dummyBlockProcessor, mockProxyFencedBlock.Object);

            // Assert
            _mockRepository.VerifyAll();
            Assert.Equal(expectedResult, dummyBlockProcessor.Indent);
        }
Exemple #26
0
        public void CloseProxy_ReturnsJsonBlockIfSuccessful()
        {
            // Arrange
            BlockProcessor dummyBlockProcessor = MarkdigTypesFactory.CreateBlockProcessor();
            var            dummyProxyJsonBlock = new ProxyJsonBlock(null, null);

            dummyProxyJsonBlock.NumOpenObjects = 0;
            Mock <Block> dummyBlock = _mockRepository.Create <Block>(null);
            Mock <IJsonBlockFactory <Block, ProxyJsonBlock> > mockJsonBlockFactory = _mockRepository.Create <IJsonBlockFactory <Block, ProxyJsonBlock> >();

            mockJsonBlockFactory.Setup(j => j.Create(dummyProxyJsonBlock, dummyBlockProcessor)).Returns(dummyBlock.Object);
            ExposedJsonBlockParser testSubject = CreateExposedJsonBlockParser(mockJsonBlockFactory.Object);

            // Act
            Block result = testSubject.ExposedCloseProxy(dummyBlockProcessor, dummyProxyJsonBlock);

            // Assert
            _mockRepository.VerifyAll();
            Assert.Same(dummyBlock.Object, result);
        }
        public void Create_FromFlexiOptionsBlock_CreatesOptions()
        {
            // Arrange
            BlockProcessor       dummyBlockProcessor     = MarkdigTypesFactory.CreateBlockProcessor();
            Mock <IDummyOptions> dummyClonedDummyOptions = _mockRepository.Create <IDummyOptions>();
            Mock <IDummyOptions> dummyOptions            = _mockRepository.Create <IDummyOptions>();
            var dummyFlexiOptionsBlock = new FlexiOptionsBlock(null);
            Mock <BlockOptionsFactory <IDummyOptions> > mockTestSubject = CreateMockBlockOptionsFactory();

            mockTestSubject.CallBase = true;
            mockTestSubject.Setup(t => t.TryGetFlexiOptionsBlock(dummyBlockProcessor)).Returns(dummyFlexiOptionsBlock);
            mockTestSubject.Setup(t => t.Create(dummyOptions.Object, dummyFlexiOptionsBlock)).Returns(dummyClonedDummyOptions.Object);

            // Act
            IDummyOptions result = mockTestSubject.Object.Create(dummyOptions.Object, dummyBlockProcessor);

            // Assert
            _mockRepository.VerifyAll();
            Assert.Same(dummyClonedDummyOptions.Object, result);
        }
        public void TryOpenBlock_ReturnsBlockStateNoneIfLineDoesNotContainAnOpeningFence()
        {
            // Arrange
            const string   dummyText           = "dummyText";
            BlockProcessor dummyBlockProcessor = MarkdigTypesFactory.CreateBlockProcessor();

            dummyBlockProcessor.Line = new StringSlice(dummyText);
            Mock <ExposedFencedBlockParser> mockTestSubject = CreateMockExposedFencedBlockParser();

            mockTestSubject.CallBase = true;
            int dummyFenceCharCount;

            mockTestSubject.Setup(t => t.LineContainsOpeningFence(It.Is <StringSlice>(s => s.Text == dummyText), out dummyFenceCharCount)).Returns(false);

            // Act
            BlockState result = mockTestSubject.Object.ExposedTryOpenBlock(dummyBlockProcessor);

            // Assert
            _mockRepository.VerifyAll();
            Assert.Equal(BlockState.None, result);
        }
Exemple #29
0
        public void TryContinueBlock_AttemptsToContinueProxyBlock()
        {
            // Arrange
            const BlockState expectedResult    = BlockState.Continue;
            var            dummyLine           = new StringSlice("o{dummy");
            BlockProcessor dummyBlockProcessor = MarkdigTypesFactory.CreateBlockProcessor();

            dummyBlockProcessor.Line = dummyLine;
            var dummyProxyJsonBlock = new ProxyJsonBlock(null, null);
            Mock <ExposedJsonBlockParser> mockTestSubject = CreateMockExposedJsonBlockParser();

            mockTestSubject.CallBase = true;
            mockTestSubject.Setup(t => t.ParseLine(dummyLine, dummyProxyJsonBlock)).Returns(expectedResult);

            // Act
            BlockState result = mockTestSubject.Object.ExposedTryContinueBlock(dummyBlockProcessor, dummyProxyJsonBlock);

            // Assert
            _mockRepository.VerifyAll();
            Assert.Equal(expectedResult, result);
        }
        public void CreateProxyJsonBlock_CreatesProxyJsonBlock()
        {
            // Arrange
            const int      dummyColumn         = 4;
            const int      dummyLineStart      = 2;
            BlockProcessor dummyBlockProcessor = MarkdigTypesFactory.CreateBlockProcessor();

            dummyBlockProcessor.Column = dummyColumn;
            dummyBlockProcessor.Line   = new StringSlice("", dummyLineStart, 10);
            Mock <BlockParser>       dummyBlockParser = _mockRepository.Create <BlockParser>();
            ExposedMediaBlockFactory testSubject      = CreateExposedMediaBlockFactory();

            // Act
            ProxyJsonBlock result = testSubject.CreateProxyJsonBlock(dummyBlockProcessor, dummyBlockParser.Object);

            // Assert
            Assert.Equal(result.Column, dummyColumn);
            Assert.Equal(result.Span.Start, dummyLineStart);
            Assert.Equal(nameof(Block), result.MainTypeName);
            Assert.Same(dummyBlockParser.Object, result.Parser);
        }