예제 #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));
        }
예제 #2
0
 public void RequestUriResourceKeySimpleTest()
 {
     UnitTestsUtil.VerifyPayload("/Customers(1)", typeof(CustomDataContext), null,
                                 new string[] {
         "/cdc:Customer",
         "/cdc:Customer/cdc:ID[text()='1']",
         "count(//cdc:Customer)=1"
     },
                                 new string[] {
         JsonValidator.GetJsonTypeXPath(typeof(CustomerWithBirthday), false /*isArray*/),
         String.Format("/{0}/ID[text()='1']", JsonValidator.ObjectString),
         String.Format("count(//{0})=1", JsonValidator.ObjectString)
     },
                                 new string[0]);
 }
예제 #3
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));
        }