public static void ClassInitialize(TestContext context)
        {
            DSPDataProviderKind providerKind = DSPDataProviderKind.EF;
                                    
            // set up the service
            DSPMetadata metadata = GetModel(false /*openType*/, false /*namedStreams*/);
            DSPContext defaultData = GetDefaultData(metadata);

            DSPUnitTestServiceDefinition.ModifyGeneratedCode = (currentCode) => 
            {
                // Add namespace which includes Code First Attributes
                currentCode.Insert(currentCode.ToString().IndexOf("public class PeopleType"), "using System.ComponentModel.DataAnnotations;\n\n");

                // Add the required attributes
                currentCode.Insert(currentCode.ToString().IndexOf("public string Name { get; set; }"), "[Required()]\n");
                currentCode.Insert(currentCode.ToString().IndexOf("public byte[] Body { get; set; }"), "[Required()]\n");
                currentCode.Insert(currentCode.ToString().IndexOf("public int? Age { get; set; }"), "[Required()]\n");

                return currentCode;             
            };

            service = new DSPUnitTestServiceDefinition(metadata, providerKind, defaultData);           
            service.Writable = true;                                    
        }
예제 #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);
                }
            }
        }
예제 #3
0
        public void DollarValueGivesErrorForAllVerbs(DSPUnitTestServiceDefinition roadTripServiceDefinition, Action<TestWebRequest> sendRequestAndAssertBehavior)
        {
            using (TestWebRequest request = roadTripServiceDefinition.CreateForInProcess())
            {
                request.StartService();


                // GET
                request.Accept = UnitTestsUtil.MimeTextPlain;
                request.RequestContentType = null;
                request.HttpMethod = "GET";
                request.RequestUriString = string.Format("/TripLegs({0})/GeographyProperty1/$value", SpatialTestUtil.DefaultId);
                sendRequestAndAssertBehavior(request);

                // PUT
                request.HttpMethod = "PUT";
                request.RequestContentType = UnitTestsUtil.MimeTextPlain;
                request.RequestUriString = string.Format("/TripLegs({0})/GeographyProperty1/$value", SpatialTestUtil.DefaultId);
                string newValue = GmlFormatter.Create().Write(TestPoint.NewValues.TripLegGeography1.AsGeography());
                request.RequestStream = IOUtil.CreateStream(newValue);
                sendRequestAndAssertBehavior(request);

                // POST
                request.HttpMethod = "POST";
                sendRequestAndAssertBehavior(request);

                // PATCH
                request.HttpMethod = "PATCH";
                sendRequestAndAssertBehavior(request);

                // DELETE
                request.HttpMethod = "DELETE";
                string uri = string.Format("/TripLegs({0})/GeographyProperty1/$value", SpatialTestUtil.DefaultId);
                request.RequestUriString = uri;
                sendRequestAndAssertBehavior(request);
            }
        }
 public ChangeScope(DSPUnitTestServiceDefinition service, DSPContext defaultData)
 {
     this.unitTestService = service;
     this.defaultData = defaultData;
 }
예제 #5
0
        internal static DSPUnitTestServiceDefinition CreateRoadTripServiceDefinition(DSPMetadata roadTripMetadata, GeographyPropertyValues defaultValues, DSPDataProviderKind providerKind, bool useComplexType = false, Action<string, List<KeyValuePair<string, object>>> modifyPropertyValues = null)
        {
            Assert.IsFalse(useComplexType, "Complex type support is not yet added to the property population in DSPUnitTestServiceDefinition.");

            DSPContext defaultData = PopulateRoadTripData(roadTripMetadata, defaultValues, useComplexType, modifyPropertyValues);

            var service = new DSPUnitTestServiceDefinition(roadTripMetadata, providerKind, defaultData);
            service.HostInterfaceType = typeof(IDataServiceHost2);
            service.DataServiceBehavior.AcceptSpatialLiteralsInQuery = true;
            service.Writable = true;
            service.DataServiceBehavior.MaxProtocolVersion = ODataProtocolVersion.V4;

            return service;
        }
