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 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 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 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 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 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 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 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()); } }
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); }
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 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 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); }
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 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 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 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); }