Ejemplo n.º 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"]);
        }
Ejemplo n.º 2
0
 public void InitializeThrowsArgumentNullExceptionWhenGenerationEnvironmentIsNull()
 {
     using (var transformation = new FakeTransformation())
     {
         TransformationContext.Initialize(transformation, null);
     }
 }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
                    }
        }
Ejemplo n.º 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"));
        }
Ejemplo n.º 6
0
 public void TransformationReturnsTransformationPassedToConstructor()
 {
     using (var transformation = new FakeTransformation())
         using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
         {
             Assert.AreSame(transformation, context.Transformation);
         }
 }
Ejemplo n.º 7
0
 public void GetPropertyValueThrowsArgumentExceptionWhenNameIsEmpty()
 {
     using (var transformation = new FakeTransformation())
         using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
         {
             context.GetPropertyValue(" \t\r\n");
         }
 }
Ejemplo n.º 8
0
 public void GetMetadataValueThrowsArgumentNullExceptionWhenNameIsNull()
 {
     using (var transformation = new FakeTransformation())
         using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
         {
             context.GetMetadataValue(null);
         }
 }
Ejemplo n.º 9
0
 public void InitializeThrowsArgumentExceptionWhenTransformationHostIsNull()
 {
     using (var transformation = new FakeTransformation())
     {
         transformation.Host = null;
         TransformationContext.Initialize(transformation, transformation.GenerationEnvironment);
     }
 }
Ejemplo n.º 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
         }
 }
Ejemplo n.º 11
0
 public void WriteThrowsArgumentNullExceptionWhenOutputIsNull()
 {
     using (var transformation = new FakeTransformation())
         using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
         {
             context.Write(null, string.Empty);
         }
 }
Ejemplo n.º 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;
     }
 }
Ejemplo n.º 14
0
 public void Dispose()
 {
     if (this.transformation != null)
     {
         TransformationContext.Cleanup();
         this.transformation.Dispose();
         this.transformation = null;
     }
 }
Ejemplo n.º 15
0
 public void Dispose()
 {
     if (this.transformation != null)
     {
         TransformationContext.Cleanup();
         this.transformation.Dispose();
         this.transformation = null;
     }
 }
Ejemplo n.º 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);
         }
 }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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);
         }
 }
Ejemplo n.º 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"));
         }
 }
Ejemplo n.º 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);
         }
 }
Ejemplo n.º 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);
         }
 }
Ejemplo n.º 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());
         }
 }
Ejemplo n.º 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);
         }
 }
Ejemplo n.º 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());
         }
 }
Ejemplo n.º 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());
         }
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
         }
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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());
         }
 }
Ejemplo n.º 30
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);
     }
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 34
0
 public void InitializeSetsCurrent()
 {
     using (var transformation = new FakeTransformation())
     {
         TransformationContext.Initialize(transformation, transformation.GenerationEnvironment);
         try
         {
             Assert.IsNotNull(TransformationContext.Current);
         }
         finally
         {
             TransformationContext.Cleanup();
         }
     }
 }
Ejemplo n.º 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());
        }
Ejemplo n.º 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
     }
 }