Exemple #1
0
        private static void TestRestStopUpdate(ResourceVerification verification, string httpMethod, string preferHeader, bool useBatch, DSPMetadata roadTripMetadata)
        {
            var restStop = SpatialTestUtil.CreateRestStopResource(
                roadTripMetadata,
                verification.Id,
                verification.PropertyValues.RestStopGeography,
                useComplexType: false,
                modifyPropertyValues: null);

            ExecuteUpdate(restStop, verification.Id, verification.Request, httpMethod, preferHeader, useBatch, verification.PayloadFormat);

            // Verify that the operation was successful by querying the same data again
            verification.GetAndVerifyRestStop();
        }
Exemple #2
0
        private static void TestSpatialMetadata(DSPDataProviderKind providerKind)
        {
            DSPMetadata metadata = new DSPMetadata("SpatialMetadata", "AstoriaUnitTests.Tests");

            // Entity with all types of geography properties
            KeyValuePair <string, Type>[] geographyProperties = new KeyValuePair <string, Type>[] {
                new KeyValuePair <string, Type>("GeographyProperty", typeof(Geography)),
                new KeyValuePair <string, Type>("PointProperty", typeof(GeographyPoint)),
                new KeyValuePair <string, Type>("LineStringProperty", typeof(GeographyLineString)),
            };
            string entityTypeName = "AllGeographyTypes";

            SpatialTestUtil.AddEntityType(metadata, entityTypeName, geographyProperties, useComplexType: false, useOpenTypes: false);
            metadata.SetReadOnly();

            var service = new DSPUnitTestServiceDefinition(metadata, providerKind, new DSPContext());

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

                request.HttpMethod = "GET";
                XDocument response = UnitTestsUtil.GetResponseAsAtomXLinq(request, "/$metadata");

                XElement   schemaElement = response.Root.Element(UnitTestsUtil.EdmxNamespace + "DataServices").Elements().Single(e => e.Name.LocalName == "Schema");
                XNamespace edmNs         = schemaElement.Name.Namespace;
                XElement   entityElement = schemaElement.Elements(edmNs + "EntityType").Single(e => (string)e.Attribute("Name") == entityTypeName);

                foreach (KeyValuePair <string, Type> property in geographyProperties)
                {
                    XElement propertyElement = entityElement.Elements(edmNs + "Property").Single(e => (string)e.Attribute("Name") == property.Key);

                    // EF provider currently represents all types as Edm.Geography in metadata (property is DbGeography on the entity), otherwise it should reflect the actual type
                    string expectedEdmTypeName = providerKind == DSPDataProviderKind.EF ? "Edm.Geography" : GetExpectedEdmTypeName(property.Value);

                    Assert.AreEqual(expectedEdmTypeName, propertyElement.Attribute("Type").Value, "Wrong property type for property {0},", property.Key);

                    XAttribute attribute = propertyElement.Attributes().Where(a => a.Name == "SRID").Single();
                    Assert.AreEqual("Variable", attribute.Value);
                }
            }
        }
        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));
        }
Exemple #4
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);
                        }
                    });
                }
            });
        }