예제 #1
0
        public void Pass_SetsNamespaceAndClassName_ComputedFromSource_ForView()
        {
            // Arrange
            var document = new DocumentIntermediateNode();
            var builder  = IntermediateNodeBuilder.Create(document);

            // This will be ignored.
            builder.Push(new DirectiveIntermediateNode()
            {
                Directive = NamespaceDirective.Directive,
                Source    = new SourceSpan("/Account/_ViewImports.cshtml", 0, 0, 0, 0),
            });
            builder.Add(new DirectiveTokenIntermediateNode()
            {
                Content = "ignored"
            });
            builder.Pop();

            // This will be used.
            builder.Push(new DirectiveIntermediateNode()
            {
                Directive = NamespaceDirective.Directive,
                Source    = new SourceSpan("/Account/Manage/AddUser.cshtml", 0, 0, 0, 0),
            });
            builder.Add(new DirectiveTokenIntermediateNode()
            {
                Content = "WebApplication.Account.Manage"
            });
            builder.Pop();

            var @namespace = new NamespaceDeclarationIntermediateNode()
            {
                Content = "default"
            };

            builder.Push(@namespace);

            var @class = new ClassDeclarationIntermediateNode()
            {
                ClassName = "default"
            };

            builder.Add(@class);

            document.DocumentKind = MvcViewDocumentClassifierPass.MvcViewDocumentKind;

            var codeDocument = RazorCodeDocument.Create(RazorSourceDocument.Create("ignored", "/Account/Manage/AddUser.cshtml"));

            var pass = new NamespaceDirective.Pass();

            pass.Engine = RazorEngine.CreateEmpty(b => { });

            // Act
            pass.Execute(codeDocument, document);

            // Assert
            Assert.Equal("WebApplication.Account.Manage", @namespace.Content);
            Assert.Equal("AddUser_View", @class.ClassName);
        }
예제 #2
0
        public void Pass_DoesNothing_ForUnknownDocumentKind()
        {
            // Arrange
            var document = new DocumentIntermediateNode();
            var builder  = IntermediateNodeBuilder.Create(document);

            builder.Push(new DirectiveIntermediateNode()
            {
                Directive = NamespaceDirective.Directive,
                Source    = new SourceSpan(null, 0, 0, 0, 0),
            });
            builder.Add(new DirectiveTokenIntermediateNode()
            {
                Content = "WebApplication.Account"
            });
            builder.Pop();

            var @namespace = new NamespaceDeclarationIntermediateNode()
            {
                Content = "default"
            };

            builder.Push(@namespace);

            var @class = new ClassDeclarationIntermediateNode()
            {
                ClassName = "default"
            };

            builder.Add(@class);

            document.DocumentKind = null;

            var codeDocument = RazorCodeDocument.Create(RazorSourceDocument.Create("ignored", "/Account/Manage/AddUser.cshtml"));

            var pass = new NamespaceDirective.Pass();

            pass.Engine = RazorEngine.CreateEmpty(b => { });

            // Act
            pass.Execute(codeDocument, document);

            // Assert
            Assert.Equal("default", @namespace.Content);
            Assert.Equal("default", @class.ClassName);
        }
예제 #3
0
        public void Pass_SetsNamespace_VerbatimFromImports()
        {
            // Arrange
            var document = new DocumentIntermediateNode();
            var builder  = IntermediateNodeBuilder.Create(document);

            builder.Push(new DirectiveIntermediateNode()
            {
                Directive = NamespaceDirective.Directive,
                Source    = new SourceSpan(null, 0, 0, 0, 0),
            });
            builder.Add(new DirectiveTokenIntermediateNode()
            {
                Content = "WebApplication.Account"
            });
            builder.Pop();

            var @namespace = new NamespaceDeclarationIntermediateNode()
            {
                Content = "default"
            };

            builder.Push(@namespace);

            var @class = new ClassDeclarationIntermediateNode()
            {
                ClassName = "default"
            };

            builder.Add(@class);

            document.DocumentKind = RazorPageDocumentClassifierPass.RazorPageDocumentKind;

            var codeDocument = RazorCodeDocument.Create(RazorSourceDocument.Create("ignored", "/Account/Manage/AddUser.cshtml"));

            var pass = new NamespaceDirective.Pass();

            pass.Engine = Mock.Of <RazorEngine>();

            // Act
            pass.Execute(codeDocument, document);

            // Assert
            Assert.Equal("WebApplication.Account", @namespace.Content);
            Assert.Equal("default", @class.ClassName);
        }