示例#1
0
        public void WriteUsingDirective_WithSource_WritesContentWithLinePragma()
        {
            // Arrange
            var codeWriter = new CodeWriter();
            var writer     = new RuntimeNodeWriter();
            var context    = TestCodeRenderingContext.CreateRuntime();

            var node = new UsingDirectiveIntermediateNode()
            {
                Content = "System",
                Source  = new SourceSpan("test.cshtml", 0, 0, 0, 3),
            };

            // Act
            writer.WriteUsingDirective(context, node);

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

            Assert.Equal(
                @"
#nullable restore
#line 1 ""test.cshtml""
using System;

#line default
#line hidden
#nullable disable
",
                csharp,
                ignoreLineEndingDifferences: true);
        }
示例#2
0
        public void WriteUsingDirective_NoSource_WritesContent()
        {
            // Arrange
            var codeWriter = new CodeWriter();
            var writer     = new RuntimeNodeWriter();
            var context    = TestCodeRenderingContext.CreateRuntime();

            var node = new UsingDirectiveIntermediateNode()
            {
                Content = "System",
            };

            // Act
            writer.WriteUsingDirective(context, node);

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

            Assert.Equal(
                @"using System;
",
                csharp,
                ignoreLineEndingDifferences: true);
        }