コード例 #1
0
ファイル: XmlPoke_Tests.cs プロジェクト: cameron314/msbuild
        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);
                }
            }
        }
コード例 #2
0
ファイル: XmlPoke_Tests.cs プロジェクト: JamesLinus/msbuild
        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");
        }
コード例 #3
0
ファイル: XmlPoke_Tests.cs プロジェクト: cameron314/msbuild
        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);
                }
            }
        }
コード例 #4
0
ファイル: XmlPoke_Tests.cs プロジェクト: cameron314/msbuild
        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."
                }
            }
        }
コード例 #5
0
ファイル: XmlPoke_Tests.cs プロジェクト: cameron314/msbuild
        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);
        }
コード例 #6
0
ファイル: XmlPoke_Tests.cs プロジェクト: cameron314/msbuild
        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"
                }
            }
        }
コード例 #7
0
ファイル: XmlPoke_Tests.cs プロジェクト: cameron314/msbuild
        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"
            }
        }
コード例 #8
0
ファイル: XmlPoke_Tests.cs プロジェクト: cameron314/msbuild
        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"
            }
        }