コード例 #1
0
        public void MissingXsltFile()
        {
            string dir;
            TaskItem[] xmlPaths;
            TaskItem xslPath;
            TaskItem xslCompiledPath;
            TaskItem[] outputPaths;
            List<KeyValuePair<XslTransformation.XmlInput.XmlModes, object>> xmlInputs;
            List<KeyValuePair<XslTransformation.XsltInput.XslModes, object>> xslInputs;
            MockEngine engine;
            Prepare(out dir, out xmlPaths, out xslPath, out xslCompiledPath, out outputPaths, out xmlInputs, out xslInputs, out engine);

            // load missing xsl
            {
                XslTransformation t = new XslTransformation();
                t.BuildEngine = engine;
                t.OutputPaths = outputPaths;
                t.XmlInputPaths = xmlPaths;
                xslPath.ItemSpec = xslPath.ItemSpec + "bad";
                t.XslInputPath = xslPath;
                Assert.False(t.Execute()); // "This test should've failed (bad xslt)."
                Console.WriteLine(engine.Log);
                Assert.True(engine.Log.Contains("MSB3704"));
            }

            CleanUp(dir);
        }
コード例 #2
0
        public void MissingCompiledDllFile()
        {
            string dir;
            TaskItem[] xmlPaths;
            TaskItem xslPath;
            TaskItem xslCompiledPath;
            TaskItem[] outputPaths;
            List<KeyValuePair<XslTransformation.XmlInput.XmlModes, object>> xmlInputs;
            List<KeyValuePair<XslTransformation.XsltInput.XslModes, object>> xslInputs;
            MockEngine engine;
            Prepare(out dir, out xmlPaths, out xslPath, out xslCompiledPath, out outputPaths, out xmlInputs, out xslInputs, out engine);

            // missing xsltCompiledDll
            {
                XslTransformation t = new XslTransformation();
                t.BuildEngine = engine;
                t.OutputPaths = outputPaths;
                t.XmlContent = _xmlDocument;
                xslCompiledPath.ItemSpec = xslCompiledPath.ItemSpec + "bad;xslt";
                t.XslCompiledDllPath = xslCompiledPath;
                Assert.False(t.Execute()); // "XsltComiledDllBad execution should've failed"
                Console.WriteLine(engine.Log);
                Assert.True(engine.Log.Contains("MSB3704"));
                System.Diagnostics.Debug.WriteLine(engine.Log);
            }

            CleanUp(dir);
        }
コード例 #3
0
        public void BadXsltFile()
        {
            string dir;
            TaskItem[] xmlPaths;
            TaskItem xslPath;
            TaskItem xslCompiledPath;
            TaskItem[] outputPaths;
            List<KeyValuePair<XslTransformation.XmlInput.XmlModes, object>> xmlInputs;
            List<KeyValuePair<XslTransformation.XsltInput.XslModes, object>> xslInputs;
            MockEngine engine;
            Prepare(out dir, out xmlPaths, out xslPath, out xslCompiledPath, out outputPaths, out xmlInputs, out xslInputs, out engine);

            // load bad xslt
            {
                XslTransformation t = new XslTransformation();
                t.BuildEngine = engine;
                t.OutputPaths = outputPaths;
                t.XmlContent = _xmlDocument;
                t.XslContent = _errorXslDocument;
                try
                {
                    t.Execute();
                    Console.WriteLine(engine.Log);
                }
                catch (Exception e)
                {
                    Assert.True(e.Message.Contains("The '$' character"));
                }
            }

            CleanUp(dir);
        }