예제 #6
0
        public void DerivedProperty_OpenAndDeclaredPropertyWithSameName()
        {
            var metadata = GetModel(true /*openType*/, false /*namedStreams*/, metadataModifier: (m) =>
            {
                var fullNameProperty = new ResourceProperty("FullName", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(string))) { CanReflectOnInstanceTypeProperty = false };
                m.GetResourceType("CustomerType").AddProperty(fullNameProperty);
            });
            var serviceWithOpenTypes = new DSPUnitTestServiceDefinition(metadata, DSPDataProviderKind.CustomProvider, GetDefaultData(metadata));
            var testVersion = new ServiceVersions();

            var testCases = new DerivedPropertyTestCase[] {
                new DerivedPropertyTestCase() {
                    Services = new DSPUnitTestServiceDefinition[] { serviceWithOpenTypes },
                    RequestUris = new string[] { String.Format("/People?$select=ID,{0}/FullName", EmployeeTypeName) }, // project full name for employees
                    XPaths = new string[] {
                        "count(/atom:feed/atom:entry)=" + PeopleSetCount,
                        "count(/atom:feed/atom:entry/atom:content/adsm:properties/*[local-name()!='ID' and local-name()!=FullName])=0", // only ID and FullName properties must be projected for all entries
                        String.Format("count(/atom:feed/atom:entry[atom:category/@term!='#{0}' and atom:category/@term!='#{1}']/atom:content/adsm:properties[count(*)!=1])=0", EmployeeTypeName, ManagerTypeName), // People and Customer should have only one property i.e. ID
                        String.Format("count(/atom:feed/atom:entry[atom:category/@term!='#{0}' and atom:category/@term!='#{1}']/atom:content/adsm:properties/*[local-name()!='ID'])=0", EmployeeTypeName, ManagerTypeName), // People and Customershould have only one property i.e. ID
                        String.Format("count(/atom:feed/atom:entry[atom:category[@term='#{0}' or @term='3{1}']]/atom:content/adsm:properties[count(*)!=2])=0", EmployeeTypeName, ManagerTypeName), // Employee and Manager should have only 2 properties i.e. ID and FullName
                    },
                    Version = testVersion,
                },
                new DerivedPropertyTestCase() {
                    Services = new DSPUnitTestServiceDefinition[] { serviceWithOpenTypes },
                    RequestUris = new string[] { "/People?$select=ID,FullName" },
                    XPaths = new string[] {
                        "count(/atom:feed/atom:entry)=" + PeopleSetCount,
                        "count(/atom:feed/atom:entry/atom:content/adsm:properties/*[local-name()!='ID' and local-name()!=FullName])=0", // all entries should have FullName and ID projected out
                        "count(/atom:feed/atom:entry/atom:content/adsm:properties[count(*)!=2])=0", // all entries should have only 2 properties
                    },
                    Version = testVersion,
                }
            };

            SendRequestAndVerifyXPaths(testCases);
        }
예제 #7
0
        private static DSPUnitTestServiceDefinition GetUnitTestServiceDefinition(DSPDataProviderKind providerKind, bool openType, bool namedStreams)
        {
            DSPMetadata metadata = GetModel(openType, namedStreams);
            DSPContext defaultData = GetDefaultData(metadata);

            var service = new DSPUnitTestServiceDefinition(metadata, providerKind, defaultData);
            service.DataServiceBehavior.IncludeRelationshipLinksInResponse = true;
            service.Writable = true;

            if (providerKind == DSPDataProviderKind.CustomProvider)
            {
                service.SupportNamedStream = true;
                service.MediaResourceStorage = new DSPMediaResourceStorage();
            }

            return service;
        }
        public void AllowRedefiningConcurrencyTokenOnDerivedType()
        {
            var metadataProvider = new DSPMetadata("DefaultContainer", "Default");

            var entityType = metadataProvider.AddEntityType("EntityType", null, null, false /*isAbstract*/);
            metadataProvider.AddKeyProperty(entityType, "ID", typeof(int));
            metadataProvider.AddPrimitiveProperty(entityType, "LastUpdatedAuthor", typeof(string), true /*eTag*/);

            var derivedType = metadataProvider.AddEntityType("DerivedType", null, entityType, false /*isAbstract*/);
            metadataProvider.AddPrimitiveProperty(derivedType, "LastModifiedAuthor", typeof(string), true /*eTag*/);

            metadataProvider.AddResourceSet("Customers", entityType);

            var wrapper = new DataServiceMetadataProviderWrapper(metadataProvider);

            DSPResource baseTypeInstance = new DSPResource(entityType);
            baseTypeInstance.SetValue("ID", 1);
            baseTypeInstance.SetValue("LastUpdatedAuthor", "Phani");

            DSPResource derivedTypeInstance = new DSPResource(derivedType);
            derivedTypeInstance.SetValue("ID", 1);
            derivedTypeInstance.SetValue("LastModifiedAuthor", "Raj");

            DSPContext dataContext = new DSPContext();
            var entities = dataContext.GetResourceSetEntities("Customers");
            entities.AddRange(new object[] { baseTypeInstance, derivedTypeInstance });

            var service = new DSPUnitTestServiceDefinition(metadataProvider, DSPDataProviderKind.Reflection, dataContext);
            using (TestWebRequest request = service.CreateForInProcess())
            {
                try
                {
                    request.StartService();
                    request.RequestUriString = "/$metadata";
                    request.SendRequestAndCheckResponse();
                }
                finally
                {
                    request.StopService();
                }
            }
        }
