示例#1
0
        public void SerializeGeodeticPropertiesInResource()
        {
            var testCases = new[]
            {
                new
                {
                    GeographyType = typeof(GeographyPoint),
                    DefaultValues = TestPoint.DefaultValues
                },
                new
                {
                    GeographyType = typeof(GeographyLineString),
                    DefaultValues = TestLineString.DefaultValues
                },
            };

            var responseFromats = new string[] { UnitTestsUtil.AtomFormat };

            TestUtil.RunCombinations(testCases, responseFromats, (testCase, responseFormat) =>
            {
                GeographyPropertyValues defaultValues = testCase.DefaultValues;

                DSPUnitTestServiceDefinition roadTripServiceDefinition = GetRoadTripServiceDefinition(testCase.GeographyType, defaultValues);
                using (TestWebRequest request = roadTripServiceDefinition.CreateForInProcess())
                {
                    request.StartService();
                    request.Accept = responseFormat;

                    ResourceVerification verification = GetResourceVerification(responseFormat, SpatialTestUtil.DefaultId, defaultValues, request);

                    // Geography property followed by another geography property
                    verification.GetAndVerifyTripLeg();

                    // Geography property followed by another non-geography property
                    verification.GetAndVerifyAmusementPark();

                    // Geography property at the end of the entry
                    verification.GetAndVerifyRestStop();
                }
            });
        }
示例#2
0
 public ResourceVerification(TestWebRequest request, DSPResourceSerializerFormat payloadFormat, int id, GeographyPropertyValues propertyValues)
 {
     this.Request = request;
     this.Id = id;
     this.PropertyValues = propertyValues;
     this.PayloadFormat = payloadFormat;
 }
示例#3
0
 internal static DSPUnitTestServiceDefinition GetRoadTripServiceDefinition(Type geographyType, GeographyPropertyValues defaultValues, bool useComplexType = false, bool useOpenTypes = false, Action<DSPMetadata> modifyMetadata = null)
 {
     DSPMetadata roadTripMetadata = SpatialTestUtil.CreateRoadTripMetadata(geographyType, useComplexType, useOpenTypes, modifyMetadata);
     return SpatialTestUtil.CreateRoadTripServiceDefinition(roadTripMetadata, defaultValues, DSPDataProviderKind.CustomProvider, useComplexType);
 }
示例#4
0
 private static ResourceVerification GetResourceVerification(string responseFormat, int id, GeographyPropertyValues defaultValues, TestWebRequest request)
 {
     Assert.IsTrue(responseFormat == UnitTestsUtil.AtomFormat || responseFormat == UnitTestsUtil.JsonLightMimeType, "Response format {0} not recognized in GetResourceVerification.", responseFormat);
     DSPResourceSerializerFormat payloadFormat = responseFormat == UnitTestsUtil.AtomFormat ? DSPResourceSerializerFormat.Atom : DSPResourceSerializerFormat.Json;
     return new ResourceVerification(request, payloadFormat, id, defaultValues);
 }
示例#5
0
        internal static DSPUnitTestServiceDefinition GetRoadTripServiceDefinition(Type geographyType, GeographyPropertyValues defaultValues, bool useComplexType = false, bool useOpenTypes = false, Action <DSPMetadata> modifyMetadata = null)
        {
            DSPMetadata roadTripMetadata = SpatialTestUtil.CreateRoadTripMetadata(geographyType, useComplexType, useOpenTypes, modifyMetadata);

            return(SpatialTestUtil.CreateRoadTripServiceDefinition(roadTripMetadata, defaultValues, DSPDataProviderKind.CustomProvider, useComplexType));
        }
示例#6
0
        private static LinqTestCase[] GetSupportedLinqQueries <T>(DataServiceContext context, GeographyPropertyValues defaultValues) where T : Geography
        {
            LinqTestCase[] tests = null;

            IQueryable <TripLeg <T> > allTripLegsActual = context.CreateQuery <TripLeg <T> >("TripLegs");

            IQueryable <TripLeg <T> > allTripLegsExpected = new List <TripLeg <T> >()
            {
                new TripLeg <T>()
                {
                    ID = SpatialTestUtil.DefaultId,
                    GeographyProperty1 = (T)defaultValues.TripLegGeography1.AsGeography(),
                    GeographyProperty2 = (T)defaultValues.TripLegGeography2.AsGeography()
                }
            }.AsQueryable();

            LinqTestCase[] tests_BaseGeography = GetSupportedLinqQueries_BaseGeography(allTripLegsActual, allTripLegsExpected);

            Type testSpatialType = typeof(T);

            if (testSpatialType == typeof(Geography))
            {
                tests = tests_BaseGeography;
            }
            else if (testSpatialType == typeof(GeographyPoint))
            {
                LinqTestCase[] tests_GeographyPoint = GetSupportedLinqQueries_GeographyPoint((IQueryable <TripLeg <GeographyPoint> >)allTripLegsActual, (IQueryable <TripLeg <GeographyPoint> >)allTripLegsExpected);

                tests = tests_GeographyPoint.Concat(tests_BaseGeography).ToArray();
            }
            else if (testSpatialType == typeof(GeographyLineString))
            {
                LinqTestCase[] tests_GeographyLineString = GetSupportedLinqQueries_GeographyLineString((IQueryable <TripLeg <GeographyLineString> >)allTripLegsActual, (IQueryable <TripLeg <GeographyLineString> >)allTripLegsExpected);

                tests = tests_GeographyLineString.Concat(tests_BaseGeography).ToArray();
            }
            else
            {
                Assert.Fail("No supported LINQ queries are defined for the type {0}.", testSpatialType);
            }

            return(tests);
        }
