public void ContextThrowsArgumentNullExceptionWhenNewValueIsNull() // Because allowing it would magically change property value to TransformationContext.Current. { using (var template = new FakeTemplate()) { template.Context = null; } }
public void ContextReturnsTransformationContextByDefault() { using (var template = new FakeTemplate()) { Assert.AreSame(TransformationContext.Current, template.Context); } }
public void EnabledIsTrueByDefault() { using (var template = new FakeTemplate()) { Assert.IsTrue(template.Enabled); } }
public void ContextCanBeSet() { using (var transformation = new FakeTransformation()) using (var context = new TransformationContext(transformation, transformation.GenerationEnvironment)) using (var template = new FakeTemplate()) { template.Context = context; Assert.AreSame(context, template.Context); } }
public void TransformDoesNotValidateOutputProperties() { using (var template = new FakeTemplate()) { template.Output.Project = "Test.proj"; template.Transform(); Assert.AreEqual(0, template.Errors.Count); } }
public void TransformClearsPreviousOutputToAllowGeneratingMultipleOutputsFromSingleTemplate() { using (var template = new FakeTemplate()) { template.TransformedText = () => template.Write("First Output"); template.Transform(); template.TransformedText = () => template.Write(TestOutput); Assert.AreEqual(TestOutput, template.Transform()); } }
public void TransformDoesNotGenerateOutputWhenValidateReportsErrors() { using (var template = new FakeTemplate()) { template.TransformedText = () => template.WriteLine(TestOutput); template.Validated = () => template.Error(TestMessage); Assert.AreEqual(string.Empty, template.Transform()); } }
public void TransformGeneratesOutputWhenValidateReportsWarnings() { using (var template = new FakeTemplate()) { template.TransformedText = () => template.Write(TestOutput); template.Validated = () => template.Warning(TestMessage); Assert.AreEqual(TestOutput, template.Transform()); } }
public void WarningFormatThrowsArgumentNullExceptionWhenFormatIsNull() { using (var template = new FakeTemplate()) { template.Warning(null, null); } }
public void RenderReportsTransformationExceptionsAsErrors() { using (var template = new FakeTemplate()) { template.Validated = () => { throw new TransformationException(TestMessage); }; template.Render(); AssertSingleError(template.Errors, TestMessage); } }
public void SessionReturnsTransformationSession() { using (var template = new FakeTemplate()) { Assert.AreSame(this.transformation.Session, template.Session); } }
public void RenderDoesNotTransformTemplateWhenEnabledIsFalse() { using (var template = new FakeTemplate()) { template.Enabled = false; bool transformed = false; template.TransformedText = () => transformed = true; template.Render(); Assert.IsFalse(transformed); } }
public void RenderToFileSetsOutputFile() { using (var template = new FakeTemplate()) { template.RenderToFile(TestFile); Assert.AreEqual(TestFile, template.Output.File); } }
public void RenderToFileRendersTheTemplate() { OutputFile[] outputFiles = null; this.transformation.Host.UpdatedOutputFiles = (input, outputs) => outputFiles = outputs; using (var template = new FakeTemplate()) { template.TransformedText = () => template.Write(TestOutput); template.RenderToFile(TestFile); } this.Dispose(); // Force the end of transformation OutputFile outputFile = outputFiles.Single(output => output.File == TestFile); Assert.AreEqual(TestOutput, outputFile.Content.ToString()); }
public void RenderReportsTemplateFileInErrorsOfTemplateFileBasedTransformation() { this.transformation.Host.TemplateFile = "Template.tt"; using (var template = new FakeTemplate()) { template.Validated = () => template.Error(TestMessage); template.Render(); } var error = this.transformation.Errors.Cast<CompilerError>().Single(); Assert.AreEqual("Template.tt", error.FileName); }
public void RenderReportsInputFileInErrorsOfInputFileBasedTransformation() { this.transformation.Session[TransformationContext.InputFileNameKey] = "Input.cs"; using (var template = new FakeTemplate()) { template.Validated = () => template.Error(TestMessage); template.Render(); } var error = this.transformation.Errors.Cast<CompilerError>().Single(); Assert.AreEqual("Input.cs", error.FileName); }
public void RenderReportsTemplateValidationErrorsToTransformation() { using (var template = new FakeTemplate()) { template.Validated = () => template.Error(TestMessage); template.Render(); AssertSingleError(this.transformation.Errors, TestMessage); } }
public void TransformClearsPreviousErrorsToAllowTransformingSameTemplateMultipleTimes() { using (var template = new FakeTemplate()) { template.Validated = () => template.Error(TestMessage); template.Transform(); template.Validated = null; template.TransformedText = () => template.Write(TestOutput); Assert.AreEqual(TestOutput, template.Transform()); } }
public void RenderRaisesRenderingEvent() { using (var template = new FakeTemplate()) { bool eventRaised = false; template.Rendering += delegate { eventRaised = true; }; template.Render(); Assert.AreEqual(true, eventRaised); } }
public void WarningThrowsArgumentNullExceptionWhenMessageIsNull() { using (var template = new FakeTemplate()) { template.Warning(null); } }
public void EnabledCanBeSet() { using (var template = new FakeTemplate()) { template.Enabled = false; Assert.AreEqual(false, template.Enabled); } }
public void WarningFormatAddsNewWarningToErrorsCollection() { using (var template = new FakeTemplate()) { template.Warning("{0}", TestMessage); Assert.AreEqual(1, template.Errors.Count); Assert.AreEqual(TestMessage, template.Errors[0].ErrorText); Assert.AreEqual(true, template.Errors[0].IsWarning); } }
public void ErrorsIsNotNull() { using (var template = new FakeTemplate()) { Assert.IsNotNull(template.Errors); } }
public void TransformRunsCodeGeneratedByDirectiveProcessors() { using (var template = new FakeTemplate()) { bool initialized = false; template.Initialized = () => initialized = true; template.Transform(); Assert.IsTrue(initialized); } }
public void RenderTransformsTemplateWhenEnabledIsSetByRenderingEventHandler() { using (var template = new FakeTemplate()) { template.Enabled = false; bool transformed = false; template.Rendering += delegate { template.Enabled = true; }; template.TransformedText = () => transformed = true; template.Render(); Assert.IsTrue(transformed); } }
public void TransformValidatesTemplate() { using (var template = new FakeTemplate()) { template.Validated = () => template.Error(TestMessage); template.Transform(); Assert.AreEqual(1, template.Errors.Count); } }
public void TransformDoesNotCatchTransformationException() { using (var template = new FakeTemplate()) { template.Validated = () => { throw new TransformationException(); }; template.Transform(); } }
public void ErrorAddsNewErrorToErrorsCollection() { using (var template = new FakeTemplate()) { template.Error(TestMessage); Assert.AreEqual(1, template.Errors.Count); Assert.AreEqual(TestMessage, template.Errors[0].ErrorText); Assert.AreEqual(false, template.Errors[0].IsWarning); } }
public void ErrorFormatThrowsNullArgumentExceptionWhenFormatIsNull() { using (var template = new FakeTemplate()) { template.Error(null, null); } }