コード例 #4
0
        public void MissingOutputFile()
        {
            Assert.Throws<System.ArgumentNullException>(() =>
            {
                string dir;
                TaskItem[] xmlPaths;
                TaskItem xslPath;
                TaskItem xslCompiledPath;
                TaskItem[] outputPaths;
                List<KeyValuePair<XslTransformation.XmlInput.XmlModes, object>> xmlInputs;
                List<KeyValuePair<XslTransformation.XsltInput.XslModes, object>> xslInputs;
                MockEngine engine;
                Prepare(out dir, out xmlPaths, out xslPath, out xslCompiledPath, out outputPaths, out xmlInputs, out xslInputs, out engine);

                // load missing xml
                {
                    XslTransformation t = new XslTransformation();
                    t.BuildEngine = engine;
                    t.XmlInputPaths = xmlPaths;
                    t.XslInputPath = xslPath;
                    Assert.False(t.Execute()); // "This test should've failed (no output)."
                    Console.WriteLine(engine.Log);
                }

                CleanUp(dir);
            }
           );
        }
コード例 #5
0
        public void MultipleXmlInputs_Matching()
        {
            string dir;
            TaskItem[] xmlPaths;
            TaskItem xslPath;
            TaskItem xslCompiledPath;
            TaskItem[] outputPaths;
            List<KeyValuePair<XslTransformation.XmlInput.XmlModes, object>> xmlInputs;
            List<KeyValuePair<XslTransformation.XsltInput.XslModes, object>> xslInputs;
            MockEngine engine;
            Prepare(out dir, out xmlPaths, out xslPath, out xslCompiledPath, out outputPaths, out xmlInputs, out xslInputs, out engine);

            var otherXmlPath = new TaskItem(Path.Combine(dir, Guid.NewGuid().ToString()));
            using (StreamWriter sw = new StreamWriter(otherXmlPath.ItemSpec, false))
            {
                sw.Write(_xmlDocument2);
            }

            // xmlPaths have one XmlPath, lets duplicate it
            TaskItem[] xmlMultiPaths = new TaskItem[] { xmlPaths[0], otherXmlPath, xmlPaths[0], xmlPaths[0] };

            // outputPaths have one output path, lets duplicate it
            TaskItem[] outputMultiPaths = new TaskItem[] { new TaskItem(outputPaths[0].ItemSpec + ".1.xml"),
                new TaskItem(outputPaths[0].ItemSpec + ".2.xml"), new TaskItem(outputPaths[0].ItemSpec + ".3.xml"), new TaskItem(outputPaths[0].ItemSpec + ".4.xml") };

            {
                XslTransformation t = new XslTransformation();
                t.BuildEngine = engine;
                t.XslInputPath = xslPath;
                t.XmlInputPaths = xmlMultiPaths;
                t.OutputPaths = outputMultiPaths;
                Assert.True(t.Execute(), "CompiledDllWithTwoTypes execution should've passed" + engine.Log);
                Console.WriteLine(engine.Log);
                foreach (TaskItem tsk in t.OutputPaths)
                {
                    Assert.True(File.Exists(tsk.ItemSpec), tsk.ItemSpec + " should exist on output dir");
                }

                // The first and second input XML files are not equivalent, so their output files
                // should be different
                Assert.NotEqual(new FileInfo(xmlMultiPaths[0].ItemSpec).Length, new FileInfo(xmlMultiPaths[1].ItemSpec).Length);
                Assert.NotEqual(new FileInfo(outputMultiPaths[0].ItemSpec).Length, new FileInfo(outputMultiPaths[1].ItemSpec).Length);

                System.Diagnostics.Debug.WriteLine(engine.Log);
            }

            CleanUp(dir);
        }
