Exemplo n.º 1
0
        public void PokeWithNamespace()
        {
            MockEngine engine = new MockEngine(true);
            string xmlInputPath;
            Prepare(_xmlFileWithNs, out xmlInputPath);

            XmlPoke p = new XmlPoke();
            p.BuildEngine = engine;
            p.XmlInputPath = new TaskItem(xmlInputPath);
            p.Query = "//s:variable/@Name";
            p.Namespaces = "<Namespace Prefix=\"s\" Uri=\"http://nurl\" />";
            p.Value = new TaskItem("Mert");
            p.Execute();

            List<int> positions = new List<int>();
            positions.AddRange(new int[] { 141, 200, 259 });

            string result;
            using (StreamReader sr = new StreamReader(xmlInputPath))
            {
                result = sr.ReadToEnd();
                Regex r = new Regex("Mert");
                MatchCollection mc = r.Matches(result);

                foreach (Match m in mc)
                {
                    Assert.True(positions.Contains(m.Index), "This test should effect 3 positions. There should be 3 occurances of 'Mert'\n" + result);
                }
            }
        }
Exemplo n.º 2
0
        public void ErrorInNamespaceDecl()
        {
            MockEngine engine = new MockEngine(true);
            string xmlInputPath;
            Prepare(_xmlFileWithNs, out xmlInputPath);

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

            bool executeResult = p.Execute();
            Assert.IsTrue(engine.Log.Contains("MSB3731"));
            Assert.IsFalse(executeResult, "Execution should've failed");
        }
Exemplo n.º 3
0
        public void PokeElement()
        {
            MockEngine engine = new MockEngine(true);
            string xmlInputPath;
            Prepare(_xmlFileNoNs, out xmlInputPath);

            XmlPoke p = new XmlPoke();
            p.BuildEngine = engine;
            p.XmlInputPath = new TaskItem(xmlInputPath);
            Assert.True(p.XmlInputPath.ItemSpec.Equals(xmlInputPath));
            p.Query = "//variable/.";
            Assert.True(p.Query.Equals("//variable/."));
            string valueString = "<testing the=\"element\">With<somewhat complex=\"value\" /></testing>";
            p.Value = new TaskItem(valueString);
            Assert.True(p.Value.ItemSpec.Equals(valueString));

            Assert.True(p.Execute());

            List<int> positions = new List<int>();
            positions.AddRange(new int[] { 126, 249, 372 });

            string result;
            using (StreamReader sr = new StreamReader(xmlInputPath))
            {
                result = sr.ReadToEnd();

                Regex r = new Regex("<testing the=\"element\">With<somewhat complex=\"value\" /></testing>");
                MatchCollection mc = r.Matches(result);

                foreach (Match m in mc)
                {
                    Assert.True(positions.Contains(m.Index), "This test should effect 3 positions. There should be 3 occurances of 'Mert'\n" + result);
                }
            }
        }
Exemplo n.º 4
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] + " ";
                    }
                }
                XmlPoke p = new XmlPoke();
                p.BuildEngine = engine;
                p.XmlInputPath = new TaskItem(xmlInputPath);
                p.Query = "//s:variable/@Name";
                p.Namespaces = "<Namespace " + res + " />";
                p.Value = new TaskItem("Nur");

                bool result = p.Execute();

                if (i == 3)
                {
                    Assert.True(result); // "Only 3rd value should pass."
                }
                else
                {
                    Assert.False(result); // "Only 3rd value should pass."
                }
            }
        }
Exemplo n.º 5
0
        public void PokeNoNSWPrefixedQueryError()
        {
            MockEngine engine = new MockEngine(true);
            string xmlInputPath;
            Prepare(_xmlFileNoNs, out xmlInputPath);

            XmlPoke p = new XmlPoke();
            p.BuildEngine = engine;

            p.XmlInputPath = new TaskItem(xmlInputPath);
            p.Query = "//s:variable/@Name";
            p.Value = new TaskItem("Nur");
            Assert.False(p.Execute()); // "Test should've failed"
            Assert.True(engine.Log.Contains("MSB3732"), "Engine log should contain error code MSB3732 " + engine.Log);
        }
Exemplo n.º 6
0
        public void PokeMissingParams()
        {
            MockEngine engine = new MockEngine(true);
            string xmlInputPath;
            Prepare(_xmlFileNoNs, out xmlInputPath);

            for (int i = 0; i < 8; i++)
            {
                XmlPoke p = new XmlPoke();
                p.BuildEngine = engine;

                if ((i & 1) == 1)
                {
                    p.XmlInputPath = new TaskItem(xmlInputPath);
                }

                if ((i & 2) == 2)
                {
                    p.Query = "//variable/@Name";
                }

                if ((i & 4) == 4)
                {
                    p.Value = new TaskItem("Mert");
                }

                bool exceptionThrown = false;
                try
                {
                    p.Execute();
                }
                catch (ArgumentNullException)
                {
                    exceptionThrown = true;
                }

                if (i < 7)
                {
                    Assert.True(exceptionThrown); // "Expecting argumentnullexception for the first 7 tests"
                }
                else
                {
                    Assert.False(exceptionThrown); // "Expecting argumentnullexception for the first 7 tests"
                }
            }
        }
Exemplo n.º 7
0
        public void PokeChildren()
        {
            MockEngine engine = new MockEngine(true);
            string xmlInputPath;
            Prepare(_xmlFileNoNs, out xmlInputPath);

            XmlPoke p = new XmlPoke();
            p.BuildEngine = engine;
            p.XmlInputPath = new TaskItem(xmlInputPath);
            p.Query = "//class/.";
            p.Value = new TaskItem("<Test>Testing</Test>");
            Assert.True(p.Execute(), engine.Log);

            string result;
            using (StreamReader sr = new StreamReader(xmlInputPath))
            {
                result = sr.ReadToEnd();

                Regex r = new Regex("<Test>Testing</Test>");
                MatchCollection mc = r.Matches(result);

                Assert.Equal(1, mc.Count); // "Should match once"
            }
        }
Exemplo n.º 8
0
        public void PokeAttribute()
        {
            MockEngine engine = new MockEngine(true);
            string xmlInputPath;
            Prepare(_xmlFileNoNs, out xmlInputPath);

            XmlPoke p = new XmlPoke();
            p.BuildEngine = engine;
            p.XmlInputPath = new TaskItem(xmlInputPath);
            p.Query = "//class[1]/@AccessModifier";
            p.Value = new TaskItem("<Test>Testing</Test>");
            p.Execute();
            string result;
            using (StreamReader sr = new StreamReader(xmlInputPath))
            {
                result = sr.ReadToEnd();
                Regex r = new Regex("AccessModifier=\"&lt;Test&gt;Testing&lt;/Test&gt;\"");
                MatchCollection mc = r.Matches(result);

                Assert.Equal(1, mc.Count); // "Should match once"
            }
        }