public void GeographyAsOpenProperty_AtomWithTypeDeserialize()
        {
            // tests atom deserialization with m:type information
            var testCases = testData.Select(kvp =>
                                            new
            {
                Type    = SpatialTestUtil.GeographyTypeFor(kvp.Key),
                EdmName = SpatialTestUtil.GeographyEdmNameFor(kvp.Key),
                WktData = kvp.Value
            });

            TestUtil.RunCombinations(testCases, (tcase) =>
            {
                using (TestWebRequest request = CreateSpatialPropertyService(new Geography[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 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 GeographyAsOpenProperty_Deserialize()
        {
            var testCases = testData.Select(kvp => new
            {
                Type    = SpatialTestUtil.GeographyTypeFor(kvp.Key),
                EdmName = SpatialTestUtil.GeographyEdmNameFor(kvp.Key),
                Data    = new Geography[kvp.Value.Length],
                Payload = AggregateJsonPayloadFromWkt(SpatialTestUtil.GeographyTypeFor(kvp.Key).Name, kvp.Value, SpatialTestUtil.GeographyEdmNameFor(kvp.Key))
            });

            TestUtil.RunCombinations(testCases, UnitTestsUtil.ResponseFormats, (tcase, format) =>
            {
                using (TestWebRequest request = CreateSpatialPropertyService(tcase.Data, tcase.Type, true, true).CreateForInProcess())
                {
                    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 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 GeographyCollection_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.GeographyTypeFor(kvp.Key).Name, kvp.Value, SpatialTestUtil.GeographyEdmNameFor(kvp.Key)));
            }

            payload.AppendLine("}");

            var svc = CreateCollectionWriteService(testData.Keys.Select(t => SpatialTestUtil.GeographyTypeFor(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.GeographyTypeFor(d.Key).Name, d.Value.Length)).ToArray());
                });
            }
        }