public void TryOpen_ReturnsBlockStateNone()
        {
            // Arrange
            ContextObjectsStore testSubject = CreateContextObjectsStore();

            // Act
            BlockState result = testSubject.TryOpen(null);

            // Assert
            Assert.Equal(BlockState.None, result);
        }
Exemplo n.º 2
0
        public void TryGetContextObjectsStore_ReturnsNullIfNoGlobalParserIsAContextObjectsStore()
        {
            // Arrange
            BlockProcessor        dummyBlockProcessor = MarkdigTypesFactory.CreateBlockProcessor(); // Several global parsers registered by default
            ContextObjectsService testSubject         = CreateContextObjectsService();

            // Act
            ContextObjectsStore result = testSubject.TryGetContextObjectsStore(dummyBlockProcessor);

            // Assert
            Assert.Null(result);
        }
Exemplo n.º 3
0
        public void TryGetContextObjectsStore_ReturnsNullIfThereAreNoGlobalParsers()
        {
            // Arrange
            BlockProcessor        dummyBlockProcessor = MarkdigTypesFactory.CreateBlockProcessor(blockParsers: new BlockParserList(new BlockParser[0]));
            ContextObjectsService testSubject         = CreateContextObjectsService();

            // Act
            ContextObjectsStore result = testSubject.TryGetContextObjectsStore(dummyBlockProcessor);

            // Assert
            Assert.Null(result);
        }
Exemplo n.º 4
0
        public void Setup_InsertsContextObjectsStoreIntoBlockParsersIfItDoesNotContainAContextObjectsStore()
        {
            // Arrange
            var dummyContextObjectsStore        = new ContextObjectsStore();
            ContextObjectsExtension testSubject = CreateContextObjectsExtension(dummyContextObjectsStore);
            var dummyMarkdownPipelineBuilder    = new MarkdownPipelineBuilder();

            // Act
            testSubject.Setup(dummyMarkdownPipelineBuilder);

            // Assert
            Assert.Contains(dummyContextObjectsStore, dummyMarkdownPipelineBuilder.BlockParsers);
        }
Exemplo n.º 5
0
        public void TryGetContextObjectsStore_ReturnsContextObjectsStoreIfItExists()
        {
            // Arrange
            var                   dummyContextObjectsStore = new ContextObjectsStore();
            BlockProcessor        dummyBlockProcessor      = MarkdigTypesFactory.CreateBlockProcessor(blockParsers: new BlockParserList(new BlockParser[] { dummyContextObjectsStore }));
            ContextObjectsService testSubject = CreateContextObjectsService();

            // Act
            ContextObjectsStore result = testSubject.TryGetContextObjectsStore(dummyBlockProcessor);

            // Assert
            _mockRepository.VerifyAll();
            Assert.Same(dummyContextObjectsStore, result);
        }
Exemplo n.º 6
0
        public void TryGetFromContextObjectsStore_ReturnsFalseAndNullIfTheContextObjectsStoreDoesNotContainAContextObjectWithTheSpecifiedKey()
        {
            // Arrange
            BlockProcessor dummyBlockProcessor           = MarkdigTypesFactory.CreateBlockProcessor();
            var            dummyContextObjectsStore      = new ContextObjectsStore();
            Mock <ContextObjectsService> mockTestSubject = CreateMockContextObjectsService();

            mockTestSubject.CallBase = true;
            mockTestSubject.Setup(t => t.TryGetContextObjectsStore(dummyBlockProcessor)).Returns(dummyContextObjectsStore);

            // Act
            bool result = mockTestSubject.Object.TryGetFromContextObjectsStore("dummyKey", dummyBlockProcessor, out object resultValue);

            // Assert
            _mockRepository.VerifyAll();
            Assert.False(result);
            Assert.Null(resultValue);
        }
Exemplo n.º 7
0
        public void Setup_DoesNothingIfBlockParsersContainsAContextObjectsStore()
        {
            // Arrange
            var dummyContextObjectsStore        = new ContextObjectsStore();
            ContextObjectsExtension testSubject = CreateContextObjectsExtension(dummyContextObjectsStore);
            var dummyMarkdownPipelineBuilder    = new MarkdownPipelineBuilder();

            dummyMarkdownPipelineBuilder.BlockParsers.Add(new ContextObjectsStore());

            // Act
            testSubject.Setup(dummyMarkdownPipelineBuilder);

            // Assert
            // Can't use Assert.DoesNotContain here:
            // Because ContextObjectsStore implements IDictionary<object, object>, Xunit compares the ContextObjectsStore instances as dictionaries:
            // - https://github.com/xunit/assert.xunit/blob/92395f59e3ff47d6d5a1edeced9e99ccfef9fd37/Sdk/AssertEqualityComparer.cs#L84
            // They're found to be "equal" because they have the same contents. What we want to check is whether the same reference exists in the collection.
            Assert.NotSame(dummyContextObjectsStore, dummyMarkdownPipelineBuilder.BlockParsers.Find <ContextObjectsStore>());
        }
Exemplo n.º 8
0
        public void TryAddContextObject_ReturnsTrueAndAddsContextObjectToContextObjectsStoreIfItsNotNullAndMarkdownParserContextIsNull()
        {
            // Arrange
            var            dummyKey                      = new object();
            var            dummyValue                    = new object();
            BlockProcessor dummyBlockProcessor           = MarkdigTypesFactory.CreateBlockProcessor();
            var            dummyContextObjectsStore      = new ContextObjectsStore();
            Mock <ContextObjectsService> mockTestSubject = CreateMockContextObjectsService();

            mockTestSubject.CallBase = true;
            mockTestSubject.Setup(t => t.TryGetContextObjectsStore(dummyBlockProcessor)).Returns(dummyContextObjectsStore);

            // Act
            bool result = mockTestSubject.Object.TryAddContextObject(dummyKey, dummyValue, dummyBlockProcessor);

            // Assert
            _mockRepository.VerifyAll();
            Assert.True(result);
            Assert.Single(dummyContextObjectsStore);
            Assert.Same(dummyValue, dummyContextObjectsStore[dummyKey]);
        }
Exemplo n.º 9
0
        public void TryGetFromContextObjectsStore_ReturnsTrueAndTheContextObjectIfItExists()
        {
            // Arrange
            var            dummyKey                 = new object();
            var            dummyValue               = new object();
            BlockProcessor dummyBlockProcessor      = MarkdigTypesFactory.CreateBlockProcessor();
            var            dummyContextObjectsStore = new ContextObjectsStore();

            dummyContextObjectsStore.Add(dummyKey, dummyValue);
            Mock <ContextObjectsService> mockTestSubject = CreateMockContextObjectsService();

            mockTestSubject.CallBase = true;
            mockTestSubject.Setup(t => t.TryGetContextObjectsStore(dummyBlockProcessor)).Returns(dummyContextObjectsStore);

            // Act
            bool result = mockTestSubject.Object.TryGetFromContextObjectsStore(dummyKey, dummyBlockProcessor, out object resultValue);

            // Assert
            _mockRepository.VerifyAll();
            Assert.True(result);
            Assert.Same(dummyValue, resultValue);
        }
Exemplo n.º 10
0
 private ContextObjectsExtension CreateContextObjectsExtension(ContextObjectsStore contextObjectsStore = null)
 {
     return(new ContextObjectsExtension(contextObjectsStore));
 }