Exemplo n.º 1
0
        public void PeekWithNamespaceNode()
        {
            MockEngine engine = new MockEngine(true);
            string     xmlInputPath;

            Prepare(_xmlFileWithNs, out xmlInputPath);

            XmlPeek p = new XmlPeek();

            p.BuildEngine = engine;

            p.XmlInputPath = new TaskItem(xmlInputPath);
            p.Query        = "//s:variable/.";
            p.Namespaces   = "<Namespace Prefix=\"s\" Uri=\"http://nsurl\" />";

            Assert.True(p.Execute());         // "Test should've passed"
            Assert.Equal(3, p.Result.Length); // "result Length should be 3"

            string[] results = new string[] {
                "<s:variable Type=\"String\" Name=\"a\" xmlns:s=\"http://nsurl\"></s:variable>",
                "<s:variable Type=\"String\" Name=\"b\" xmlns:s=\"http://nsurl\"></s:variable>",
                "<s:variable Type=\"String\" Name=\"c\" xmlns:s=\"http://nsurl\"></s:variable>"
            };

            for (int i = 0; i < p.Result.Length; i++)
            {
                Assert.Equal(p.Result[i].ItemSpec, results[i]);
            }
        }
Exemplo n.º 2
0
        public void PeekWithNamespaceText()
        {
            MockEngine engine = new MockEngine(true);
            string     xmlInputPath;

            Prepare(_xmlFileWithNsWithText, out xmlInputPath);

            XmlPeek p = new XmlPeek();

            p.BuildEngine = engine;

            p.XmlInputPath = new TaskItem(xmlInputPath);
            p.Query        = "//s:variable/text()";
            p.Namespaces   = "<Namespace Prefix=\"s\" Uri=\"http://nsurl\" />";
            Assert.Equal("<Namespace Prefix=\"s\" Uri=\"http://nsurl\" />", p.Namespaces);
            Assert.True(p.Execute());         // "Test should've passed"
            Assert.Equal(3, p.Result.Length); // "result Length should be 3"

            string[] results = new string[] {
                "This",
                "is",
                "Sparta!"
            };

            for (int i = 0; i < p.Result.Length; i++)
            {
                Assert.Equal(p.Result[i].ItemSpec, results[i]);
            }
        }
Exemplo n.º 3
0
        public void PeekNoNSWPrefixedQueryError()
        {
            MockEngine engine = new MockEngine(true);
            string     xmlInputPath;

            Prepare(_xmlFileNoNsNoDtd, out xmlInputPath);

            XmlPeek p = new XmlPeek();

            p.BuildEngine = engine;

            p.XmlInputPath = new TaskItem(xmlInputPath);
            p.Query        = "//s:variable/@Name";

            Assert.False(p.Execute());              // "Test should've failed"
            Assert.Contains("MSB3743", engine.Log); // "Engine log should contain error code MSB3743"
        }
Exemplo n.º 4
0
        public void PeekNoNSXmlContentAndXmlInputError2()
        {
            MockEngine engine = new MockEngine(true);

            string xmlInputPath;

            Prepare(_xmlFileNoNsNoDtd, out xmlInputPath);

            XmlPeek p = new XmlPeek();

            p.BuildEngine = engine;

            p.Query = "//variable/@Name";

            Assert.False(p.Execute());              // "Test should've failed"
            Assert.Contains("MSB3741", engine.Log); // "Error message MSB3741 should fire"
        }
Exemplo n.º 5
0
        public void PeekDtdWhenDtdProhibitedError()
        {
            MockEngine engine = new MockEngine(true);
            string     xmlInputPath;

            Prepare(_xmlFileWithNs, out xmlInputPath);

            XmlPeek p = new XmlPeek();

            p.BuildEngine = engine;

            p.ProhibitDtd  = true;
            p.XmlInputPath = new TaskItem(xmlInputPath);
            p.Query        = "//s:variable/@Name";

            Assert.False(p.Execute());              // "Test should've failed"
            Assert.Contains("MSB3733", engine.Log); // "Engine log should contain error code MSB3733"
        }
Exemplo n.º 6
0
        public void ErrorInNamespaceDecl()
        {
            MockEngine engine = new MockEngine(true);
            string     xmlInputPath;

            Prepare(_xmlFileWithNs, out xmlInputPath);

            XmlPeek p = new XmlPeek();

            p.BuildEngine  = engine;
            p.XmlInputPath = new TaskItem(xmlInputPath);
            p.Query        = "//s:variable/@Name";
            p.Namespaces   = "<!THIS IS ERROR Namespace Prefix=\"s\" Uri=\"http://nsurl\" />";

            bool executeResult = p.Execute();

            Assert.True(engine.Log.Contains("MSB3742"), "Engine Log: " + engine.Log);
            Assert.False(executeResult); // "Execution should've failed"
        }
