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]); }
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)); }
public void GeometryCollection_Deserialize() { StringBuilder payload = new StringBuilder(); payload.Append("{ \"__metadata\":{ \"uri\": \"http://host/Entities(0)\" }, \"ID\": 0"); foreach (var kvp in testData) { payload.AppendLine(","); payload.Append(JsonCollectionPropertyFromWkt(SpatialTestUtil.GeometryTypeFor(kvp.Key).Name, kvp.Value, SpatialTestUtil.GeometryEdmNameFor(kvp.Key))); } payload.AppendLine("}"); var svc = CreateCollectionWriteService(testData.Keys.Select(t => SpatialTestUtil.GeometryTypeFor(t)).ToList()); using (TestWebRequest request = svc.CreateForInProcess()) { System.Data.Test.Astoria.TestUtil.RunCombinations(UnitTestsUtil.ResponseFormats, (format) => { request.RequestUriString = "/Entities"; request.HttpMethod = "POST"; request.Accept = "application/atom+xml,application/xml"; request.RequestContentType = format; if (format == UnitTestsUtil.JsonLightMimeType) { request.SetRequestStreamAsText(payload.ToString()); } else { var xDoc = JsonValidator.ConvertToXDocument(payload.ToString()); var atomPayload = UnitTestsUtil.Json2AtomXLinq(xDoc, true).ToString(); request.SetRequestStreamAsText(atomPayload); } request.SendRequest(); var response = request.GetResponseStreamAsXDocument(); UnitTestsUtil.VerifyXPaths(response, testData.Select(d => String.Format("count(atom:entry/atom:content/adsm:properties/ads:Collection{0}/adsm:element) = {1}", SpatialTestUtil.GeometryTypeFor(d.Key).Name, d.Value.Length)).ToArray()); }); } }
public void GeometryAsOpenProperty_Deserialize() { var testCases = testData.Select(kvp => new { Type = SpatialTestUtil.GeometryTypeFor(kvp.Key), EdmName = SpatialTestUtil.GeometryEdmNameFor(kvp.Key), Data = new Geometry[kvp.Value.Length], Payload = AggregateJsonPayloadFromWkt(SpatialTestUtil.GeometryTypeFor(kvp.Key).Name, kvp.Value, SpatialTestUtil.GeometryEdmNameFor(kvp.Key)) }); TestUtil.RunCombinations(testCases, UnitTestsUtil.ResponseFormats, (tcase, format) => { using (TestWebRequest request = CreateSpatialPropertyService(tcase.Data, tcase.Type, true, true).CreateForInProcessWcf()) { request.RequestUriString = "/Entities"; request.HttpMethod = "POST"; request.Accept = "application/atom+xml,application/xml"; request.RequestContentType = format; if (format == UnitTestsUtil.JsonLightMimeType) { request.SetRequestStreamAsText(tcase.Payload); } else { // atom from Json - this payload has no m:type var xDoc = JsonValidator.ConvertToXDocument(tcase.Payload.ToString()); var atomPayload = UnitTestsUtil.Json2AtomXLinq(xDoc, true).ToString(); request.SetRequestStreamAsText(atomPayload); } request.SendRequest(); var response = request.GetResponseStreamAsXDocument(); string rootXpath = "atom:entry/atom:content/adsm:properties/ads:" + tcase.Type.Name; string[] xpaths = tcase.Data.Select((v, i) => rootXpath + i + "[@adsm:type = '" + tcase.EdmName + "' and namespace-uri(*) = 'http://www.opengis.net/gml']").ToArray(); UnitTestsUtil.VerifyXPaths(response, xpaths); } }); }