コード例 #6
0
        public void XslDocumentFunctionWorks()
        {
            string dir;
            TaskItem[] xmlPaths;
            TaskItem xslPath;
            TaskItem xslCompiledPath;
            TaskItem[] outputPaths;
            List<KeyValuePair<XslTransformation.XmlInput.XmlModes, object>> xmlInputs;
            List<KeyValuePair<XslTransformation.XsltInput.XslModes, object>> xslInputs;
            MockEngine engine;
            Prepare(out dir, out xmlPaths, out xslPath, out xslCompiledPath, out outputPaths, out xmlInputs, out xslInputs, out engine);

            var otherXslPath = new TaskItem(Path.Combine(dir, Guid.NewGuid().ToString() + ".xslt"));
            using (StreamWriter sw = new StreamWriter(otherXslPath.ItemSpec, false))
            {
                sw.Write(_xslDocument2);
            }

            // Initialize first xml file for the XslTransformation task to consume
            var myXmlPath1 = new TaskItem(Path.Combine(dir, "a.xml"));
            using (StreamWriter sw = new StreamWriter(myXmlPath1.ItemSpec, false))
            {
                sw.Write("<document><myInclude path = \"b.xml\"/></document>");
            }

            // Initialize second xml file for the first one to consume
            var myXmlPath2 = new TaskItem(Path.Combine(dir, "b.xml"));
            using (StreamWriter sw = new StreamWriter(myXmlPath2.ItemSpec, false))
            {
                sw.Write("<stuff/>");
            }

            // Validate that execution passes when UseTrustedSettings is true
            XslTransformation t = new XslTransformation();
            t.BuildEngine = engine;
            t.OutputPaths = outputPaths;
            t.XmlInputPaths = new TaskItem[] { myXmlPath1 };
            t.XslInputPath = otherXslPath;
            t.UseTrustedSettings = true;

            Assert.True(t.Execute()); // "Test should have passed and allowed the use of the document() function within the xslt file"

            // Validate that execution fails when UseTrustedSettings is false
            t = new XslTransformation();
            t.BuildEngine = engine;
            t.OutputPaths = outputPaths;
            t.XmlInputPaths = new TaskItem[] { myXmlPath1 };
            t.XslInputPath = otherXslPath;
            t.UseTrustedSettings = false;

            Assert.False(t.Execute()); // "Test should have failed and not allowed the use of the document() function within the xslt file"

            CleanUp(dir);
        }
コード例 #7
0
        public void XsltParametersIncorrect()
        {
            string dir;
            TaskItem[] xmlPaths;
            TaskItem xslPath;
            TaskItem xslCompiledPath;
            TaskItem[] outputPaths;
            List<KeyValuePair<XslTransformation.XmlInput.XmlModes, object>> xmlInputs;
            List<KeyValuePair<XslTransformation.XsltInput.XslModes, object>> xslInputs;
            MockEngine engine;
            Prepare(out dir, out xmlPaths, out xslPath, out xslCompiledPath, out outputPaths, out xmlInputs, out xslInputs, out engine);

            // Test Xslt Parameters
            {
                string[] attrs = new string[] { "Name=\"param2\"", "Namespace=\"http://eksiduyuru.com\"", "Value=\"2\"" };
                for (int i = 0; i < Math.Pow(2, attrs.Length); i++)
                {
                    string res = "";
                    for (int k = 0; k < attrs.Length; k++)
                    {
                        if ((i & (int)Math.Pow(2, k)) != 0)
                        {
                            res += attrs[k] + " ";
                        }
                    }

                    XslTransformation t = new XslTransformation();
                    t.BuildEngine = engine;
                    t.OutputPaths = outputPaths;
                    t.XmlContent = _xmlDocument;
                    t.XslContent = _xslParameterDocument;
                    t.Parameters = "<Parameter " + res + "/>";
                    Assert.True(t.Parameters.Equals("<Parameter " + res + "/>"));
                    bool result = t.Execute();
                    Console.WriteLine(engine.Log);

                    if (i == 5 || i == 7)
                    {
                        Assert.True(result); // "Only 5th and 7th values should pass."
                    }
                    else
                    {
                        Assert.False(result); // "Only 5th and 7th values should pass."
                    }
                }
            }

            CleanUp(dir);
        }
