public void Visit_GeneratesProperties_ForInjectChunks()
        {
            // Arrange
            var expected =
@"[ActivateAttribute]
public MyType1 MyPropertyName1 { get; private set; }
[ActivateAttribute]
public MyType2 @MyPropertyName2 { get; private set; }
";
            var writer = new CSharpCodeWriter();
            var context = CreateContext();

            var visitor = new InjectChunkVisitor(writer, context, "ActivateAttribute");
            var factory = SpanFactory.CreateCsHtml();
            var node = (Span)factory.Code("Some code")
                                    .As(new InjectParameterGenerator("MyType", "MyPropertyName"));

            // Act
            visitor.Accept(new Chunk[]
            {
                new LiteralChunk(),
                new InjectChunk("MyType1", "MyPropertyName1") { Association = node },
                new InjectChunk("MyType2", "@MyPropertyName2") { Association = node }
            });
            var code = writer.GenerateCode();

            // Assert
            Assert.Equal(expected, code);
        }
Example #2
0
        public void Visit_GeneratesProperties_ForInjectChunks()
        {
            // Arrange
            var expected =
                @"[ActivateAttribute]
public MyType1 MyPropertyName1 { get; private set; }
[ActivateAttribute]
public MyType2 @MyPropertyName2 { get; private set; }
";
            var writer  = new CSharpCodeWriter();
            var context = CreateContext();

            var visitor = new InjectChunkVisitor(writer, context, "ActivateAttribute");
            var factory = SpanFactory.CreateCsHtml();
            var node    = (Span)factory.Code("Some code")
                          .As(new InjectParameterGenerator("MyType", "MyPropertyName"));

            // Act
            visitor.Accept(new Chunk[]
            {
                new LiteralChunk(),
                new InjectChunk("MyType1", "MyPropertyName1")
                {
                    Association = node
                },
                new InjectChunk("MyType2", "@MyPropertyName2")
                {
                    Association = node
                }
            });
            var code = writer.GenerateCode();

            // Assert
            Assert.Equal(expected, code);
        }
        protected override void BuildConstructor([NotNull] CSharpCodeWriter writer)
        {
            base.BuildConstructor(writer);

            writer.WriteLineHiddenDirective();

            var injectVisitor = new InjectChunkVisitor(writer, Context, _injectAttribute);
            injectVisitor.Accept(Context.ChunkTreeBuilder.ChunkTree.Chunks);

            writer.WriteLine();
            writer.WriteLineHiddenDirective();
        }
        protected override void BuildConstructor([NotNull] CSharpCodeWriter writer)
        {
            base.BuildConstructor(writer);

            writer.WriteLineHiddenDirective();

            var injectVisitor = new InjectChunkVisitor(writer, Context, _injectAttribute);

            injectVisitor.Accept(Context.ChunkTreeBuilder.ChunkTree.Chunks);

            writer.WriteLine();
            writer.WriteLineHiddenDirective();
        }
Example #5
0
        public void Visit_WithDesignTimeHost_GeneratesPropertiesAndLinePragmas_ForInjectChunks()
        {
            // Arrange
            var expected = string.Join(Environment.NewLine,
                                       @"[Microsoft.AspNet.Mvc.ActivateAttribute]",
                                       @"public",
                                       @"#line 1 """"",
                                       @"MyType1 MyPropertyName1",
                                       "",
                                       @"#line default",
                                       @"#line hidden",
                                       @"{ get; private set; }",
                                       @"[Microsoft.AspNet.Mvc.ActivateAttribute]",
                                       @"public",
                                       @"#line 1 """"",
                                       @"MyType2 @MyPropertyName2",
                                       "",
                                       @"#line default",
                                       @"#line hidden",
                                       @"{ get; private set; }",
                                       "");
            var writer  = new CSharpCodeWriter();
            var context = CreateContext();

            context.Host.DesignTimeMode = true;

            var visitor = new InjectChunkVisitor(writer, context, "Microsoft.AspNet.Mvc.ActivateAttribute");
            var factory = SpanFactory.CreateCsHtml();
            var node    = (Span)factory.Code("Some code")
                          .As(new InjectParameterGenerator("MyType", "MyPropertyName"));

            // Act
            visitor.Accept(new Chunk[]
            {
                new LiteralChunk(),
                new InjectChunk("MyType1", "MyPropertyName1")
                {
                    Association = node
                },
                new InjectChunk("MyType2", "@MyPropertyName2")
                {
                    Association = node
                }
            });
            var code = writer.GenerateCode();

            // Assert
            Assert.Equal(expected, code);
        }
Example #6
0
        protected override void BuildConstructor([NotNull] CSharpCodeWriter writer)
        {
            // TODO: Move this to a proper extension point. Right now, we don't have a place to print out properties
            // in the generated view.
            // Tracked by #773
            base.BuildConstructor(writer);

            writer.WriteLineHiddenDirective();

            var injectVisitor = new InjectChunkVisitor(writer, Context, _hostOptions.ActivateAttributeName);
            injectVisitor.Accept(Context.CodeTreeBuilder.CodeTree.Chunks);

            writer.WriteLine();
            writer.WriteLineHiddenDirective();
        }
