Example #1
0
        public void TestRemove()
        {
            string             body         = null;
            WebDavQueryBuilder queryBuilder = new WebDavQueryBuilder();
            Property           del2         = new Property("del2", "NS2");
            FreeBusyProperty   del3         = new FreeBusyProperty("del3", "FB", "type2");
            string             expectedBody =
                "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                "<a:propertyupdate " +
                "xmlns:a=\"DAV:\" " +
                "xmlns:b=\"urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/\" " +
                "xmlns:c=\"xml:\" " +
                "xmlns:d=\"NS1\" " +
                "xmlns:e=\"NS2\" " +
                "xmlns:f=\"FB\">" +
                "<a:remove>" +
                "<a:prop>" +
                "<d:del1/>" +
                "<e:del2/>" +
                "<f:del3/>" +
                "</a:prop>" +
                "</a:remove>" +
                "</a:propertyupdate>";

            VerifyWellFormedXml(expectedBody);

            for (int i = 0; i < 2; i++)
            {
                bool exceptionCaught = false;
                try
                {
                    body = queryBuilder.BuildQueryBody();
                }
                catch (Exception)
                {
                    exceptionCaught = true;
                }
                Assert.IsTrue(exceptionCaught);

                queryBuilder.AddRemoveProperty("del1", "NS1");
                queryBuilder.AddRemoveProperty(del2);
                queryBuilder.AddRemoveProperty(del3);

                body = queryBuilder.BuildQueryBody();
                VerifyWellFormedXml(body);
                Assert.IsTrue(CompareXml(body, expectedBody));
                queryBuilder.Reset();
            }
        }
        public void TestUpdate()
        {
            string body = null;
            WebDavQueryBuilder queryBuilder = new WebDavQueryBuilder();
            Property up2 = new Property("up2", "NS1");
            FreeBusyProperty up3 = new FreeBusyProperty("up3", "FB", "type1");
            FreeBusyProperty up4 = new FreeBusyProperty("up4", "MV", "mv.type2");
            FreeBusyProperty up5 = new FreeBusyProperty("up5", "MV", "mv.type5");
            List<string> emptyList = new List<string>();
            List<string> up4Values = new List<string>();
            List<string> up5Values = new List<string>();
            string expectedBody =
                "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                "<a:propertyupdate " +
                "xmlns:a=\"DAV:\" " +
                "xmlns:b=\"urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/\" " +
                "xmlns:c=\"xml:\" " +
                "xmlns:d=\"NS1\" " +
                "xmlns:e=\"FB\" " +
                "xmlns:f=\"MV\">" +
                "<a:set>" +
                "<a:prop>" +
                "<a:up1>" +
                "1" +
                "</a:up1>" +
                "<d:up2>" +
                "2" +
                "</d:up2>" +
                "<e:up3 b:dt=\"type1\">" +
                "3" +
                "</e:up3>" +
                "<f:up4 b:dt=\"mv.type2\">" +
                "<c:v>" +
                "one" +
                "</c:v>" +
                "</f:up4>" +
                "<f:up5 b:dt=\"mv.type5\">" +
                "<c:v>" +
                "0x1234" +
                "</c:v>" +
                "<c:v>" +
                "0xabcd" +
                "</c:v>" +
                "</f:up5>" +
                "</a:prop>" +
                "</a:set>" +
                "</a:propertyupdate>";

            up4Values.Add("one");

            up5Values.Add("0x1234");
            up5Values.Add("0xabcd");

            VerifyWellFormedXml(expectedBody);

            for (int i = 0; i < 2; i++)
            {
                bool exceptionCaught = false;
                try
                {
                    body = queryBuilder.BuildQueryBody();
                }
                catch (Exception)
                {
                    exceptionCaught = true;
                }
                Assert.IsTrue(exceptionCaught);

                queryBuilder.AddUpdateProperty("up1", "DAV:", "1");
                queryBuilder.AddUpdateProperty(up2, "2");
                queryBuilder.AddUpdateProperty(up3, "3");

                try
                {
                    queryBuilder.AddUpdateProperty(up4, emptyList);
                }
                catch (Exception)
                {
                    exceptionCaught = true;
                }
                Assert.IsTrue(exceptionCaught);

                queryBuilder.AddUpdateProperty(up4, up4Values);
                queryBuilder.AddUpdateProperty(up5, up5Values);

                body = queryBuilder.BuildQueryBody();
                VerifyWellFormedXml(body);
                Assert.IsTrue(CompareXml(body, expectedBody));
                queryBuilder.Reset();
            }
        }
        public void TestNamespaceManagement()
        {
            char ns1Prefix = ' ';
            char ns2Prefix = ' ';
            char davPrefix = ' ';
            char xmlPrefix = ' ';
            char dtPrefix = ' ';
            char tempPrefix = ' ';
            WebDavQueryBuilder queryBuilder = new WebDavQueryBuilder();

            ns1Prefix = CallFindOrAddNamespace(queryBuilder, "NS1");
            Assert.IsTrue(ns1Prefix > 'a' && ns1Prefix < ('a' + 'z') / 2);
            tempPrefix = CallFindOrAddNamespace(queryBuilder, "NS1");
            Assert.AreEqual(ns1Prefix, tempPrefix);

            davPrefix = CallFindOrAddNamespace(queryBuilder, "DAV:");
            Assert.IsTrue(davPrefix < ns1Prefix && davPrefix >= 'a');
            tempPrefix = CallFindOrAddNamespace(queryBuilder, "DAV:");
            Assert.AreEqual(davPrefix, tempPrefix);

            xmlPrefix = CallFindOrAddNamespace(queryBuilder, "xml:");
            Assert.IsTrue(xmlPrefix < ns1Prefix && xmlPrefix >= 'a');
            tempPrefix = CallFindOrAddNamespace(queryBuilder, "xml:");
            Assert.AreEqual(xmlPrefix, tempPrefix);

            dtPrefix = CallFindOrAddNamespace(queryBuilder,
                                              "urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/");
            Assert.IsTrue(dtPrefix < ns1Prefix && dtPrefix >= 'a');
            tempPrefix = CallFindOrAddNamespace(queryBuilder,
                                                "urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/");
            Assert.AreEqual(dtPrefix, tempPrefix);

            ns2Prefix = CallFindOrAddNamespace(queryBuilder, "NS2");
            Assert.IsTrue(ns2Prefix > ns1Prefix && xmlPrefix <= 'z');
            tempPrefix = CallFindOrAddNamespace(queryBuilder, "NS2");
            Assert.AreEqual(ns2Prefix, tempPrefix);

            char[] prefixes = new char[5] { ns1Prefix, ns2Prefix, davPrefix, dtPrefix, xmlPrefix };

            for (int i = 0; i < prefixes.Length; i++)
            {
                for (int j = i + 1; j < prefixes.Length; j++)
                {
                    Assert.AreNotEqual(prefixes[i], prefixes[j]);
                }
            }

            char c = ns2Prefix;
            for (c++; c <= 'z'; c++)
            {
                tempPrefix = CallFindOrAddNamespace(queryBuilder, c.ToString());
                Assert.AreEqual(tempPrefix, c);
            }

            bool exceptionCaught = false;
            try
            {
                tempPrefix = CallFindOrAddNamespace(queryBuilder, "Boom:");
            }
            catch (Exception)
            {
                exceptionCaught = true;
            }
            Assert.IsTrue(exceptionCaught);

            queryBuilder.Reset();
            tempPrefix = CallFindOrAddNamespace(queryBuilder, "NEW:");
            Assert.AreEqual(ns1Prefix, tempPrefix);
        }
        public void TestUpdateAndRemove()
        {
            string body = null;
            WebDavQueryBuilder queryBuilder = new WebDavQueryBuilder();
            Property up2 = new Property("up2", "NS1");
            FreeBusyProperty up3 = new FreeBusyProperty("up3", "FB", "type1");
            Property del2 = new Property("del2", "NS2");
            FreeBusyProperty del3 = new FreeBusyProperty("del3", "FB", "type2");
            string expectedBody =
                "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                "<a:propertyupdate " +
                "xmlns:a=\"DAV:\" " +
                "xmlns:b=\"urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/\" " +
                "xmlns:c=\"xml:\" " +
                "xmlns:d=\"NS1\" " +
                "xmlns:e=\"FB\" " +
                "xmlns:f=\"NS2\">" +
                "<a:set>" +
                "<a:prop>" +
                "<a:up1>" +
                "1" +
                "</a:up1>" +
                "<d:up2>" +
                "2" +
                "</d:up2>" +
                "<e:up3 b:dt=\"type1\">" +
                "3" +
                "</e:up3>" +
                "</a:prop>" +
                "</a:set>" +
                "<a:remove>" +
                "<a:prop>" +
                "<d:del1/>" +
                "<f:del2/>" +
                "<e:del3/>" +
                "</a:prop>" +
                "</a:remove>" +
                "</a:propertyupdate>";

            VerifyWellFormedXml(expectedBody);

            for (int i = 0; i < 2; i++)
            {
                bool exceptionCaught = false;
                try
                {
                    body = queryBuilder.BuildQueryBody();
                }
                catch (Exception)
                {
                    exceptionCaught = true;
                }
                Assert.IsTrue(exceptionCaught);

                queryBuilder.AddUpdateProperty("up1", "DAV:", "1");
                queryBuilder.AddUpdateProperty(up2, "2");
                queryBuilder.AddUpdateProperty(up3, "3");

                queryBuilder.AddRemoveProperty("del1", "NS1");
                queryBuilder.AddRemoveProperty(del2);
                queryBuilder.AddRemoveProperty(del3);

                body = queryBuilder.BuildQueryBody();
                VerifyWellFormedXml(body);
                Assert.IsTrue(CompareXml(body, expectedBody));
                queryBuilder.Reset();
            }
        }
