public void Merge_ThrowsIfThePassedInChunkIsNotASetBaseTypeChunk()
        {
            // Arrange
            var expected = "Argument must be an instance of " +
                           "'Microsoft.AspNet.Razor.Chunks.SetBaseTypeChunk'.";
            var merger = new SetBaseTypeChunkMerger("dynamic");

            // Act and Assert
            ExceptionAssert.ThrowsArgument(() => merger.Merge(new ChunkTree(), new LiteralChunk()), "chunk", expected);
        }
        public void Merge_ThrowsIfThePassedInChunkIsNotASetBaseTypeChunk()
        {
            // Arrange
            var expected = "Argument must be an instance of " +
                           "'Microsoft.AspNet.Razor.Generator.Compiler.SetBaseTypeChunk'.";
            var merger = new SetBaseTypeChunkMerger("dynamic");

            // Act and Assert
            ExceptionAssert.ThrowsArgument(() => merger.Merge(new CodeTree(), new LiteralChunk()), "chunk", expected);
        }
        public void Merge_IgnoresSetBaseTypeChunksIfSetBaseTypeWasPreviouslyMerged()
        {
            // Arrange
            var merger   = new SetBaseTypeChunkMerger("dynamic");
            var codeTree = new CodeTree();

            // Act
            merger.Merge(codeTree, new SetBaseTypeChunk {
                TypeName = "MyBase1"
            });
            merger.Merge(codeTree, new SetBaseTypeChunk {
                TypeName = "MyBase2"
            });

            // Assert
            var chunk            = Assert.Single(codeTree.Chunks);
            var setBaseTypeChunk = Assert.IsType <SetBaseTypeChunk>(chunk);

            Assert.Equal("MyBase1", setBaseTypeChunk.TypeName);
        }
        public void Merge_IgnoresSetBaseTypeChunksIfChunkTreeContainsOne()
        {
            // Arrange
            var merger = new SetBaseTypeChunkMerger("dynamic");
            var chunkTree = new ChunkTree();

            // Act
            merger.VisitChunk(new SetBaseTypeChunk { TypeName = "MyBaseType1" });
            merger.Merge(chunkTree, new SetBaseTypeChunk { TypeName = "MyBaseType2" });

            // Assert
            Assert.Empty(chunkTree.Chunks);
        }
        public void Merge_SetsBaseTypeIfItHasNotBeenSetInChunkTree()
        {
            // Arrange
            var expected = "MyApp.Razor.MyBaseType";
            var merger = new SetBaseTypeChunkMerger("dynamic");
            var chunkTree = new ChunkTree();

            // Act
            merger.Merge(chunkTree, new SetBaseTypeChunk { TypeName = expected });

            // Assert
            var chunk = Assert.Single(chunkTree.Chunks);
            var setBaseTypeChunk = Assert.IsType<SetBaseTypeChunk>(chunk);
            Assert.Equal(expected, setBaseTypeChunk.TypeName);
        }
        public void Merge_IgnoresSetBaseTypeChunksIfCodeTreeContainsOne()
        {
            // Arrange
            var merger   = new SetBaseTypeChunkMerger("dynamic");
            var codeTree = new CodeTree();

            // Act
            merger.VisitChunk(new SetBaseTypeChunk {
                TypeName = "MyBaseType1"
            });
            merger.Merge(codeTree, new SetBaseTypeChunk {
                TypeName = "MyBaseType2"
            });

            // Assert
            Assert.Empty(codeTree.Chunks);
        }
        public void Merge_SetsBaseTypeIfItHasNotBeenSetInCodeTree()
        {
            // Arrange
            var expected = "MyApp.Razor.MyBaseType";
            var merger   = new SetBaseTypeChunkMerger("dynamic");
            var codeTree = new CodeTree();

            // Act
            merger.Merge(codeTree, new SetBaseTypeChunk {
                TypeName = expected
            });

            // Assert
            var chunk            = Assert.Single(codeTree.Chunks);
            var setBaseTypeChunk = Assert.IsType <SetBaseTypeChunk>(chunk);

            Assert.Equal(expected, setBaseTypeChunk.TypeName);
        }
        public void Merge_IgnoresSetBaseTypeChunksIfSetBaseTypeWasPreviouslyMerged()
        {
            // Arrange
            var merger = new SetBaseTypeChunkMerger("dynamic");
            var chunkTree = new ChunkTree();

            // Act
            merger.Merge(chunkTree, new SetBaseTypeChunk { TypeName = "MyBase1" });
            merger.Merge(chunkTree, new SetBaseTypeChunk { TypeName = "MyBase2" });

            // Assert
            var chunk = Assert.Single(chunkTree.Chunks);
            var setBaseTypeChunk = Assert.IsType<SetBaseTypeChunk>(chunk);
            Assert.Equal("MyBase1", setBaseTypeChunk.TypeName);
        }