Exemplo n.º 1
0
        public void RequestUriResourceSetPropertyTest()
        {
            UnitTestsUtil.VerifyPayload("/Customers(0)/Orders", typeof(CustomDataContext), null,
                                        new string[] { "/cdc:Orders",
                                                       "/cdc:Orders/cdc:Order" },
                                        new string[] { String.Format("/{0}", JsonValidator.ArrayString),
                                                       JsonValidator.GetJsonTypeXPath(typeof(Order), true /*isArray*/) },
                                        new string[0]);

            UnitTestsUtil.VerifyInvalidUri("/Customers!1000/Orders", typeof(CustomDataContext));
            UnitTestsUtil.VerifyInvalidUri("/Customers(1)/Orders(10000)", typeof(CustomDataContext));
        }
Exemplo n.º 2
0
        public void RequestUriResourceSetPropertyTest()
        {
            Func <Hashtable, XmlDocument, bool> testCallBack = (values, document) =>
            {
                string responseFormat = (string)values["ResponseFormat"];
                string xPath;

                if (responseFormat == UnitTestsUtil.JsonLightMimeType)
                {
                    xPath = String.Format("/{0}/{1}/ID", JsonValidator.ArrayString, JsonValidator.ObjectString);
                }
                else
                {
                    Assert.IsTrue(responseFormat == UnitTestsUtil.AtomFormat, "unexpected format");
                    xPath = "/atom:feed/atom:entry/atom:content/adsm:properties/ads:ID";
                }

                XmlElement order = (XmlElement)document.SelectSingleNode(xPath, TestUtil.TestNamespaceManager);

                using (TestWebRequest request = TestWebRequest.CreateForLocation(WebServerLocation.InProcess))
                {
                    request.RequestUriString = "/Customers(0)/Orders(" + order.InnerText + ")";
                    request.Accept           = responseFormat;
                    request.DataServiceType  = typeof(CustomDataContext);
                    request.SendRequest();

                    UnitTestsUtil.VerifyXPaths(request.GetResponseStream(), responseFormat,
                                               new string[] { "/cdc:Order" },
                                               new string[] { JsonValidator.GetJsonTypeXPath(typeof(Order), false /*isArray*/) },
                                               new string[0]);

                    return(true);
                }
            };

            UnitTestsUtil.VerifyPayload("/Customers(0)/Orders", typeof(CustomDataContext), testCallBack,
                                        new string[] { "/cdc:Orders",
                                                       "/cdc:Orders/cdc:Order" },
                                        new string[] { String.Format("/{0}", JsonValidator.ArrayString),
                                                       JsonValidator.GetJsonTypeXPath(typeof(Order), true /*isArray*/) },
                                        new string[0]);

            // TODO: When this is fixed, we should uncomment this test cases
            //UnitTestsUtil.VerifyInvalidUri("/Customers!1000/Orders", typeof(CustomDataContext));
            UnitTestsUtil.VerifyInvalidUri("/Customers(1)/Orders(10000)", typeof(CustomDataContext));
        }
Exemplo n.º 3
0
        public void RequestUriResourcePropertyTest()
        {
            UnitTestsUtil.VerifyInvalidUri("/Customers(1000)/BestFriend", typeof(CustomDataContext));

            UnitTestsUtil.VerifyPayload("/Customers(2)/BestFriend", typeof(CustomDataContext), null,
                                        new string[] { "/cdc:BestFriend",
                                                       "/cdc:BestFriend/web3s:ID[text()='1']" },
                                        new string[] { String.Format("/{0}", JsonValidator.ObjectString),
                                                       String.Format("/{0}/ID[text()='1']", JsonValidator.ObjectString) },
                                        new string[0]);

            ServiceModelData.Northwind.EnsureDependenciesAvailable();
            UnitTestsUtil.VerifyPayload("/Territories", typeof(NorthwindContext), null,
                                        new string[] { "//nc:Territories/web3s:ID" },
                                        new string[] { String.Format("/{0}/{1}/TerritoryID[text()='01581']", JsonValidator.ArrayString, JsonValidator.ObjectString),
                                                       String.Format("count(//{0})>10", JsonValidator.ObjectString) },
                                        new string[0]);
        }