Example #5
0
        public void TestUpdate()
        {
            string             body         = null;
            WebDavQueryBuilder queryBuilder = new WebDavQueryBuilder();
            Property           up2          = new Property("up2", "NS1");
            FreeBusyProperty   up3          = new FreeBusyProperty("up3", "FB", "type1");
            FreeBusyProperty   up4          = new FreeBusyProperty("up4", "MV", "mv.type2");
            FreeBusyProperty   up5          = new FreeBusyProperty("up5", "MV", "mv.type5");
            List <string>      emptyList    = new List <string>();
            List <string>      up4Values    = new List <string>();
            List <string>      up5Values    = new List <string>();
            string             expectedBody =
                "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                "<a:propertyupdate " +
                "xmlns:a=\"DAV:\" " +
                "xmlns:b=\"urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/\" " +
                "xmlns:c=\"xml:\" " +
                "xmlns:d=\"NS1\" " +
                "xmlns:e=\"FB\" " +
                "xmlns:f=\"MV\">" +
                "<a:set>" +
                "<a:prop>" +
                "<a:up1>" +
                "1" +
                "</a:up1>" +
                "<d:up2>" +
                "2" +
                "</d:up2>" +
                "<e:up3 b:dt=\"type1\">" +
                "3" +
                "</e:up3>" +
                "<f:up4 b:dt=\"mv.type2\">" +
                "<c:v>" +
                "one" +
                "</c:v>" +
                "</f:up4>" +
                "<f:up5 b:dt=\"mv.type5\">" +
                "<c:v>" +
                "0x1234" +
                "</c:v>" +
                "<c:v>" +
                "0xabcd" +
                "</c:v>" +
                "</f:up5>" +
                "</a:prop>" +
                "</a:set>" +
                "</a:propertyupdate>";

            up4Values.Add("one");

            up5Values.Add("0x1234");
            up5Values.Add("0xabcd");

            VerifyWellFormedXml(expectedBody);

            for (int i = 0; i < 2; i++)
            {
                bool exceptionCaught = false;
                try
                {
                    body = queryBuilder.BuildQueryBody();
                }
                catch (Exception)
                {
                    exceptionCaught = true;
                }
                Assert.IsTrue(exceptionCaught);

                queryBuilder.AddUpdateProperty("up1", "DAV:", "1");
                queryBuilder.AddUpdateProperty(up2, "2");
                queryBuilder.AddUpdateProperty(up3, "3");

                try
                {
                    queryBuilder.AddUpdateProperty(up4, emptyList);
                }
                catch (Exception)
                {
                    exceptionCaught = true;
                }
                Assert.IsTrue(exceptionCaught);

                queryBuilder.AddUpdateProperty(up4, up4Values);
                queryBuilder.AddUpdateProperty(up5, up5Values);

                body = queryBuilder.BuildQueryBody();
                VerifyWellFormedXml(body);
                Assert.IsTrue(CompareXml(body, expectedBody));
                queryBuilder.Reset();
            }
        }