コード例 #8
0
        public void XsltDocumentThrowsError()
        {
            string dir;
            TaskItem[] xmlPaths;
            TaskItem xslPath;
            TaskItem xslCompiledPath;
            TaskItem[] outputPaths;
            List<KeyValuePair<XslTransformation.XmlInput.XmlModes, object>> xmlInputs;
            List<KeyValuePair<XslTransformation.XsltInput.XslModes, object>> xslInputs;
            MockEngine engine;
            Prepare(out dir, out xmlPaths, out xslPath, out xslCompiledPath, out outputPaths, out xmlInputs, out xslInputs, out engine);

            // load error xslDocument
            {
                XslTransformation t = new XslTransformation();
                t.BuildEngine = engine;
                t.OutputPaths = outputPaths;
                t.XmlContent = _xmlDocument;
                t.XslContent = _errorXslDocument2;
                try
                {
                    Assert.False(t.Execute()); // "This test should've failed (xsl with error)."
                    Console.WriteLine(engine.Log);
                }
                catch (Exception e)
                {
                    Assert.True(e.Message.Contains("error?"));
                }
            }

            CleanUp(dir);
        }
コード例 #9
0
        public void OutputTest()
        {
            string dir;
            TaskItem[] xmlPaths;
            TaskItem xslPath;
            TaskItem xslCompiledPath;
            TaskItem[] outputPaths;
            List<KeyValuePair<XslTransformation.XmlInput.XmlModes, object>> xmlInputs;
            List<KeyValuePair<XslTransformation.XsltInput.XslModes, object>> xslInputs;
            MockEngine engine;
            Prepare(out dir, out xmlPaths, out xslPath, out xslCompiledPath, out outputPaths, out xmlInputs, out xslInputs, out engine);

            // Test Out
            {
                XslTransformation t = new XslTransformation();
                t.BuildEngine = engine;
                t.XmlContent = _xmlDocument;
                t.XslContent = _xslDocument;
                t.OutputPaths = outputPaths;
                Assert.True(t.Execute()); // "Test out should have given true when executed"
                Assert.True(engine.Log.Equals(String.Empty)); // "The log should be empty"
                Console.WriteLine(engine.Log);
                using (StreamReader sr = new StreamReader(t.OutputPaths[0].ItemSpec))
                {
                    string fileContents = sr.ReadToEnd();
                    MatchCollection mc = _surroundMatch.Matches(fileContents);
                    Assert.Equal(8, mc.Count); // "The file test doesn't match"
                }
            }

            CleanUp(dir);
        }
コード例 #10
0
        public void XsltParamatersCorrect()
        {
            string dir;
            TaskItem[] xmlPaths;
            TaskItem xslPath;
            TaskItem xslCompiledPath;
            TaskItem[] outputPaths;
            List<KeyValuePair<XslTransformation.XmlInput.XmlModes, object>> xmlInputs;
            List<KeyValuePair<XslTransformation.XsltInput.XslModes, object>> xslInputs;
            MockEngine engine;
            Prepare(out dir, out xmlPaths, out xslPath, out xslCompiledPath, out outputPaths, out xmlInputs, out xslInputs, out engine);

            // Test Correct Xslt Parameters
            {
                XslTransformation t = new XslTransformation();
                t.BuildEngine = engine;
                t.OutputPaths = outputPaths;
                t.XmlContent = _xmlDocument;
                t.XslContent = _xslParameterDocument;
                t.Parameters = _xslParameters;
                t.Execute();
                Console.WriteLine(engine.Log);
                using (StreamReader sr = new StreamReader(t.OutputPaths[0].ItemSpec))
                {
                    string fileContents = sr.ReadToEnd();
                    Assert.True(fileContents.Contains("param 1: 1param 2: 2"));
                }
            }

            CleanUp(dir);
        }
