示例#1
0
        public void ModelDirectivePass_Execute_ReplacesTModelInBaseType_DifferentOrdering()
        {
            // Arrange
            var codeDocument = CreateDocument(@"
@model Type1
@inherits BaseType<TModel>
@model Type2
");

            var engine = CreateEngine();
            var pass   = new ModelDirective.Pass()
            {
                Engine = engine,
            };

            var irDocument = CreateIRDocument(engine, codeDocument);

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

            // Assert
            var @class = FindClassNode(irDocument);

            Assert.NotNull(@class);
            Assert.Equal("BaseType<Type1>", @class.BaseType);
        }
示例#2
0
        public void ModelDirectivePass_DesignTime_WithModel_AddsTModelUsingDirective()
        {
            // Arrange
            var codeDocument = CreateDocument(@"
@inherits BaseType<TModel>
@model SomeType
");

            var engine = CreateDesignTimeEngine();
            var pass   = new ModelDirective.Pass()
            {
                Engine = engine,
            };

            var irDocument = CreateIRDocument(engine, codeDocument);

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

            // Assert
            var @class = FindClassNode(irDocument);

            Assert.NotNull(@class);
            Assert.Equal("BaseType<SomeType>", @class.BaseType);

            var @namespace = FindNamespaceNode(irDocument);
            var usingNode  = Assert.IsType <UsingDirectiveIntermediateNode>(@namespace.Children[0]);

            Assert.Equal($"TModel = global::System.Object", usingNode.Content);
        }
示例#3
0
        public void ModelDirectivePass_Execute_NoOpWithoutTModel()
        {
            // Arrange
            var codeDocument = CreateDocument(@"
@inherits BaseType
@model Type1
");

            var engine = CreateEngine();
            var pass   = new ModelDirective.Pass()
            {
                Engine = engine,
            };

            var irDocument = CreateIRDocument(engine, codeDocument);

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

            // Assert
            var @class = FindClassNode(irDocument);

            Assert.NotNull(@class);
            Assert.Equal("BaseType", @class.BaseType);
        }
示例#4
0
        public void ModelDirectivePass_DesignTime_AddsTModelUsingDirective()
        {
            // Arrange
            var codeDocument = CreateDocument(@"
@inherits BaseType<TModel>
");

            var engine = CreateEngine();
            var pass   = new ModelDirective.Pass(designTime: true)
            {
                Engine = engine,
            };

            var irDocument = CreateIRDocument(engine, codeDocument);

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

            // Assert
            var @class = FindClassNode(irDocument);

            Assert.NotNull(@class);
            Assert.Equal("BaseType<dynamic>", @class.BaseType);

            var @namespace = FindNamespaceNode(irDocument);
            var usingNode  = Assert.IsType <UsingDirectiveIntermediateNode>(@namespace.Children[0]);

            Assert.Equal($"TModel = global::{typeof(object).FullName}", usingNode.Content);
        }
示例#5
0
        public void ModelDirectivePass_Execute_ReplacesTModelInBaseType_DefaultDynamic()
        {
            // Arrange
            var codeDocument = CreateDocument(@"
@inherits BaseType<TModel>
");

            var engine = CreateRuntimeEngine();
            var pass   = new ModelDirective.Pass()
            {
                Engine = engine,
            };

            var irDocument = CreateIRDocument(engine, codeDocument);

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

            // Assert
            var @class = FindClassNode(irDocument);

            Assert.NotNull(@class);
            Assert.Equal("BaseType<dynamic>", @class.BaseType);
        }