Example #6
0
        public void TestNamespaceManagement()
        {
            char ns1Prefix  = ' ';
            char ns2Prefix  = ' ';
            char davPrefix  = ' ';
            char xmlPrefix  = ' ';
            char dtPrefix   = ' ';
            char tempPrefix = ' ';
            WebDavQueryBuilder queryBuilder = new WebDavQueryBuilder();

            ns1Prefix = CallFindOrAddNamespace(queryBuilder, "NS1");
            Assert.IsTrue(ns1Prefix > 'a' && ns1Prefix < ('a' + 'z') / 2);
            tempPrefix = CallFindOrAddNamespace(queryBuilder, "NS1");
            Assert.AreEqual(ns1Prefix, tempPrefix);

            davPrefix = CallFindOrAddNamespace(queryBuilder, "DAV:");
            Assert.IsTrue(davPrefix < ns1Prefix && davPrefix >= 'a');
            tempPrefix = CallFindOrAddNamespace(queryBuilder, "DAV:");
            Assert.AreEqual(davPrefix, tempPrefix);

            xmlPrefix = CallFindOrAddNamespace(queryBuilder, "xml:");
            Assert.IsTrue(xmlPrefix < ns1Prefix && xmlPrefix >= 'a');
            tempPrefix = CallFindOrAddNamespace(queryBuilder, "xml:");
            Assert.AreEqual(xmlPrefix, tempPrefix);

            dtPrefix = CallFindOrAddNamespace(queryBuilder,
                                              "urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/");
            Assert.IsTrue(dtPrefix < ns1Prefix && dtPrefix >= 'a');
            tempPrefix = CallFindOrAddNamespace(queryBuilder,
                                                "urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/");
            Assert.AreEqual(dtPrefix, tempPrefix);

            ns2Prefix = CallFindOrAddNamespace(queryBuilder, "NS2");
            Assert.IsTrue(ns2Prefix > ns1Prefix && xmlPrefix <= 'z');
            tempPrefix = CallFindOrAddNamespace(queryBuilder, "NS2");
            Assert.AreEqual(ns2Prefix, tempPrefix);

            char[] prefixes = new char[5] {
                ns1Prefix, ns2Prefix, davPrefix, dtPrefix, xmlPrefix
            };

            for (int i = 0; i < prefixes.Length; i++)
            {
                for (int j = i + 1; j < prefixes.Length; j++)
                {
                    Assert.AreNotEqual(prefixes[i], prefixes[j]);
                }
            }

            char c = ns2Prefix;

            for (c++; c <= 'z'; c++)
            {
                tempPrefix = CallFindOrAddNamespace(queryBuilder, c.ToString());
                Assert.AreEqual(tempPrefix, c);
            }

            bool exceptionCaught = false;

            try
            {
                tempPrefix = CallFindOrAddNamespace(queryBuilder, "Boom:");
            }
            catch (Exception)
            {
                exceptionCaught = true;
            }
            Assert.IsTrue(exceptionCaught);

            queryBuilder.Reset();
            tempPrefix = CallFindOrAddNamespace(queryBuilder, "NEW:");
            Assert.AreEqual(ns1Prefix, tempPrefix);
        }