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 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.º 3
0
 public void WriteThrowsArgumentNullExceptionWhenOutputIsNull()
 {
     using (var transformation = new FakeTransformation())
         using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
         {
             context.Write(null, string.Empty);
         }
 }
Ejemplo n.º 4
0
        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.º 5
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.º 6
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.º 7
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.º 8
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.º 9
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.º 10
0
        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());
        }
Ejemplo n.º 11
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.º 12
0
        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);
                        }
                    }
                }
        }
Ejemplo n.º 13
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.º 14
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);
        }
Ejemplo n.º 15
0
        public void DisposeUpdatesTemplateFileWhenSessionDoesNotHaveInputFile()
        {
            const string TemplateFile = "TestTemplate.tt";
            string       actualInput  = null;

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

            Assert.AreEqual(TemplateFile, actualInput);
        }
Ejemplo n.º 16
0
        public void WriteSetsFileEncodingForDefaultOutput()
        {
            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 {
                        Encoding = Encoding.UTF7
                    }, string.Empty);
                }

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

            Assert.AreEqual(Encoding.UTF7, outputFile.Encoding);
        }
Ejemplo n.º 17
0
        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);
        }
Ejemplo n.º 18
0
        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);
        }
Ejemplo n.º 19
0
        public void DisposeUpdatesInputFileWhenSessionHasInputFile()
        {
            const string ExpectedInput = "TestInput.cs";
            string       actualInput   = null;

            using (var transformation = new FakeTransformation())
                using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
                {
                    transformation.Session[TransformationContext.InputFileNameKey] = ExpectedInput;
                    transformation.Host.TemplateFile       = "TestTemplate.tt";
                    transformation.Host.UpdatedOutputFiles = (input, outputs) => actualInput = input;
                    context.Write(new OutputItem {
                        File = TestFile
                    }, TestText);
                }

            Assert.AreEqual(ExpectedInput, actualInput);
        }
Ejemplo n.º 20
0
        public void DisposeLogsTransformationExceptionsThrownByOutputFileManager()
        {
            CompilerErrorCollection actualErrors = null;

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

            var error = actualErrors.Cast <CompilerError>().Single();

            Assert.AreEqual(TestText, error.ErrorText);
        }
        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 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 WriteThrowsArgumentNullExceptionWhenOutputIsNull()
 {
     using (var transformation = new FakeTransformation())
     using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
     {
         context.Write(null, string.Empty);
     }
 }
        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 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 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 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 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 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());
        }
        public void DisposeLogsTransformationExceptionsThrownByOutputFileManager()
        {
            CompilerErrorCollection actualErrors = null;
            using (var transformation = new FakeTransformation())
            using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
            {
                transformation.Host.UpdatedOutputFiles = (input, outputs) => { throw new TransformationException(TestText); };
                transformation.Host.LoggedErrors = errors => actualErrors = errors;
                context.Write(new OutputItem { File = TestFile }, TestText);
            }

            var error = actualErrors.Cast<CompilerError>().Single();
            Assert.AreEqual(TestText, error.ErrorText);
        }
 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 DisposeUpdatesInputFileWhenSessionHasInputFile()
        {
            const string ExpectedInput = "TestInput.cs";
            string actualInput = null;
            using (var transformation = new FakeTransformation())
            using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
            {
                transformation.Session[TransformationContext.InputFileNameKey] = ExpectedInput;
                transformation.Host.TemplateFile = "TestTemplate.tt";
                transformation.Host.UpdatedOutputFiles = (input, outputs) => actualInput = input;
                context.Write(new OutputItem { File = TestFile }, TestText);
            }

            Assert.AreEqual(ExpectedInput, actualInput);
        }
        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 DisposeUpdatesTemplateFileWhenSessionDoesNotHaveInputFile()
        {
            const string TemplateFile = "TestTemplate.tt";
            string actualInput = null;
            using (var transformation = new FakeTransformation())
            using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
            {
                transformation.Host.TemplateFile = TemplateFile;
                transformation.Host.UpdatedOutputFiles = (input, outputs) => actualInput = input;
                context.Write(new OutputItem { File = TestFile }, TestText);
            }

            Assert.AreEqual(TemplateFile, actualInput);
        }
        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 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 WriteThrowsInvalidOperationExceptionWhenDirectoryIsSpecifiedWithoutFile()
 {
     using (var transformation = new FakeTransformation())
     using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment))
     {
         context.Write(new OutputItem { Directory = "SubFolder" }, string.Empty);
     }
 }
 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());
     }
 }
        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 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);
        }