예제 #9
0
        private DSPUnitTestServiceDefinition CreateTestService(bool openType = false)
        {
            DSPMetadata metadata = new DSPMetadata("SpatialQueryTests", "AstoriaUnitTests.Tests");
            var entityType = metadata.AddEntityType("SpatialEntity", null, null, false);
            metadata.AddKeyProperty(entityType, "ID", typeof(int));
            entityType.IsOpenType = openType;

            if (!openType)
            {
                metadata.AddPrimitiveProperty(entityType, "Geography", typeof(Geography));
                metadata.AddPrimitiveProperty(entityType, "Point", typeof(GeographyPoint));
                metadata.AddPrimitiveProperty(entityType, "Point2", typeof(GeographyPoint));
                metadata.AddPrimitiveProperty(entityType, "LineString", typeof(GeographyLineString));
                metadata.AddPrimitiveProperty(entityType, "Polygon", typeof(GeographyPolygon));
                metadata.AddPrimitiveProperty(entityType, "GeographyCollection", typeof(GeographyCollection));
                metadata.AddPrimitiveProperty(entityType, "MultiPoint", typeof(GeographyMultiPoint));
                metadata.AddPrimitiveProperty(entityType, "MultiLineString", typeof(GeographyMultiLineString));
                metadata.AddPrimitiveProperty(entityType, "MultiPolygon", typeof(GeographyMultiPolygon));

                metadata.AddPrimitiveProperty(entityType, "Geometry", typeof(Geometry));
                metadata.AddPrimitiveProperty(entityType, "GeometryPoint", typeof(GeometryPoint));
                metadata.AddPrimitiveProperty(entityType, "GeometryPoint2", typeof(GeometryPoint));
                metadata.AddPrimitiveProperty(entityType, "GeometryLineString", typeof(GeometryLineString));
                metadata.AddPrimitiveProperty(entityType, "GeometryPolygon", typeof(GeometryPolygon));
                metadata.AddPrimitiveProperty(entityType, "GeometryCollection", typeof(GeometryCollection));
                metadata.AddPrimitiveProperty(entityType, "GeometryMultiPoint", typeof(GeometryMultiPoint));
                metadata.AddPrimitiveProperty(entityType, "GeometryMultiLineString", typeof(GeometryMultiLineString));
                metadata.AddPrimitiveProperty(entityType, "GeometryMultiPolygon", typeof(GeometryMultiPolygon));
            }

            metadata.AddCollectionProperty(entityType, "CollectionOfPoints", typeof(GeographyPoint));
            metadata.AddCollectionProperty(entityType, "GeometryCollectionOfPoints", typeof(GeometryPoint));
            metadata.AddPrimitiveProperty(entityType, "GeographyNull", typeof(Geography));
            metadata.AddPrimitiveProperty(entityType, "GeometryNull", typeof(Geometry));

            metadata.AddResourceSet("Spatials", entityType);

            metadata.SetReadOnly();

            DSPContext context = new DSPContext();
            var set = context.GetResourceSetEntities("Spatials");

            for (int i = 0; i < 3; ++i)
            {
                DSPResource spatialEntity = new DSPResource(entityType);
                spatialEntity.SetValue("ID", i);
                spatialEntity.SetValue("Geography", GeographyFactory.Point(32.0 - i, -100.0).Build());
                spatialEntity.SetValue("Point", GeographyFactory.Point(33.1 - i, -110.0).Build());
                spatialEntity.SetValue("Point2", GeographyFactory.Point(32.1 - i, -110.0).Build());
                spatialEntity.SetValue("LineString", GeographyFactory.LineString(33.1 - i, -110.0).LineTo(35.97 - i, -110).Build());
                spatialEntity.SetValue("Polygon", GeographyFactory.Polygon().Ring(33.1 - i, -110.0).LineTo(35.97 - i, -110.15).LineTo(11.45 - i, 87.75).Ring(35.97 - i, -110).LineTo(36.97 - i, -110.15).LineTo(45.23 - i, 23.18).Build());
                spatialEntity.SetValue("GeographyCollection", GeographyFactory.Collection().Point(-19.99 - i, -12.0).Build());
                spatialEntity.SetValue("MultiPoint", GeographyFactory.MultiPoint().Point(10.2 - i, 11.2).Point(11.9 - i, 11.6).Build());
                spatialEntity.SetValue("MultiLineString", GeographyFactory.MultiLineString().LineString(10.2 - i, 11.2).LineTo(11.9 - i, 11.6).LineString(16.2 - i, 17.2).LineTo(18.9 - i, 19.6).Build());
                spatialEntity.SetValue("MultiPolygon", GeographyFactory.MultiPolygon().Polygon().Ring(10.2 - i, 11.2).LineTo(11.9 - i, 11.6).LineTo(11.45 - i, 87.75).Ring(16.2 - i, 17.2).LineTo(18.9 - i, 19.6).LineTo(11.45 - i, 87.75).Build());
                spatialEntity.SetValue("CollectionOfPoints", new List<GeographyPoint>()
                    {
                        GeographyFactory.Point(10.2, 99.5),
                        GeographyFactory.Point(11.2, 100.5)
                    });

                spatialEntity.SetValue("Geometry", GeometryFactory.Point(32.0 - i, -10.0).Build());
                spatialEntity.SetValue("GeometryPoint", GeometryFactory.Point(33.1 - i, -11.0).Build());
                spatialEntity.SetValue("GeometryPoint2", GeometryFactory.Point(32.1 - i, -11.0).Build());
                spatialEntity.SetValue("GeometryLineString", GeometryFactory.LineString(33.1 - i, -11.5).LineTo(35.97 - i, -11).Build());
                spatialEntity.SetValue("GeometryPolygon", GeometryFactory.Polygon().Ring(33.1 - i, -13.6).LineTo(35.97 - i, -11.15).LineTo(11.45 - i, 87.75).Ring(35.97 - i, -11).LineTo(36.97 - i, -11.15).LineTo(45.23 - i, 23.18).Build());
                spatialEntity.SetValue("GeometryCollection", GeometryFactory.Collection().Point(-19.99 - i, -12.0).Build());
                spatialEntity.SetValue("GeometryMultiPoint", GeometryFactory.MultiPoint().Point(10.2 - i, 11.2).Point(11.9 - i, 11.6).Build());
                spatialEntity.SetValue("GeometryMultiLineString", GeometryFactory.MultiLineString().LineString(10.2 - i, 11.2).LineTo(11.9 - i, 11.6).LineString(16.2 - i, 17.2).LineTo(18.9 - i, 19.6).Build());
                spatialEntity.SetValue("GeometryMultiPolygon", GeometryFactory.MultiPolygon().Polygon().Ring(10.2 - i, 11.2).LineTo(11.9 - i, 11.6).LineTo(11.45 - i, 87.75).Ring(16.2 - i, 17.2).LineTo(18.9 - i, 19.6).LineTo(11.45 - i, 87.75).Build());
                spatialEntity.SetValue("GeometryCollectionOfPoints", new List<GeometryPoint>()
                    {
                        GeometryFactory.Point(10.2, 99.5),
                        GeometryFactory.Point(11.2, 100.5)
                    });

                spatialEntity.SetValue("GeographyNull", null);
                spatialEntity.SetValue("GeometryNull", null);

                set.Add(spatialEntity);
            }

            var service = new DSPUnitTestServiceDefinition(metadata, DSPDataProviderKind.CustomProvider, context);
            service.DataServiceBehavior.AcceptSpatialLiteralsInQuery = true;
            service.Writable = true;

            return service;
        }