public void WriteDesignTimeDirective_ChildrenWithNoSource_WritesEmptyMethod_WithPragma()
        {
            // Arrange
            var extension = new DesignTimeDirectiveTargetExtension();
            var context   = TestCodeRenderingContext.CreateDesignTime();

            var node  = new DesignTimeDirectiveIntermediateNode();
            var token = new DirectiveTokenIntermediateNode()
            {
                Content        = "Value",
                DirectiveToken = DirectiveTokenDescriptor.CreateToken(DirectiveTokenKind.String),
            };

            node.Children.Add(token);

            // Act
            extension.WriteDesignTimeDirective(context, node);

            // Assert
            var csharp = context.CodeWriter.GenerateCode();

            Assert.Equal(
                @"#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
}
#pragma warning restore 219
",
                csharp,
                ignoreLineEndingDifferences: true);
        }
        public void WriteDesignTimeDirective_WithNamespaceToken_WritesLambda()
        {
            // Arrange
            var extension = new DesignTimeDirectiveTargetExtension();
            var context   = TestCodeRenderingContext.CreateDesignTime();

            var node  = new DesignTimeDirectiveIntermediateNode();
            var token = new DirectiveTokenIntermediateNode()
            {
                Source         = new SourceSpan("test.cshtml", 0, 0, 0, 5),
                Content        = "System.Collections.Generic",
                DirectiveToken = DirectiveTokenDescriptor.CreateToken(DirectiveTokenKind.Namespace),
            };

            node.Children.Add(token);

            // Act
            extension.WriteDesignTimeDirective(context, node);

            // Assert
            var csharp = context.CodeWriter.GenerateCode();

            Assert.Equal(
                @"#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
((System.Action)(() => {
global::System.Object __typeHelper = nameof(System.Collections.Generic);
}
))();
}
#pragma warning restore 219
",
                csharp,
                ignoreLineEndingDifferences: true);
        }
Esempio n. 3
0
        public void WriteDesignTimeDirective_WithStringToken_WritesLambda()
        {
            // Arrange
            var extension = new DesignTimeDirectiveTargetExtension();
            var context   = TestCodeRenderingContext.CreateDesignTime();

            var node  = new DesignTimeDirectiveIntermediateNode();
            var token = new DirectiveTokenIntermediateNode()
            {
                Source         = new SourceSpan("test.cshtml", 0, 0, 0, 5),
                Content        = "Value",
                DirectiveToken = DirectiveTokenDescriptor.CreateToken(DirectiveTokenKind.String),
            };
            var tokenWithQuotedContent = new DirectiveTokenIntermediateNode()
            {
                Source         = new SourceSpan("test.cshtml", 0, 0, 0, 5),
                Content        = "\"Value\"",
                DirectiveToken = DirectiveTokenDescriptor.CreateToken(DirectiveTokenKind.String),
            };

            node.Children.Add(token);
            node.Children.Add(tokenWithQuotedContent);

            // Act
            extension.WriteDesignTimeDirective(context, node);

            // Assert
            var csharp = context.CodeWriter.GenerateCode();

            Assert.Equal(
                @"#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
((System.Action)(() => {
#nullable restore
#line 1 ""test.cshtml""
global::System.Object __typeHelper = ""Value"";

#line default
#line hidden
#nullable disable
}
))();
((System.Action)(() => {
#nullable restore
#line 1 ""test.cshtml""
global::System.Object __typeHelper = ""Value"";

#line default
#line hidden
#nullable disable
}
))();
}
#pragma warning restore 219
",
                csharp,
                ignoreLineEndingDifferences: true);
        }
        public void WriteDesignTimeDirective_NoChildren_WritesEmptyMethod_WithPragma()
        {
            // Arrange
            var extension = new DesignTimeDirectiveTargetExtension();
            var context   = TestCodeRenderingContext.CreateDesignTime();

            var node = new DesignTimeDirectiveIntermediateNode();

            // Act
            extension.WriteDesignTimeDirective(context, node);

            // Assert
            var csharp = context.CodeWriter.GenerateCode();

            Assert.Equal(
                @"#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
}
#pragma warning restore 219
",
                csharp,
                ignoreLineEndingDifferences: true);
        }