Beispiel #1
0
        public void WriteCombinesFileMetadata()
        {
            OutputFile[] outputFiles = null;

            using (var transformation = new FakeTransformation())
                using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
                {
                    transformation.Host.UpdatedOutputFiles = (input, outputs) => outputFiles = outputs;

                    var outputInfo = new OutputItem {
                        File = TestFile
                    };
                    outputInfo.Metadata["Generator"] = "TextTemplatingFileGenerator";
                    context.Write(outputInfo, string.Empty);

                    outputInfo.Metadata.Clear();
                    outputInfo.Metadata["LastGenOutput"] = "Test.txt";
                    context.Write(outputInfo, string.Empty);
                }

            OutputFile outputFile = outputFiles.Single(output => output.File == TestFile);

            Assert.AreEqual("TextTemplatingFileGenerator", outputFile.Metadata["Generator"]);
            Assert.AreEqual("Test.txt", outputFile.Metadata["LastGenOutput"]);
        }
Beispiel #2
0
 public void InitializeThrowsArgumentNullExceptionWhenGenerationEnvironmentIsNull()
 {
     using (var transformation = new FakeTransformation())
     {
         TransformationContext.Initialize(transformation, null);
     }
 }
Beispiel #3
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);
            }
        }
Beispiel #4
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);
                    }
        }
Beispiel #5
0
        public void WriteCombinesFileReferences()
        {
            OutputFile[] outputFiles = null;

            using (var transformation = new FakeTransformation())
                using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
                {
                    transformation.Host.UpdatedOutputFiles = (input, outputs) => outputFiles = outputs;

                    var outputInfo = new OutputItem {
                        File = TestFile
                    };
                    outputInfo.References.Add("System");
                    context.Write(outputInfo, string.Empty);

                    outputInfo.Metadata.Clear();
                    outputInfo.References.Add("System.Xml");
                    context.Write(outputInfo, string.Empty);
                }

            OutputFile outputFile = outputFiles.Single(output => output.File == TestFile);

            Assert.IsTrue(outputFile.References.Contains("System"));
            Assert.IsTrue(outputFile.References.Contains("System.Xml"));
        }
Beispiel #6
0
 public void TransformationReturnsTransformationPassedToConstructor()
 {
     using (var transformation = new FakeTransformation())
         using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
         {
             Assert.AreSame(transformation, context.Transformation);
         }
 }
Beispiel #7
0
 public void GetPropertyValueThrowsArgumentExceptionWhenNameIsEmpty()
 {
     using (var transformation = new FakeTransformation())
         using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
         {
             context.GetPropertyValue(" \t\r\n");
         }
 }
Beispiel #8
0
 public void GetMetadataValueThrowsArgumentNullExceptionWhenNameIsNull()
 {
     using (var transformation = new FakeTransformation())
         using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
         {
             context.GetMetadataValue(null);
         }
 }
Beispiel #9
0
 public void InitializeThrowsArgumentExceptionWhenTransformationHostIsNull()
 {
     using (var transformation = new FakeTransformation())
     {
         transformation.Host = null;
         TransformationContext.Initialize(transformation, transformation.GenerationEnvironment);
     }
 }
Beispiel #10
0
 public void GetServiceReturnsNullWhenServiceIsNotAvailable()
 {
     using (var transformation = new FakeTransformation())
         using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
         {
             Assert.IsNull(context.GetService(typeof(ICloneable))); // Bogus service
         }
 }
Beispiel #11
0
 public void WriteThrowsArgumentNullExceptionWhenOutputIsNull()
 {
     using (var transformation = new FakeTransformation())
         using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
         {
             context.Write(null, string.Empty);
         }
 }
Beispiel #12
0
 public void CleanupRemovesCurrent()
 {
     using (var transformation = new FakeTransformation())
     {
         TransformationContext.Initialize(transformation, transformation.GenerationEnvironment);
         TransformationContext.Cleanup();
         var value = TransformationContext.Current;
     }
 }
 public void CleanupRemovesCurrent()
 {
     using (var transformation = new FakeTransformation())
     {
         TransformationContext.Initialize(transformation, transformation.GenerationEnvironment);
         TransformationContext.Cleanup();
         var value = TransformationContext.Current;
     }
 }
Beispiel #14
0
 public void Dispose()
 {
     if (this.transformation != null)
     {
         TransformationContext.Cleanup();
         this.transformation.Dispose();
         this.transformation = null;
     }
 }
Beispiel #15
0
 public void Dispose()
 {
     if (this.transformation != null)
     {
         TransformationContext.Cleanup();
         this.transformation.Dispose();
         this.transformation = null;
     }
 }
