コード例 #1
0
ファイル: ClrTemplateTest.cs プロジェクト: icool123/T4Toolbox
        public void DefaultNamespaceCombinesRelativeInputFilePathWithRootNamespace()
        {
            using (var transformation = new FakeTransformation())
            using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
            using (var template = new TestClrTemplate())
            {
                template.Context = context;
                transformation.Host.TemplateFile = Path.Combine(Environment.CurrentDirectory, "SubFolder\\Template.tt");
                transformation.Host.GetMetadataValue = (hierarhcy, inputFile, metadataName) => string.Empty;
                transformation.Host.GetPropertyValue = (hierarchy, propertyName) =>
                {
                    switch (propertyName)
                    {
                        case "RootNamespace":
                            return "TestNamespace";
                        case "MSBuildProjectFullPath":
                            return Path.Combine(Environment.CurrentDirectory, "Project.proj");
                        default:
                            return string.Empty;
                    }
                };

                Assert.AreEqual("TestNamespace.SubFolder", template.DefaultNamespace);
            }
        }
コード例 #2
0
        public void DefaultNamespaceCombinesRelativeInputFilePathWithRootNamespace()
        {
            using (var transformation = new FakeTransformation())
                using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
                    using (var template = new TestClrTemplate())
                    {
                        template.Context = context;
                        transformation.Host.TemplateFile     = Path.Combine(Environment.CurrentDirectory, "SubFolder\\Template.tt");
                        transformation.Host.GetMetadataValue = (hierarhcy, inputFile, metadataName) => string.Empty;
                        transformation.Host.GetPropertyValue = (hierarchy, propertyName) =>
                        {
                            switch (propertyName)
                            {
                            case "RootNamespace":
                                return("TestNamespace");

                            case "MSBuildProjectFullPath":
                                return(Path.Combine(Environment.CurrentDirectory, "Project.proj"));

                            default:
                                return(string.Empty);
                            }
                        };

                        Assert.AreEqual("TestNamespace.SubFolder", template.DefaultNamespace);
                    }
        }
コード例 #3
0
        public void RootNamespaceReturnsPropertyValueSuppliedByProvider()
        {
            using (var transformation = new FakeTransformation())
                using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
                    using (var template = new TestClrTemplate())
                    {
                        template.Context = context;

                        const string ExpectedValue      = "TestNamespace";
                        string       actualPropertyName = null;
                        transformation.Host.GetPropertyValue = (hierarchy, propertyName) =>
                        {
                            actualPropertyName = propertyName;
                            return(ExpectedValue);
                        };

                        Assert.AreEqual(ExpectedValue, template.RootNamespace);
                        Assert.AreEqual("RootNamespace", actualPropertyName);
                    }
        }
コード例 #4
0
ファイル: ClrTemplateTest.cs プロジェクト: icool123/T4Toolbox
        public void RootNamespaceReturnsPropertyValueSuppliedByProvider()
        {
            using (var transformation = new FakeTransformation())
            using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
            using (var template = new TestClrTemplate())
            {
                template.Context = context;

                const string ExpectedValue = "TestNamespace";
                string actualPropertyName = null;
                transformation.Host.GetPropertyValue = (hierarchy, propertyName) =>
                {
                    actualPropertyName = propertyName;
                    return ExpectedValue;
                };

                Assert.AreEqual(ExpectedValue, template.RootNamespace);
                Assert.AreEqual("RootNamespace", actualPropertyName);
            }
        }