コード例 #11
0
        public void ManyXslParameters()
        {
            string dir;
            TaskItem[] xmlPaths;
            TaskItem xslPath;
            TaskItem xslCompiledPath;
            TaskItem[] outputPaths;
            List<KeyValuePair<XslTransformation.XmlInput.XmlModes, object>> xmlInputs;
            List<KeyValuePair<XslTransformation.XsltInput.XslModes, object>> xslInputs;
            MockEngine engine;
            Prepare(out dir, out xmlPaths, out xslPath, out xslCompiledPath, out outputPaths, out xmlInputs, out xslInputs, out engine);

            // Test too many Xsl.
            {
                XslTransformation t = new XslTransformation();
                t.BuildEngine = engine;
                t.OutputPaths = outputPaths;
                t.XmlContent = _xmlDocument;
                t.XslContent = _xslDocument;
                t.XslInputPath = xslPath;
                Assert.True(t.XslContent.Equals(_xslDocument));
                Assert.True(t.XslInputPath.Equals(xslPath));
                Assert.False(t.Execute()); // "The test should fail when there are too many files"
                Console.WriteLine(engine.Log);
                Assert.True(engine.Log.Contains("MSB3701")); // "The output should contain MSB3701 error message at no params test"
            }

            CleanUp(dir);
        }
コード例 #12
0
        public void MissingXmlXslParameter()
        {
            string dir;
            TaskItem[] xmlPaths;
            TaskItem xslPath;
            TaskItem xslCompiledPath;
            TaskItem[] outputPaths;
            List<KeyValuePair<XslTransformation.XmlInput.XmlModes, object>> xmlInputs;
            List<KeyValuePair<XslTransformation.XsltInput.XslModes, object>> xslInputs;
            MockEngine engine;
            Prepare(out dir, out xmlPaths, out xslPath, out xslCompiledPath, out outputPaths, out xmlInputs, out xslInputs, out engine);

            // Test both missing.
            {
                XslTransformation t = new XslTransformation();
                t.BuildEngine = engine;
                t.OutputPaths = outputPaths;

                Assert.False(t.Execute()); // "The test should fail when there is no params"
                Console.WriteLine(engine.Log);
                Assert.True(engine.Log.Contains("MSB3701")); // "The output should contain MSB3701 error message"
            }

            CleanUp(dir);
        }
コード例 #13
0
        public void MissingXmlParameter()
        {
            string dir;
            TaskItem[] xmlPaths;
            TaskItem xslPath;
            TaskItem xslCompiledPath;
            TaskItem[] outputPaths;
            List<KeyValuePair<XslTransformation.XmlInput.XmlModes, object>> xmlInputs;
            List<KeyValuePair<XslTransformation.XsltInput.XslModes, object>> xslInputs;
            MockEngine engine;
            Prepare(out dir, out xmlPaths, out xslPath, out xslCompiledPath, out outputPaths, out xmlInputs, out xslInputs, out engine);

            // Test Xml missing.
            for (int xsi = 0; xsi < xslInputs.Count; xsi++)
            {
                XslTransformation t = new XslTransformation();
                t.BuildEngine = engine;
                t.OutputPaths = outputPaths;

                XslTransformation.XsltInput.XslModes xslKey = xslInputs[xsi].Key;
                object xslValue = xslInputs[xsi].Value;
                switch (xslKey)
                {
                    case XslTransformation.XsltInput.XslModes.Xslt:
                        t.XslContent = (string)xslValue;
                        break;
                    case XslTransformation.XsltInput.XslModes.XsltFile:
                        t.XslInputPath = (TaskItem)xslValue;
                        break;
                    case XslTransformation.XsltInput.XslModes.XsltCompiledDll:
                        t.XslCompiledDllPath = (TaskItem)xslValue;
                        break;
                    default:
                        Assert.True(false, "Test error");
                        break;
                }

                Assert.False(t.Execute()); // "The test should fail when there is missing Xml params"
                Console.WriteLine(engine.Log);
                Assert.True(engine.Log.Contains("MSB3701")); // "The output should contain MSB3701 error message at missing Xml params test"
                engine.Log = "";
            }

            CleanUp(dir);
        }