Beispiel #16
0
 public void ContextCanBeSet()
 {
     using (var transformation = new FakeTransformation())
         using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
         {
             this.generator.Context = context;
             Assert.AreSame(context, this.generator.Context);
         }
 }
Beispiel #17
0
 public void ContextCanBeSet()
 {
     using (var transformation = new FakeTransformation())
     using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
     {
         this.generator.Context = context;
         Assert.AreSame(context, this.generator.Context);
     }
 }
Beispiel #18
0
 public void HostReturnsHostOfTransformation()
 {
     using (var transformation = new FakeTransformation())
         using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
         {
             Assert.IsNotNull(context.Host);
             Assert.AreSame(transformation.Host, context.Host);
         }
 }
Beispiel #19
0
 public void GetPropertyValueReturnsValueSuppliedByProvider()
 {
     using (var transformation = new FakeTransformation())
         using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
         {
             const string ExpectedValue = "TestValue";
             transformation.Host.GetPropertyValue = (hierarchy, propertyName) => ExpectedValue;
             Assert.AreEqual(ExpectedValue, context.GetPropertyValue("TestProperty"));
         }
 }
Beispiel #20
0
 public void GetServiceDelegatesToHost()
 {
     using (var transformation = new FakeTransformation())
         using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
         {
             var expected = ((IServiceProvider)transformation.Host).GetService(typeof(ITransformationContextProvider));
             var actual   = context.GetService(typeof(ITransformationContextProvider));
             Assert.AreSame(expected, actual);
         }
 }
Beispiel #21
0
 public void WriteThrowsInvalidOperationExceptionWhenDirectoryIsSpecifiedWithoutFile()
 {
     using (var transformation = new FakeTransformation())
         using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
         {
             context.Write(new OutputItem {
                 Directory = "SubFolder"
             }, string.Empty);
         }
 }
Beispiel #22
0
 public void WriteRespectsTransformationIndentationForSingleLineText()
 {
     using (var transformation = new FakeTransformation())
         using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
         {
             transformation.PushIndent("\t");
             context.Write(new OutputItem(), TestText);
             Assert.AreEqual("\t" + TestText, transformation.TransformText());
         }
 }
Beispiel #23
0
 public void WriteThrowsInvalidOperationExceptionWhenProjectIsSpecifiedWithoutFile()
 {
     using (var transformation = new FakeTransformation())
         using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
         {
             context.Write(new OutputItem {
                 Project = "Test.proj"
             }, string.Empty);
         }
 }
Beispiel #24
0
 public void WriteAppendsToTransformationWhenOutputFileIsNotSpecified()
 {
     using (var transformation = new FakeTransformation())
         using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
         {
             transformation.Write("TransformationOutput");
             context.Write(new OutputItem(), "TemplateOutput");
             Assert.AreEqual("TransformationOutput" + "TemplateOutput", transformation.TransformText());
         }
 }
Beispiel #25
0
 public void WriteAppendsToPreviousTemplateOutput()
 {
     using (var transformation = new FakeTransformation())
         using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
         {
             context.Write(new OutputItem(), "TemplateOutput");
             transformation.Write("TransformationOutput");
             Assert.AreEqual("TemplateOutput" + "TransformationOutput", transformation.TransformText());
         }
 }
Beispiel #26
0
        public void DisposeRaisesDisposedEvent()
        {
            bool disposed = false;

            using (var transformation = new FakeTransformation())
                using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
                {
                    context.Disposed += delegate { disposed = true; };
                }

            Assert.IsTrue(disposed);
        }
Beispiel #27
0
 public void TransformTextGeneratesFileHeader()
 {
     using (var transformation = new FakeTransformation())
         using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
         {
             this.template.Context            = context;
             transformation.Host.TemplateFile = Path.GetRandomFileName();
             string output = this.template.TransformText();
             StringAssert.Contains(output, "<autogenerated>");
             StringAssert.Contains(output, transformation.Host.TemplateFile);
         }
 }
Beispiel #28
0
        public void DisposeInvokesOutputFileManagerWhenThereAreNoAdditionalOutputsSoThatPreviouslyGeneratedFilesCanBeDeleted()
        {
            bool outputFileManagerInvoked = false;

            using (var transformation = new FakeTransformation())
                using (new TransformationContext(transformation, transformation.GenerationEnvironment))
                {
                    transformation.Host.UpdatedOutputFiles = (input, outputs) => outputFileManagerInvoked = true;
                }

            Assert.IsTrue(outputFileManagerInvoked);
        }
