private void Transform_TestRunner_ExpectSuccess(string source, string transform, string baseline, string expectedLog)
        {
            string src                      = CreateATestFile("source.config", source);
            string transformFile            = CreateATestFile("transform.config", transform);
            string baselineFile             = CreateATestFile("baseline.config", baseline);
            string destFile                 = GetTestFilePath("result.config");
            TestTransformationLogger logger = new TestTransformationLogger();

            XmlTransformableDocument x = new XmlTransformableDocument();

            x.PreserveWhitespace = true;
            x.Load(src);

            Microsoft.Web.XmlTransform.XmlTransformation xmlTransform = new Microsoft.Web.XmlTransform.XmlTransformation(transformFile, logger);

            //execute
            bool succeed = xmlTransform.Apply(x);

            x.Save(destFile);
            xmlTransform.Dispose();
            x.Dispose();
            //test
            Assert.AreEqual(true, succeed);
            CompareFiles(baselineFile, destFile);
            CompareMultiLines(ReadResource(expectedLog), logger.LogText);
        }
Beispiel #2
0
        public void XmlTransformWithLogger_Expect_Success_RemoveAttributes_When_Attribute_Not_Present()
        {
            //============================================================================ robs ==
            // Needs to have a logger as that's where the exception this is to highlight originates
            //====================================================================== 2019-11-29 ==
            var logger = new TestTransformationLogger();

            //============================================================================ robs ==
            // This HAS to be XmlDocument, if it's XmlTransformableDocument it won't hit the
            // exception path this test is for.
            //====================================================================== 2019-11-30 ==
            var sourceConfig = new System.Xml.XmlDocument();

            //============================================================================ robs ==
            // Load original source web.config - with debug="true"
            //====================================================================== 2019-11-30 ==
            sourceConfig.LoadXml(Resources.Web);

            //============================================================================ robs ==
            // Create two transforms, one to replicate a release build config transform and another
            // to replicate a deploy transform - they are both the same but it doesn't matter as long as
            // the result is that one transform has RemoveAttributes when the source does not have
            // the attribute.
            //====================================================================== 2019-11-30 ==
            using (var transformRelease = new XmlTransformation(Resources.Web_Release, false, logger))
                using (var transformDeploy = new XmlTransformation(Resources.Web_Release, false, logger))
                {
                    bool transformReleaseSucceed = transformRelease.Apply(sourceConfig);
                    Assert.True(transformReleaseSucceed);

                    bool transformDeploySucceed = transformDeploy.Apply(sourceConfig);
                    Assert.True(transformDeploySucceed);

                    string transformedContent = sourceConfig.OuterXml;
                    Assert.DoesNotContain("debug=\"true\"", transformedContent);
                }
        }
        private void Transform_TestRunner_ExpectFail(string source, string transform, string expectedLog)
        {
            string src = CreateATestFile("source.config", source);
            string transformFile = CreateATestFile("transform.config", transform);
            string destFile = GetTestFilePath("result.config");
            TestTransformationLogger logger = new TestTransformationLogger();

            XmlTransformableDocument x = new XmlTransformableDocument();
            x.PreserveWhitespace = true;
            x.Load(src);

            Microsoft.Web.XmlTransform.XmlTransformation xmlTransform = new Microsoft.Web.XmlTransform.XmlTransformation(transformFile, logger);

            //execute
            bool succeed = xmlTransform.Apply(x);
            x.Save(destFile);
            xmlTransform.Dispose();
            x.Dispose();
            //test
            Assert.AreEqual(false, succeed);
            CompareMultiLines(expectedLog, logger.LogText);
        }