public void GeographyCollection_Serialize() { Dictionary <Type, object> data = new Dictionary <Type, object>(); foreach (var sample in testData) { data.Add(SpatialTestUtil.GeographyTypeFor(sample.Key), sample.Value.Select(wkt => wktFormatter.Read <Geography>(new StringReader(wkt))).ToList()); } using (TestWebRequest request = CreateCollectionReadService(data).CreateForInProcess()) { System.Data.Test.Astoria.TestUtil.RunCombinations(UnitTestsUtil.ResponseFormats, (format) => { var response = UnitTestsUtil.GetResponseAsAtomXLinq(request, "/Entities", format); // feed/entry/content/properties/CollectionGeographyPoint[@type = \"Collection(Edm.Point)\"]" UnitTestsUtil.VerifyXPaths(response, testData.Keys.Select(type => String.Format("atom:feed/atom:entry/atom:content/adsm:properties/ads:Collection{0}[@adsm:type = \"#Collection({1})\"]", SpatialTestUtil.GeographyTypeFor(type).Name, SpatialTestUtil.GeographyEdmNameFor(type))).ToArray()); UnitTestsUtil.VerifyXPaths(response, testData.Select(d => String.Format("count(atom:feed/atom:entry/atom:content/adsm:properties/ads:Collection{0}/adsm:element) = {1}", SpatialTestUtil.GeographyTypeFor(d.Key).Name, d.Value.Length)).ToArray()); }); } }
public void SpatialOpenProperty_AtomWrongTypeDeserialize() { var testCases = testData.Select(kvp => new { Type = SpatialTestUtil.GeographyTypeFor(kvp.Key), WktData = new String[] { kvp.Value.Last() } }); String[] edmCases = { "Edm.Double", "Edm.String" }; TestUtil.RunCombinations(testCases, edmCases, (tcase, edmName) => { using (TestWebRequest request = CreateSpatialPropertyService(new Geography[tcase.WktData.Length], tcase.Type, true, true).CreateForInProcess()) { request.RequestUriString = "/Entities"; request.HttpMethod = "POST"; request.RequestContentType = UnitTestsUtil.AtomFormat; request.SetRequestStreamAsText(AggregateAtomPayloadFromWkt(tcase.Type.Name, tcase.WktData, edmName)); Exception ex = TestUtil.RunCatching(request.SendRequest); Assert.IsNotNull(ex); while (ex.InnerException != null) { ex = ex.InnerException; } Assert.AreEqual(ODataLibResourceUtil.GetString("XmlReaderExtension_InvalidNodeInStringValue", "Element"), ex.Message); } }); }
public void GeometryAsOpenProperty_AtomWithTypeDeserialize() { // tests atom deserialization with m:type information var testCases = testData.Select(kvp => new { Type = SpatialTestUtil.GeometryTypeFor(kvp.Key), EdmName = SpatialTestUtil.GeometryEdmNameFor(kvp.Key), WktData = kvp.Value }); TestUtil.RunCombinations(testCases, (tcase) => { using (TestWebRequest request = CreateSpatialPropertyService(new Geometry[tcase.WktData.Length], tcase.Type, true, true).CreateForInProcessWcf()) { request.RequestUriString = "/Entities"; request.HttpMethod = "POST"; request.Accept = "application/atom+xml,application/xml"; request.RequestContentType = UnitTestsUtil.AtomFormat; request.SetRequestStreamAsText(AggregateAtomPayloadFromWkt(tcase.Type.Name, tcase.WktData, tcase.EdmName)); request.SendRequest(); var response = request.GetResponseStreamAsXDocument(); string rootXpath = "atom:entry/atom:content/adsm:properties/ads:" + tcase.Type.Name; UnitTestsUtil.VerifyXPaths(response, tcase.WktData.Select((v, i) => rootXpath + i + "[@adsm:type = '" + tcase.EdmName + "' and namespace-uri(*) = 'http://www.opengis.net/gml']").ToArray()); } }); }
public void VerifyGmlContent(XElement property) { XElement point = property.Element(UnitTestsUtil.GmlNamespace + "Point"); Assert.IsNotNull(point, "Payload does not contain the GML point element."); XElement pos = point.Element(UnitTestsUtil.GmlNamespace + "pos"); Assert.IsNotNull(pos, "Payload does not contain the GML pos element"); Assert.AreEqual(SpatialTestUtil.ToPointString(this), pos.Value, "Incorrect GML Content"); }
public void VerifyGmlContent(XElement property) { XElement linestring = property.Element(UnitTestsUtil.GmlNamespace + "LineString"); Assert.IsNotNull(linestring, "Payload does not contain the GML line element."); var pos = linestring.Elements(UnitTestsUtil.GmlNamespace + "pos"); Assert.IsNotNull(pos, "Payload does not contain the GML pos element"); Assert.AreEqual(this.Points.Count(), pos.Count(), "Number of pos elements does not equal to number of points in the linestring"); string pointString = pos.Select(p => p.Value).Concatenate(" "); Assert.AreEqual(SpatialTestUtil.ToPointString(this.Points), pointString, "Incorrect GML Content"); }
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 SpatialAsKeys() { var types = testData.Select(kvp => SpatialTestUtil.GeographyTypeFor(kvp.Key)) .Union(testData.Select(kvp => SpatialTestUtil.GeometryTypeFor(kvp.Key))) .Union(new Type[] { typeof(Geography), typeof(Geometry) }) .ToArray(); TestUtil.RunCombinations(types, (t) => { DSPMetadata metadata = new DSPMetadata("SpatialServerIntegration", "AstoriaUnitTests.Tests"); var entityType = metadata.AddEntityType("EntityType", null, null, false); metadata.AddResourceSet("Entities", entityType); Exception ex = TestUtil.RunCatching <InvalidOperationException>( () => metadata.AddKeyProperty(entityType, "ID", t)); Assert.IsNotNull(ex); Assert.AreEqual(DataServicesResourceUtil.GetString("ResourceType_SpatialKeyOrETag", "ID", "EntityType"), ex.Message); }); }
public void GeographyAsOpenProperty_Serialize() { var testCases = testData.Select(kvp => new { Type = SpatialTestUtil.GeographyTypeFor(kvp.Key), EdmName = SpatialTestUtil.GeographyEdmNameFor(kvp.Key), Data = kvp.Value.Select(wkt => wktFormatter.Read <Geography>(new StringReader(wkt))).ToArray() }); TestUtil.RunCombinations(testCases, UnitTestsUtil.ResponseFormats, (tcase, format) => { using (TestWebRequest request = CreateSpatialPropertyService(tcase.Data, tcase.Type, true).CreateForInProcessWcf()) { var response = UnitTestsUtil.GetResponseAsAtomXLinq(request, "/Entities", format); string rootXpath = "atom:feed/atom:entry/atom:content/adsm:properties/ads:" + tcase.Type.Name; UnitTestsUtil.VerifyXPaths(response, tcase.Data.Select((v, i) => rootXpath + i + "[@adsm:type = '" + tcase.EdmName + "' and namespace-uri(*) = 'http://www.opengis.net/gml']").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); } }); }
public string AsGml() { return(SpatialTestUtil.ToPointString(this.Points)); }