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

            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<Type1>", @class.BaseType);
        }
Esempio n. 2
0
        public void ModelDirectivePass_Execute_NoOpWithoutTModel()
        {
            // Arrange
            var codeDocument = CreateDocument(@"
@inherits BaseType
@model Type1
");

            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", @class.BaseType);
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        public void ModelDirectivePass_Execute_ReplacesTModelInBaseType_DefaultDynamic()
        {
            // Arrange
            var codeDocument = CreateDocument(@"
@inherits BaseType<TModel>
");

            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<dynamic>", @class.BaseType);
        }