コード例 #14
0
        public void BadXmlAsParameter()
        {
            string dir;
            TaskItem[] xmlPaths;
            TaskItem xslPath;
            TaskItem xslCompiledPath;
            TaskItem[] outputPaths;
            List<KeyValuePair<XslTransformation.XmlInput.XmlModes, object>> xmlInputs;
            List<KeyValuePair<XslTransformation.XsltInput.XslModes, object>> xslInputs;
            MockEngine engine;
            Prepare(out dir, out xmlPaths, out xslPath, out xslCompiledPath, out outputPaths, out xmlInputs, out xslInputs, out engine);

            // load bad xml on parameters
            {
                XslTransformation t = new XslTransformation();
                t.BuildEngine = engine;
                t.OutputPaths = outputPaths;
                t.XmlContent = _xmlDocument;
                t.XslContent = _xslParameterDocument;
                t.Parameters = "<<>>";
                try
                {
                    Assert.False(t.Execute()); // "This test should've failed (bad params1)."
                    Console.WriteLine(engine.Log);
                }
                catch (Exception e)
                {
                    Assert.True(e.Message.Contains("'<'"));
                }
            }

            CleanUp(dir);
        }
コード例 #15
0
        public void EmptyParameters()
        {
            string dir;
            TaskItem[] xmlPaths;
            TaskItem xslPath;
            TaskItem xslCompiledPath;
            TaskItem[] outputPaths;
            List<KeyValuePair<XslTransformation.XmlInput.XmlModes, object>> xmlInputs;
            List<KeyValuePair<XslTransformation.XsltInput.XslModes, object>> xslInputs;
            MockEngine engine;
            Prepare(out dir, out xmlPaths, out xslPath, out xslCompiledPath, out outputPaths, out xmlInputs, out xslInputs, out engine);

            // load empty parameters
            {
                XslTransformation t = new XslTransformation();
                t.BuildEngine = engine;
                t.OutputPaths = outputPaths;
                t.XmlInputPaths = xmlPaths;
                t.XslInputPath = xslPath;
                t.Parameters = "   ";
                Assert.True(t.Execute()); // "This test should've passed (empty parameters)."
                Console.WriteLine(engine.Log);
            }

            CleanUp(dir);
        }
コード例 #16
0
        public void OutputFileCannotBeWritten()
        {
            string dir;
            TaskItem[] xmlPaths;
            TaskItem xslPath;
            TaskItem xslCompiledPath;
            TaskItem[] outputPaths;
            List<KeyValuePair<XslTransformation.XmlInput.XmlModes, object>> xmlInputs;
            List<KeyValuePair<XslTransformation.XsltInput.XslModes, object>> xslInputs;
            MockEngine engine;
            Prepare(out dir, out xmlPaths, out xslPath, out xslCompiledPath, out outputPaths, out xmlInputs, out xslInputs, out engine);

            // load bad output
            {
                XslTransformation t = new XslTransformation();
                t.BuildEngine = engine;
                t.OutputPaths = outputPaths;
                t.XmlContent = _xmlDocument;
                t.XslContent = _xslDocument;
                t.OutputPaths = new TaskItem[] { new TaskItem("k:\\folder\\file.xml") };
                try
                {
                    Assert.False(t.Execute()); // "This test should've failed (bad output)."
                    Console.WriteLine(engine.Log);
                }
                catch (Exception e)
                {
                    Assert.True(e.Message.Contains("MSB3701"));
                }
            }

            CleanUp(dir);
        }
コード例 #17
0
        public void CompiledDllWithType()
        {
            string dir;
            TaskItem[] xmlPaths;
            TaskItem xslPath;
            TaskItem xslCompiledPath;
            TaskItem[] outputPaths;
            List<KeyValuePair<XslTransformation.XmlInput.XmlModes, object>> xmlInputs;
            List<KeyValuePair<XslTransformation.XsltInput.XslModes, object>> xslInputs;
            MockEngine engine;
            Prepare(out dir, out xmlPaths, out xslPath, out xslCompiledPath, out outputPaths, out xmlInputs, out xslInputs, out engine);

            // Test Compiled DLLs

            // with type specified.
            {
                XslTransformation t = new XslTransformation();
                t.BuildEngine = engine;
                t.OutputPaths = outputPaths;
                t.XmlContent = _xmlDocument;
                xslCompiledPath.ItemSpec = xslCompiledPath.ItemSpec + ";xslt";
                t.XslCompiledDllPath = xslCompiledPath;
                Assert.True(t.XslCompiledDllPath.ItemSpec.Equals(xslCompiledPath.ItemSpec));
                Assert.True(t.Execute()); // "XsltComiledDll1 execution should've passed"
                Console.WriteLine(engine.Log);
                Assert.False(engine.Log.Contains("MSB")); // "The log should not contain any errors. (XsltComiledDll1)"
            }

            CleanUp(dir);
        }