示例#7
0
 private static void TestSupportedLinqQueries <T>(GeographyPropertyValues defaultValues, Type spatialTestType) where T : Geography
 {
     TestSupportedLinqQueries(context => GetSupportedLinqQueries <T>(context, defaultValues));
 }
示例#8
0
 public ResourceVerification(TestWebRequest request, DSPResourceSerializerFormat payloadFormat, int id, GeographyPropertyValues propertyValues)
 {
     this.Request        = request;
     this.Id             = id;
     this.PropertyValues = propertyValues;
     this.PayloadFormat  = payloadFormat;
 }
示例#9
0
        public void InsertAndUpdateGeodeticProperties()
        {
            var testCases = new[]
            {
                new
                {
                    GeographyType = typeof(Geography),
                    DefaultValues = TestLineString.DefaultValues,
                    NewValues     = TestLineString.NewValues,
                },
                new
                {
                    GeographyType = typeof(GeographyPoint),
                    DefaultValues = TestPoint.DefaultValues,
                    NewValues     = TestPoint.NewValues,
                },
                new
                {
                    GeographyType = typeof(GeographyLineString),
                    DefaultValues = TestLineString.DefaultValues,
                    NewValues     = TestLineString.NewValues,
                },
            };

            TestUtil.RunCombinations(testCases, UnitTestsUtil.BooleanValues, UnitTestsUtil.ResponseFormats, (testCase, enableTypeConversion, payloadFormat) =>
            {
                GeographyPropertyValues defaultValues = testCase.DefaultValues;
                bool useComplexType = false;
                DSPUnitTestServiceDefinition roadTripServiceDefinition = GetRoadTripServiceDefinition(testCase.GeographyType, defaultValues, useComplexType);

                // EnableTypeConversion is interesting here because it affects whether or not we pay attention to the type that's specified on the wire, instead of metadata
                // Since spatial types can specify Geography in metadata but GeographyPoint as the value, we need to verify it works either way
                roadTripServiceDefinition.EnableTypeConversion = enableTypeConversion;

                using (TestWebRequest request = roadTripServiceDefinition.CreateForInProcess())
                {
                    request.StartService();

                    TestUtil.RunCombinations(
                        new string[] { "POST", "PUT", "PATCH", "PATCH" },
                        new string[] { null, "return=representation", "return=minimal" },
                        UnitTestsUtil.BooleanValues,
                        (httpMethod, preferHeader, useBatch) =>
                    {
                        bool isPost = httpMethod == "POST";
                        bool expectedReturnContent = preferHeader == "return=representation" || isPost && preferHeader == null;

                        DSPMetadata roadTripMetadata = roadTripServiceDefinition.Metadata;
                        DSPContext changeScopeData   = SpatialTestUtil.PopulateRoadTripData(roadTripMetadata, defaultValues, useComplexType);
                        using (IDisposable changeScope = roadTripServiceDefinition.CreateChangeScope(changeScopeData))
                        {
                            int id = isPost ? 2 : SpatialTestUtil.DefaultId;

                            ResourceVerification verification = GetResourceVerification(payloadFormat, id, testCase.NewValues, request);

                            TestTripLegUpdate(verification, httpMethod, preferHeader, useBatch, roadTripMetadata);
                            TestAmusementParkUpdate(verification, httpMethod, preferHeader, useBatch, roadTripMetadata);
                            TestRestStopUpdate(verification, httpMethod, preferHeader, useBatch, roadTripMetadata);
                        }
                    });
                }
            });
        }
示例#10
0
        private static ResourceVerification GetResourceVerification(string responseFormat, int id, GeographyPropertyValues defaultValues, TestWebRequest request)
        {
            Assert.IsTrue(responseFormat == UnitTestsUtil.AtomFormat || responseFormat == UnitTestsUtil.JsonLightMimeType, "Response format {0} not recognized in GetResourceVerification.", responseFormat);
            DSPResourceSerializerFormat payloadFormat = responseFormat == UnitTestsUtil.AtomFormat ? DSPResourceSerializerFormat.Atom : DSPResourceSerializerFormat.Json;

            return(new ResourceVerification(request, payloadFormat, id, defaultValues));
        }