Example #1
0
 public void ContextThrowsArgumentNullExceptionWhenNewValueIsNull() // Because allowing it would magically change property value to TransformationContext.Current.
 {
     using (var template = new FakeTemplate())
     {
         template.Context = null;
     }
 }
Example #2
0
 public void ContextReturnsTransformationContextByDefault()
 {
     using (var template = new FakeTemplate())
     {
         Assert.AreSame(TransformationContext.Current, template.Context);
     }
 }
Example #3
0
 public void EnabledIsTrueByDefault()
 {
     using (var template = new FakeTemplate())
     {
         Assert.IsTrue(template.Enabled);
     }
 }
Example #4
0
 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);
     }
 }
Example #5
0
 public void TransformDoesNotValidateOutputProperties()
 {
     using (var template = new FakeTemplate())
     {
         template.Output.Project = "Test.proj";
         template.Transform();
         Assert.AreEqual(0, template.Errors.Count);
     }
 }
Example #6
0
        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());
            }
        }
Example #7
0
 public void TransformDoesNotGenerateOutputWhenValidateReportsErrors()
 {
     using (var template = new FakeTemplate())
     {
         template.TransformedText = () => template.WriteLine(TestOutput);
         template.Validated = () => template.Error(TestMessage);
         Assert.AreEqual(string.Empty, template.Transform());
     }
 }
Example #8
0
 public void TransformGeneratesOutputWhenValidateReportsWarnings()
 {
     using (var template = new FakeTemplate())
     {
         template.TransformedText = () => template.Write(TestOutput);
         template.Validated = () => template.Warning(TestMessage);
         Assert.AreEqual(TestOutput, template.Transform());
     }
 }
Example #9
0
 public void WarningFormatThrowsArgumentNullExceptionWhenFormatIsNull()
 {
     using (var template = new FakeTemplate())
     {
         template.Warning(null, null);                
     }
 }
Example #10
0
 public void RenderReportsTransformationExceptionsAsErrors()
 {
     using (var template = new FakeTemplate())
     {
         template.Validated = () => { throw new TransformationException(TestMessage); };
         template.Render();
         AssertSingleError(template.Errors, TestMessage);
     }
 }
Example #11
0
 public void SessionReturnsTransformationSession()
 {
     using (var template = new FakeTemplate())
     {
         Assert.AreSame(this.transformation.Session, template.Session);
     }
 }
Example #12
0
 public void RenderDoesNotTransformTemplateWhenEnabledIsFalse()
 {
     using (var template = new FakeTemplate())
     {
         template.Enabled = false;
         bool transformed = false;
         template.TransformedText = () => transformed = true;
         template.Render();
         Assert.IsFalse(transformed);
     }
 }
Example #13
0
 public void RenderToFileSetsOutputFile()
 {
     using (var template = new FakeTemplate())
     {
         template.RenderToFile(TestFile);
         Assert.AreEqual(TestFile, template.Output.File);
     }
 }
Example #14
0
        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());
        }
Example #15
0
        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);            
        }
Example #16
0
        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);
        }
Example #17
0
 public void RenderReportsTemplateValidationErrorsToTransformation()
 {
     using (var template = new FakeTemplate())
     {
         template.Validated = () => template.Error(TestMessage);
         template.Render();
         AssertSingleError(this.transformation.Errors, TestMessage);
     }
 }
Example #18
0
        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());
            }            
        }
Example #19
0
 public void RenderRaisesRenderingEvent()
 {
     using (var template = new FakeTemplate())
     {
         bool eventRaised = false;
         template.Rendering += delegate { eventRaised = true; };
         template.Render();
         Assert.AreEqual(true, eventRaised);                
     }
 }
Example #20
0
 public void WarningThrowsArgumentNullExceptionWhenMessageIsNull()
 {
     using (var template = new FakeTemplate())
     {
         template.Warning(null);                
     }
 }
Example #21
0
 public void EnabledCanBeSet()
 {
     using (var template = new FakeTemplate())
     {
         template.Enabled = false;
         Assert.AreEqual(false, template.Enabled);
     }
 }
Example #22
0
 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);                
     }
 }
Example #23
0
 public void ErrorsIsNotNull()
 {
     using (var template = new FakeTemplate())
     {
         Assert.IsNotNull(template.Errors);                
     }
 }
Example #24
0
 public void TransformRunsCodeGeneratedByDirectiveProcessors()
 {
     using (var template = new FakeTemplate())
     {
         bool initialized = false;
         template.Initialized = () => initialized = true;
         template.Transform();
         Assert.IsTrue(initialized);
     }                        
 }
Example #25
0
 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);
     }            
 }
Example #26
0
 public void TransformValidatesTemplate()
 {
     using (var template = new FakeTemplate())
     {
         template.Validated = () => template.Error(TestMessage);
         template.Transform();
         Assert.AreEqual(1, template.Errors.Count);
     }            
 }
Example #27
0
 public void TransformDoesNotCatchTransformationException()
 {
     using (var template = new FakeTemplate())
     {
         template.Validated = () => { throw new TransformationException(); };
         template.Transform();
     }
 }
Example #28
0
 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);                
     }
 }
Example #29
0
 public void ErrorFormatThrowsNullArgumentExceptionWhenFormatIsNull()
 {
     using (var template = new FakeTemplate())
     {
         template.Error(null, null);                
     }
 }