コード例 #18
0
        public void CompiledDllWithTwoTypes()
        {
            string dir;
            TaskItem[] xmlPaths;
            TaskItem xslPath;
            TaskItem xslCompiledPath;
            TaskItem[] outputPaths;
            List<KeyValuePair<XslTransformation.XmlInput.XmlModes, object>> xmlInputs;
            List<KeyValuePair<XslTransformation.XsltInput.XslModes, object>> xslInputs;
            MockEngine engine;
            Prepare(out dir, out xmlPaths, out xslPath, out xslCompiledPath, out outputPaths, out xmlInputs, out xslInputs, out engine);

            // doubletype
            string doubleTypePath = Path.Combine(dir, "double.dll");
            CompileDoubleType(doubleTypePath);
            {
                XslTransformation t = new XslTransformation();
                t.BuildEngine = engine;
                t.OutputPaths = outputPaths;
                t.XmlContent = _xmlDocument;
                t.XslCompiledDllPath = new TaskItem(doubleTypePath);
                try
                {
                    t.Execute();
                    Console.WriteLine(engine.Log);
                }
                catch (Exception e)
                {
                    Assert.True(e.Message.Contains("error?"));
                }

                System.Diagnostics.Debug.WriteLine(engine.Log);
            }

            CleanUp(dir);
        }
コード例 #19
0
        public void CompiledDllWithoutType()
        {
            string dir;
            TaskItem[] xmlPaths;
            TaskItem xslPath;
            TaskItem xslCompiledPath;
            TaskItem[] outputPaths;
            List<KeyValuePair<XslTransformation.XmlInput.XmlModes, object>> xmlInputs;
            List<KeyValuePair<XslTransformation.XsltInput.XslModes, object>> xslInputs;
            MockEngine engine;
            Prepare(out dir, out xmlPaths, out xslPath, out xslCompiledPath, out outputPaths, out xmlInputs, out xslInputs, out engine);

            // without type specified.
            {
                XslTransformation t = new XslTransformation();
                t.BuildEngine = engine;
                t.OutputPaths = outputPaths;
                t.XmlContent = _xmlDocument;
                t.XslCompiledDllPath = xslCompiledPath;
                Assert.True(t.Execute(), "XsltComiledDll2 execution should've passed" + engine.Log);
                Console.WriteLine(engine.Log);
                Assert.False(engine.MockLogger.ErrorCount > 0); // "The log should not contain any errors. (XsltComiledDll2)"
            }

            CleanUp(dir);
        }
