Beispiel #1
0
        public void GetInheritedChunks_ReturnsDefaultInheritedChunks()
        {
            // Arrange
            var fileSystem = new TestFileSystem();

            fileSystem.AddFile(@"x:\myapproot\views\_viewstart.cshtml",
                               "@inject DifferentHelper<TModel> Html");
            var host          = new MvcRazorHost(fileSystem);
            var defaultChunks = new Chunk[]
            {
                new InjectChunk("MyTestHtmlHelper", "Html"),
                new UsingChunk {
                    Namespace = "AppNamespace.Model"
                },
            };
            var utility = new ChunkInheritanceUtility(host, fileSystem, defaultChunks);

            // Act
            var chunks = utility.GetInheritedChunks(@"x:\myapproot\views\home\Index.cshtml");

            // Assert
            Assert.Equal(4, chunks.Count);
            var injectChunk = Assert.IsType <InjectChunk>(chunks[1]);

            Assert.Equal("DifferentHelper<TModel>", injectChunk.TypeName);
            Assert.Equal("Html", injectChunk.MemberName);

            Assert.Same(defaultChunks[0], chunks[2]);
            Assert.Same(defaultChunks[1], chunks[3]);
        }
Beispiel #2
0
        public void GetInheritedChunks_ReturnsEmptySequenceIfNoViewStartsArePresent()
        {
            // Arrange
            var fileSystem = new TestFileSystem();

            fileSystem.AddFile(@"x:\myapproot\_viewstart.cs", string.Empty);
            fileSystem.AddFile(@"x:\myapproot\views\_Layout.cshtml", string.Empty);
            fileSystem.AddFile(@"x:\myapproot\views\home\_not-viewstart.cshtml", string.Empty);
            var host    = new MvcRazorHost(fileSystem);
            var utility = new ChunkInheritanceUtility(host, fileSystem, new Chunk[0]);

            // Act
            var chunks = utility.GetInheritedChunks(@"x:\myapproot\views\home\Index.cshtml");

            // Assert
            Assert.Empty(chunks);
        }
Beispiel #3
0
        public void GetInheritedChunks_ReadsChunksFromViewStartsInPath()
        {
            // Arrange
            var fileSystem = new TestFileSystem();

            fileSystem.AddFile(@"x:\myapproot\views\accounts\_viewstart.cshtml", "@using AccountModels");
            fileSystem.AddFile(@"x:\myapproot\views\Shared\_viewstart.cshtml", "@inject SharedHelper Shared");
            fileSystem.AddFile(@"x:\myapproot\views\home\_viewstart.cshtml", "@using MyNamespace");
            fileSystem.AddFile(@"x:\myapproot\views\_viewstart.cshtml",
                               @"@inject MyHelper<TModel> Helper
@inherits MyBaseType

@{
    Layout = ""test.cshtml"";
}

");
            var host    = new MvcRazorHost(fileSystem);
            var utility = new ChunkInheritanceUtility(host, fileSystem, new Chunk[0]);

            // Act
            var chunks = utility.GetInheritedChunks(@"x:\myapproot\views\home\Index.cshtml");

            // Assert
            Assert.Equal(8, chunks.Count);
            Assert.IsType <LiteralChunk>(chunks[0]);

            var usingChunk = Assert.IsType <UsingChunk>(chunks[1]);

            Assert.Equal("MyNamespace", usingChunk.Namespace);

            Assert.IsType <LiteralChunk>(chunks[2]);
            Assert.IsType <LiteralChunk>(chunks[3]);

            var injectChunk = Assert.IsType <InjectChunk>(chunks[4]);

            Assert.Equal("MyHelper<TModel>", injectChunk.TypeName);
            Assert.Equal("Helper", injectChunk.MemberName);

            var setBaseTypeChunk = Assert.IsType <SetBaseTypeChunk>(chunks[5]);

            Assert.Equal("MyBaseType", setBaseTypeChunk.TypeName);

            Assert.IsType <StatementChunk>(chunks[6]);
            Assert.IsType <LiteralChunk>(chunks[7]);
        }