Example #7
0
        protected override void BuildConstructor([NotNull] CSharpCodeWriter writer)
        {
            // TODO: Move this to a proper extension point. Right now, we don't have a place to print out properties
            // in the generated view.
            // Tracked by #773
            base.BuildConstructor(writer);

            writer.WriteLineHiddenDirective();

            var injectVisitor = new InjectChunkVisitor(writer, Context, _activateAttribute);

            injectVisitor.Accept(Context.CodeTreeBuilder.CodeTree.Chunks);

            writer.WriteLine();
            writer.WriteLineHiddenDirective();
        }
Example #8
0
        protected override void BuildConstructor(CSharpCodeWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            base.BuildConstructor(writer);

            writer.WriteLineHiddenDirective();

            var injectVisitor = new InjectChunkVisitor(writer, Context, _injectAttribute);

            injectVisitor.Accept(Context.ChunkTreeBuilder.ChunkTree.Chunks);

            writer.WriteLine();
            writer.WriteLineHiddenDirective();
        }
Example #9
0
        public void Visit_IgnoresNonInjectChunks()
        {
            // Arrange
            var writer  = new CSharpCodeWriter();
            var context = CreateContext();

            var visitor = new InjectChunkVisitor(writer, context, "ActivateAttribute");

            // Act
            visitor.Accept(new Chunk[]
            {
                new LiteralChunk(),
                new CodeAttributeChunk()
            });
            var code = writer.GenerateCode();

            // Assert
            Assert.Empty(code);
        }
        public void Visit_IgnoresNonInjectChunks()
        {
            // Arrange
            var writer = new CSharpCodeWriter();
            var context = CreateContext();

            var visitor = new InjectChunkVisitor(writer, context, "ActivateAttribute");

            // Act
            visitor.Accept(new Chunk[]
            {
                new LiteralChunk(),
                new CodeAttributeChunk()
            });
            var code = writer.GenerateCode();

            // Assert
            Assert.Empty(code);
        }
Example #11
0
        public void Visit_WithDesignTimeHost_GeneratesPropertiesAndLinePragmas_ForPartialInjectChunks()
        {
            // Arrange
            var expected = @"[Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute]
public
#line 1 """"
MyType1

#line default
#line hidden
{ get; private set; }
";
            var writer   = new CSharpCodeWriter();
            var context  = CreateContext();

            context.Host.DesignTimeMode = true;

            var visitor = new InjectChunkVisitor(writer, context, "Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute");
            var factory = SpanFactory.CreateCsHtml();
            var node    = (Span)factory.Code("Some code")
                          .As(new InjectParameterGenerator("MyType", "MyPropertyName"));

            // Act
            visitor.Accept(new Chunk[]
            {
                new LiteralChunk(),
                new InjectChunk("MyType1", string.Empty)
                {
                    Association = node
                },
            });
            var code = writer.GenerateCode();

            // Assert
            Assert.Equal(expected, code);
        }
        protected override void BuildConstructor(CSharpCodeWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            base.BuildConstructor(writer);

            writer.WriteLineHiddenDirective();

            var injectVisitor = new InjectChunkVisitor(writer, Context, _injectAttribute);
            injectVisitor.Accept(Context.ChunkTreeBuilder.Root.Children);

            writer.WriteLine();
            writer.WriteLineHiddenDirective();
        }
        public void Visit_WithDesignTimeHost_GeneratesPropertiesAndLinePragmas_ForInjectChunks()
        {
            // Arrange
            var expected = string.Join(Environment.NewLine,
@"[Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute]",
@"public",
@"#line 1 """"",
@"MyType1 MyPropertyName1",
"",
@"#line default",
@"#line hidden",
@"{ get; private set; }",
@"[Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute]",
@"public",
@"#line 1 """"",
@"MyType2 @MyPropertyName2",
"",
@"#line default",
@"#line hidden",
@"{ get; private set; }",
"");
            var writer = new CSharpCodeWriter();
            var context = CreateContext();
            context.Host.DesignTimeMode = true;

            var visitor = new InjectChunkVisitor(writer, context, "Microsoft.AspNet.Mvc.Razor.Internal.RazorInjectAttribute");
            var factory = SpanFactory.CreateCsHtml();
            var node = (Span)factory.Code("Some code")
                                    .As(new InjectParameterGenerator("MyType", "MyPropertyName"));

            // Act
            visitor.Accept(new Chunk[]
            {
                new LiteralChunk(),
                new InjectChunk("MyType1", "MyPropertyName1") { Association = node },
                new InjectChunk("MyType2", "@MyPropertyName2") { Association = node }
            });
            var code = writer.GenerateCode();

            // Assert
            Assert.Equal(expected, code);
        }
        public void Visit_WithDesignTimeHost_GeneratesPropertiesAndLinePragmas_ForPartialInjectChunks()
        {
            // Arrange
            var expected = @"[Microsoft.AspNet.Mvc.ActivateAttribute]
public
#line 1 """"
MyType1

#line default
#line hidden
{ get; private set; }
";
            var writer = new CSharpCodeWriter();
            var context = CreateContext();
            context.Host.DesignTimeMode = true;

            var visitor = new InjectChunkVisitor(writer, context, "Microsoft.AspNet.Mvc.ActivateAttribute");
            var factory = SpanFactory.CreateCsHtml();
            var node = (Span)factory.Code("Some code")
                                    .As(new InjectParameterGenerator("MyType", "MyPropertyName"));

            // Act
            visitor.Accept(new Chunk[]
            {
                new LiteralChunk(),
                new InjectChunk("MyType1", string.Empty) { Association = node },
            });
            var code = writer.GenerateCode();

            // Assert
            Assert.Equal(expected, code);
        }