Beispiel #29
0
 public void WriteRespectsTransformationIndentationForMultilineText()
 {
     using (var transformation = new FakeTransformation())
         using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
         {
             transformation.PushIndent("\t");
             string text = TestText + Environment.NewLine + TestText;
             context.Write(new OutputItem(), text);
             string expectedOutput = "\t" + TestText + Environment.NewLine + "\t" + TestText;
             Assert.AreEqual(expectedOutput, transformation.TransformText());
         }
 }
 public void TransformTextGeneratesFileHeader()
 {
     using (var transformation = new FakeTransformation())
     using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
     {
         this.template.Context = context;
         transformation.Host.TemplateFile = Path.GetRandomFileName();
         string output = this.template.TransformText();
         StringAssert.Contains(output, "<autogenerated>");                
         StringAssert.Contains(output, transformation.Host.TemplateFile);
     }
 }
Beispiel #31
0
        public void DisposeLogsTransformationExceptionsThrownByTransformationEndedEventHandlers()
        {
            CompilerErrorCollection actualErrors = null;

            using (var transformation = new FakeTransformation())
                using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
                {
                    transformation.Host.LoggedErrors = errors => actualErrors = errors;
                    context.Disposed += delegate { throw new TransformationException(); };
                }

            Assert.AreEqual(1, actualErrors.Count);
        }
Beispiel #32
0
        public void DisposeInvokesOutputFileManagerWhenThereAreAdditionalOutputs()
        {
            OutputFile[] outputFiles = null;
            using (var transformation = new FakeTransformation())
                using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
                {
                    transformation.Host.UpdatedOutputFiles = (input, outputs) => outputFiles = outputs;
                    context.Write(new OutputItem {
                        File = TestFile
                    }, TestText);
                }

            Assert.IsNotNull(outputFiles);
        }
Beispiel #33
0
        public void DisposeReportsInputFileInErrorsWhenSessionHasInputFile()
        {
            const string            InputFile    = "TestInput.cs";
            CompilerErrorCollection actualErrors = null;

            using (var transformation = new FakeTransformation())
                using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
                {
                    transformation.Session[TransformationContext.InputFileNameKey] = InputFile;
                    transformation.Host.LoggedErrors = errors => actualErrors = errors;
                    context.Disposed += delegate { throw new TransformationException(); };
                }

            Assert.AreEqual(InputFile, actualErrors.Cast <CompilerError>().Single().FileName);
        }
Beispiel #34
0
 public void InitializeSetsCurrent()
 {
     using (var transformation = new FakeTransformation())
     {
         TransformationContext.Initialize(transformation, transformation.GenerationEnvironment);
         try
         {
             Assert.IsNotNull(TransformationContext.Current);
         }
         finally
         {
             TransformationContext.Cleanup();
         }
     }
 }