コード例 #20
0
        public void MultipleXmlInputs_NotMatching()
        {
            string dir;
            TaskItem[] xmlPaths;
            TaskItem xslPath;
            TaskItem xslCompiledPath;
            TaskItem[] outputPaths;
            List<KeyValuePair<XslTransformation.XmlInput.XmlModes, object>> xmlInputs;
            List<KeyValuePair<XslTransformation.XsltInput.XslModes, object>> xslInputs;
            MockEngine engine;
            Prepare(out dir, out xmlPaths, out xslPath, out xslCompiledPath, out outputPaths, out xmlInputs, out xslInputs, out engine);

            // xmlPaths have one XmlPath, lets duplicate it **4 times **
            TaskItem[] xmlMultiPaths = new TaskItem[] { xmlPaths[0], xmlPaths[0], xmlPaths[0], xmlPaths[0] };

            // outputPaths have one output path, lets duplicate it **3 times **
            TaskItem[] outputMultiPathsShort = new TaskItem[] { new TaskItem(outputPaths[0].ItemSpec + ".1.xml"),
                new TaskItem(outputPaths[0].ItemSpec + ".2.xml"),
                new TaskItem(outputPaths[0].ItemSpec + ".3.xml") };

            TaskItem[] outputMultiPathsLong = new TaskItem[] { new TaskItem(outputPaths[0].ItemSpec + ".1.xml"),
                new TaskItem(outputPaths[0].ItemSpec + ".2.xml"),
                new TaskItem(outputPaths[0].ItemSpec + ".3.xml"),
                new TaskItem(outputPaths[0].ItemSpec + ".4.xml"),
                new TaskItem(outputPaths[0].ItemSpec + ".5.xml") };
            // Short version.
            {
                XslTransformation t = new XslTransformation();
                t.BuildEngine = engine;
                t.XslInputPath = xslPath;
                t.XmlInputPaths = xmlMultiPaths;
                t.OutputPaths = outputMultiPathsShort;
                Assert.False(t.Execute(), "CompiledDllWithTwoTypes execution should've failed" + engine.Log);

                System.Diagnostics.Debug.WriteLine(engine.Log);
            }

            // Long version
            {
                XslTransformation t = new XslTransformation();
                t.BuildEngine = engine;
                t.XslInputPath = xslPath;
                t.XmlInputPaths = xmlMultiPaths;
                t.OutputPaths = outputMultiPathsLong;
                Assert.False(t.Execute(), "CompiledDllWithTwoTypes execution should've failed" + engine.Log);
                Console.WriteLine(engine.Log);

                System.Diagnostics.Debug.WriteLine(engine.Log);
            }

            CleanUp(dir);
        }
コード例 #21
0
        public void XmlXslParameters()
        {
            string dir;
            TaskItem[] xmlPaths;
            TaskItem xslPath;
            TaskItem xslCompiledPath;
            TaskItem[] outputPaths;
            List<KeyValuePair<XslTransformation.XmlInput.XmlModes, object>> xmlInputs;
            List<KeyValuePair<XslTransformation.XsltInput.XslModes, object>> xslInputs;
            MockEngine engine;
            Prepare(out dir, out xmlPaths, out xslPath, out xslCompiledPath, out outputPaths, out xmlInputs, out xslInputs, out engine);

            // Test when Xml and Xsl parameters are correct
            for (int xmi = 0; xmi < xmlInputs.Count; xmi++)
            {
                for (int xsi = 0; xsi < xslInputs.Count; xsi++)
                {
                    XslTransformation t = new XslTransformation();
                    t.BuildEngine = engine;
                    t.OutputPaths = outputPaths;
                    XslTransformation.XmlInput.XmlModes xmlKey = xmlInputs[xmi].Key;
                    object xmlValue = xmlInputs[xmi].Value;
                    XslTransformation.XsltInput.XslModes xslKey = xslInputs[xsi].Key;
                    object xslValue = xslInputs[xsi].Value;

                    switch (xmlKey)
                    {
                        case XslTransformation.XmlInput.XmlModes.Xml:
                            t.XmlContent = (string)xmlValue;
                            break;
                        case XslTransformation.XmlInput.XmlModes.XmlFile:
                            t.XmlInputPaths = (TaskItem[])xmlValue;
                            break;
                        default:
                            Assert.True(false, "Test error");
                            break;
                    }

                    switch (xslKey)
                    {
                        case XslTransformation.XsltInput.XslModes.Xslt:
                            t.XslContent = (string)xslValue;
                            break;
                        case XslTransformation.XsltInput.XslModes.XsltFile:
                            t.XslInputPath = (TaskItem)xslValue;
                            break;
                        case XslTransformation.XsltInput.XslModes.XsltCompiledDll:
                            t.XslCompiledDllPath = (TaskItem)xslValue;
                            break;
                        default:
                            Assert.True(false, "Test error");
                            break;
                    }

                    Assert.True(t.Execute()); // "The test should have passed at the both params correct test"
                }
            }

            CleanUp(dir);
        }