Exemplo n.º 7
0
        public void PeekNoNSXmlContent()
        {
            MockEngine engine = new MockEngine(true);

            XmlPeek p = new XmlPeek();

            p.BuildEngine = engine;

            p.XmlContent = _xmlFileNoNsNoDtd;
            p.Query      = "//variable/@Name";

            Assert.True(p.Execute());         // "Test should've passed"
            Assert.Equal(3, p.Result.Length); // "result Length should be 3"
            string[] results = new string[] { "a", "b", "c" };
            for (int i = 0; i < p.Result.Length; i++)
            {
                Assert.Equal(p.Result[i].ItemSpec, results[i]);
            }
        }
Exemplo n.º 8
0
        public void PeekNoNSXmlContent()
        {
            MockEngine engine = new MockEngine(true);

            XmlPeek p = new XmlPeek();

            p.BuildEngine = engine;

            p.XmlContent = _xmlFileNoNs;
            p.Query      = "//variable/@Name";

            Assert.IsTrue(p.Execute(), "Test should've passed");
            Assert.IsTrue(p.Result.Length == 3, "result Length should be 3");
            string[] results = new string[] { "a", "b", "c" };
            for (int i = 0; i < p.Result.Length; i++)
            {
                Assert.IsTrue(p.Result[i].ItemSpec.Equals(results[i]), "Results don't match: " + p.Result[i].ItemSpec);
            }
        }
        public void PeekNoNamespace()
        {
            MockEngine engine = new MockEngine(true);
            string     xmlInputPath;

            Prepare(_xmlFileNoNsNoDtd, out xmlInputPath);

            XmlPeek p = new XmlPeek();

            p.BuildEngine = engine;

            p.XmlInputPath = new TaskItem(xmlInputPath);
            p.Query        = "//variable/@Name";

            Assert.True(p.Execute());         // "Test should've passed"
            Assert.Equal(3, p.Result.Length); // "result Length should be 3"
            string[] results = new string[] { "a", "b", "c" };
            for (int i = 0; i < p.Result.Length; i++)
            {
                Assert.True(p.Result[i].ItemSpec.Equals(results[i]), "Results don't match: " + p.Result[i].ItemSpec);
            }
        }
        public void PeekWithNamespaceAttribute()
        {
            MockEngine engine = new MockEngine(true);
            string     xmlInputPath;

            Prepare(_xmlFileWithNs, out xmlInputPath);

            XmlPeek p = new XmlPeek();

            p.BuildEngine = engine;

            p.XmlInputPath = new TaskItem(xmlInputPath);
            p.Query        = "//s:variable/@Name";
            p.Namespaces   = "<Namespace Prefix=\"s\" Uri=\"http://nsurl\" />";

            Assert.True(p.Execute());         // "Test should've passed"
            Assert.Equal(3, p.Result.Length); // "result Length should be 3"
            string[] results = new string[] { "a", "b", "c" };
            for (int i = 0; i < p.Result.Length; i++)
            {
                Assert.True(p.Result[i].ItemSpec.Equals(results[i]), "Results don't match: " + p.Result[i].ItemSpec);
            }
        }
        public void PeekNoNSXmlContentAndXmlInputError1()
        {
            MockEngine engine = new MockEngine(true);

            string xmlInputPath;

            Prepare(_xmlFileNoNsNoDtd, out xmlInputPath);

            XmlPeek p = new XmlPeek();

            p.BuildEngine = engine;

            p.XmlInputPath = new TaskItem(xmlInputPath);
            p.XmlContent   = _xmlFileNoNsNoDtd;
            Assert.True(p.XmlInputPath.ItemSpec.Equals(xmlInputPath));
            Assert.True(p.XmlContent.Equals(_xmlFileNoNsNoDtd));

            p.Query = "//variable/@Name";
            Assert.True(p.Query.Equals("//variable/@Name"));

            Assert.False(p.Execute());                   // "Test should've failed"
            Assert.True(engine.Log.Contains("MSB3741")); // "Error message MSB3741 should fire"
        }
Exemplo n.º 12
0
        public void MissingNamespaceParameters()
        {
            MockEngine engine = new MockEngine(true);
            string     xmlInputPath;

            Prepare(_xmlFileWithNs, out xmlInputPath);

            string[] attrs = new string[] { "Prefix=\"s\"", "Uri=\"http://nsurl\"" };
            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] + " ";
                    }
                }
                XmlPeek p = new XmlPeek();
                p.BuildEngine  = engine;
                p.XmlInputPath = new TaskItem(xmlInputPath);
                p.Query        = "//s:variable/@Name";
                p.Namespaces   = "<Namespace " + res + " />";

                bool result = p.Execute();
                Console.WriteLine(engine.Log);

                if (i == 3)
                {
                    Assert.True(result); // "Only 3rd value should pass."
                }
                else
                {
                    Assert.False(result); // "Only 3rd value should pass."
                }
            }
        }