Beispiel #35
0
        public void WriteSetsFileProject()
        {
            OutputFile[] outputFiles = null;

            using (var transformation = new FakeTransformation())
                using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
                {
                    transformation.Host.UpdatedOutputFiles = (input, outputs) => outputFiles = outputs;
                    context.Write(new OutputItem {
                        File = TestFile, Project = "Test.proj"
                    }, string.Empty);
                }

            OutputFile outputFile = outputFiles.Single(output => output.File == TestFile);

            Assert.AreEqual("Test.proj", outputFile.Project);
        }
        public void CleanupDisposesCurrent()
        {
            using (var transformation = new FakeTransformation())
            {
                bool disposed = false;
                TransformationContext.Initialize(transformation, transformation.GenerationEnvironment);
                try
                {
                    TransformationContext.Current.Disposed += delegate { disposed = true; };
                }
                finally
                {
                    TransformationContext.Cleanup();
                }

                Assert.IsTrue(disposed);
            }
        }
        public void WriteSetsFileCopyToOutputDirectory()
        {
            OutputFile[] outputFiles = null;

            using (var transformation = new FakeTransformation())
            using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
            {
                transformation.Host.UpdatedOutputFiles = (input, outputs) => outputFiles = outputs;
                context.Write(new OutputItem { File = TestFile, CopyToOutputDirectory = CopyToOutputDirectory.CopyAlways }, string.Empty);
            }

            OutputFile outputFile = outputFiles.Single(output => output.File == TestFile);
            Assert.AreEqual(CopyToOutputDirectory.CopyAlways, outputFile.CopyToOutputDirectory);
        }
 public void WriteRespectsTransformationIndentationForSingleLineText()
 {
     using (var transformation = new FakeTransformation())
     using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
     {
         transformation.PushIndent("\t");
         context.Write(new OutputItem(), TestText);
         Assert.AreEqual("\t" + TestText, transformation.TransformText());
     }
 }
 public void HostReturnsHostOfTransformation()
 {
     using (var transformation = new FakeTransformation())
     using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
     {
         Assert.IsNotNull(context.Host);
         Assert.AreSame(transformation.Host, context.Host);
     }
 }
        private static void WriteThrowsInvalidOperationException(OutputItem first, OutputItem second, params string[] keywords)
        {
            using (var transformation = new FakeTransformation())
            using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
            {
                first.File = TestFile;
                context.Write(first, string.Empty);

                try
                {
                    second.File = TestFile;
                    context.Write(second, string.Empty);
                }
                catch (InvalidOperationException e)
                {
                    Assert.AreNotEqual(typeof(TransformationException), e.GetType());
                    foreach (string keyword in keywords)
                    {
                        StringAssert.Contains(e.Message, keyword);
                    }
                }
            }
        }
 public void WriteThrowsInvalidOperationExceptionWhenDirectoryIsSpecifiedWithoutFile()
 {
     using (var transformation = new FakeTransformation())
     using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
     {
         context.Write(new OutputItem { Directory = "SubFolder" }, string.Empty);
     }
 }
        public void WriteSetsFileProject()
        {
            OutputFile[] outputFiles = null;

            using (var transformation = new FakeTransformation())
            using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
            {
                transformation.Host.UpdatedOutputFiles = (input, outputs) => outputFiles = outputs;
                context.Write(new OutputItem { File = TestFile, Project = "Test.proj" }, string.Empty);
            }

            OutputFile outputFile = outputFiles.Single(output => output.File == TestFile);
            Assert.AreEqual("Test.proj", outputFile.Project);
        }
        public void WriteCombinesFileMetadata()
        {
            OutputFile[] outputFiles = null;

            using (var transformation = new FakeTransformation())
            using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
            {
                transformation.Host.UpdatedOutputFiles = (input, outputs) => outputFiles = outputs;

                var outputInfo = new OutputItem { File = TestFile };
                outputInfo.Metadata["Generator"] = "TextTemplatingFileGenerator";
                context.Write(outputInfo, string.Empty);

                outputInfo.Metadata.Clear();
                outputInfo.Metadata["LastGenOutput"] = "Test.txt";
                context.Write(outputInfo, string.Empty);
            }

            OutputFile outputFile = outputFiles.Single(output => output.File == TestFile);
            Assert.AreEqual("TextTemplatingFileGenerator", outputFile.Metadata["Generator"]);
            Assert.AreEqual("Test.txt", outputFile.Metadata["LastGenOutput"]);
        }
 public void WriteAppendsToTransformationWhenOutputFileIsNotSpecified()
 {
     using (var transformation = new FakeTransformation())
     using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
     {
         transformation.Write("TransformationOutput");
         context.Write(new OutputItem(), "TemplateOutput");
         Assert.AreEqual("TransformationOutput" + "TemplateOutput", transformation.TransformText());
     }
 }
 public void GetServiceDelegatesToHost()
 {
     using (var transformation = new FakeTransformation())
     using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
     {
         var expected = ((IServiceProvider)transformation.Host).GetService(typeof(ITransformationContextProvider));
         var actual = context.GetService(typeof(ITransformationContextProvider));
         Assert.AreSame(expected, actual);
     }
 }
 public void TransformationReturnsTransformationPassedToConstructor()
 {
     using (var transformation = new FakeTransformation())
     using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
     {
         Assert.AreSame(transformation, context.Transformation);
     }
 }
 public void InitializeThrowsArgumentNullExceptionWhenGenerationEnvironmentIsNull()
 {
     using (var transformation = new FakeTransformation())
     {
         TransformationContext.Initialize(transformation, null);
     }
 }
 public void InitializeThrowsArgumentExceptionWhenTransformationHostIsNull()
 {
     using (var transformation = new FakeTransformation())
     {
         transformation.Host = null;
         TransformationContext.Initialize(transformation, transformation.GenerationEnvironment);
     }
 }
 public void InitializeSetsCurrent()
 {
     using (var transformation = new FakeTransformation())
     {
         TransformationContext.Initialize(transformation, transformation.GenerationEnvironment);
         try
         {
             Assert.IsNotNull(TransformationContext.Current);
         }
         finally
         {
             TransformationContext.Cleanup();
         }
     }
 }
        public void WriteSetsFileCustomToolNamespace()
        {
            OutputFile[] outputFiles = null;

            using (var transformation = new FakeTransformation())
            using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
            {
                transformation.Host.UpdatedOutputFiles = (input, outputs) => outputFiles = outputs;
                context.Write(new OutputItem { File = TestFile, CustomToolNamespace = "Microsoft" }, string.Empty);
            }

            OutputFile outputFile = outputFiles.Single(output => output.File == TestFile);
            Assert.AreEqual("Microsoft", outputFile.CustomToolNamespace);
        }
        public void WriteSetsFileItemTypeForDefaultOutput()
        {
            OutputFile[] outputFiles = null;

            using (var transformation = new FakeTransformation())
            using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
            {
                transformation.Host.UpdatedOutputFiles = (input, outputs) => outputFiles = outputs;
                context.Write(new OutputItem { ItemType = ItemType.Compile }, string.Empty);
            }

            OutputFile outputFile = outputFiles.Single(output => string.IsNullOrEmpty(output.File));
            Assert.AreEqual(ItemType.Compile, outputFile.ItemType);
        }
        public void WriteCombinesFileReferences()
        {
            OutputFile[] outputFiles = null;

            using (var transformation = new FakeTransformation())
            using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
            {
                transformation.Host.UpdatedOutputFiles = (input, outputs) => outputFiles = outputs;

                var outputInfo = new OutputItem { File = TestFile };
                outputInfo.References.Add("System");
                context.Write(outputInfo, string.Empty);

                outputInfo.Metadata.Clear();
                outputInfo.References.Add("System.Xml");
                context.Write(outputInfo, string.Empty);
            }

            OutputFile outputFile = outputFiles.Single(output => output.File == TestFile);
            Assert.IsTrue(outputFile.References.Contains("System"));
            Assert.IsTrue(outputFile.References.Contains("System.Xml"));
        }
 public void WriteThrowsArgumentNullExceptionWhenOutputIsNull()
 {
     using (var transformation = new FakeTransformation())
     using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
     {
         context.Write(null, string.Empty);
     }
 }
        public void WriteCombinesTextOfDifferentOutputsWithTheSameFileName()
        {
            OutputFile[] outputFiles = null;

            using (var transformation = new FakeTransformation())
            using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
            {
                transformation.Host.UpdatedOutputFiles = (input, outputs) => outputFiles = outputs;
                context.Write(new OutputItem { File = TestFile }, TestText);
                context.Write(new OutputItem { File = TestFile }, TestText);
            }

            OutputFile outputFile = outputFiles.Single(output => output.File == TestFile);
            Assert.AreEqual(TestText + TestText, outputFile.Content.ToString());
        }
 public void WriteThrowsInvalidOperationExceptionWhenProjectIsSpecifiedWithoutFile()
 {
     using (var transformation = new FakeTransformation())
     using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
     {
         context.Write(new OutputItem { Project = "Test.proj" }, string.Empty);
     }
 }
        public void WriteCombinesTextWrittenToTheSameOutputMultipleTimes()
        {
            OutputFile[] outputFiles = null;

            using (var transformation = new FakeTransformation())
            using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
            {
                transformation.Host.UpdatedOutputFiles = (input, outputs) => outputFiles = outputs;
                var outputInfo = new OutputItem { File = TestFile };
                context.Write(outputInfo, TestText);
                context.Write(outputInfo, TestText);
            }

            OutputFile outputFile = outputFiles.Single(output => output.File == TestFile);
            Assert.AreEqual(TestText + TestText, outputFile.Content.ToString());
        }
Beispiel #57
0
 public GeneratorTest()
 {
     this.transformation = new FakeTransformation();
     TransformationContext.Initialize(this.transformation, this.transformation.GenerationEnvironment);
 }
 public void WriteRespectsTransformationIndentationForMultilineText()
 {
     using (var transformation = new FakeTransformation())
     using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
     {
         transformation.PushIndent("\t");
         string text = TestText + Environment.NewLine + TestText;
         context.Write(new OutputItem(), text);
         string expectedOutput = "\t" + TestText + Environment.NewLine + "\t" + TestText;
         Assert.AreEqual(expectedOutput, transformation.TransformText());
     }
 }
 public void WriteAppendsToPreviousTemplateOutput()
 {
     using (var transformation = new FakeTransformation())
     using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
     {
         context.Write(new OutputItem(), "TemplateOutput");
         transformation.Write("TransformationOutput");
         Assert.AreEqual("TemplateOutput" + "TransformationOutput", transformation.TransformText());
     }
 }
 public void GetServiceReturnsNullWhenServiceIsNotAvailable()
 {
     using (var transformation = new FakeTransformation())
     using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
     {
         Assert.IsNull(context.GetService(typeof(ICloneable))); // Bogus service
     }
 }