internal static DSPMetadata CreateRoadTripMetadata(Type geographyPropertyType, bool useComplexType = false, bool useOpenTypes = false, Action <DSPMetadata> modifyMetadata = null) { Assert.IsTrue(typeof(ISpatial).IsAssignableFrom(geographyPropertyType), "geographyPropertyType passed to CreateRoadTripMetadata is not a type derived from Geography."); string modelName = string.Format("RoadTripModelWith{0}", geographyPropertyType.Name); DSPMetadata metadata = new DSPMetadata(modelName, "AstoriaUnitTests.Tests"); // Geography property followed by another geography property KeyValuePair <string, Type>[] tripLegProperties = new KeyValuePair <string, Type>[] { new KeyValuePair <string, Type>("GeographyProperty1", geographyPropertyType), new KeyValuePair <string, Type>("GeographyProperty2", geographyPropertyType), }; AddEntityType(metadata, "TripLeg", tripLegProperties, useComplexType, useOpenTypes); // Geography property followed by another non-geography property KeyValuePair <string, Type>[] amusementParkProperties = new KeyValuePair <string, Type>[] { new KeyValuePair <string, Type>("GeographyProperty", geographyPropertyType), new KeyValuePair <string, Type>("Name", typeof(string)), }; AddEntityType(metadata, "AmusementPark", amusementParkProperties, useComplexType, useOpenTypes); // Geography property at the end of the entry KeyValuePair <string, Type>[] restStopProperties = new KeyValuePair <string, Type>[] { new KeyValuePair <string, Type>("GeographyProperty", geographyPropertyType), }; AddEntityType(metadata, "RestStop", restStopProperties, useComplexType, useOpenTypes); if (modifyMetadata != null) { modifyMetadata(metadata); } metadata.SetReadOnly(); return(metadata); }
private static DSPMetadata GetModel(bool openType, bool namedStreams, Action <DSPMetadata> metadataModifier = null) { #region Model Definition // Navigation Collection Property: Client - Entity, Server - NonEntity DSPMetadata metadata = new DSPMetadata("ModelWithNonNullableProperties", "AstoriaUnitTests.Tests"); // Define people type having non-nullable properties var peopleType = metadata.AddEntityType("PeopleType", null, null, false); var officeType = metadata.AddComplexType("OfficeType", null, null, false); metadata.AddPrimitiveProperty(officeType, "Building", typeof(string)); metadata.AddPrimitiveProperty(officeType, "OfficeNumber", typeof(int)); peopleType.IsOpenType = openType; metadata.AddKeyProperty(peopleType, "ID", typeof(int)); if (!openType) { metadata.AddPrimitiveProperty(peopleType, "Name", typeof(string)); metadata.AddPrimitiveProperty(peopleType, "Body", typeof(byte[])); metadata.AddPrimitiveProperty(peopleType, "Age", typeof(Nullable <int>)); metadata.AddComplexProperty(peopleType, "Office", officeType); } var peopleSet = metadata.AddResourceSet("People", peopleType); if (metadataModifier != null) { metadataModifier(metadata); } metadata.SetReadOnly(); #endregion Model Definition return(metadata); }
public static void ClassInitialize(TestContext context) { Metadata = new DSPMetadata(ServiceName, ServiceNamespace); CustomerResourceType = Metadata.AddEntityType("CustomerEntity", null, null, false); Metadata.AddKeyProperty(CustomerResourceType, "ID", typeof(int)); Metadata.AddPrimitiveProperty(CustomerResourceType, "Name", typeof(string), false); Metadata.AddResourceSet("CustomerEntities", CustomerResourceType); Metadata.SetReadOnly(); }
public void EdmValidNamesNotAllowedInUri() { DSPMetadata metadata = new DSPMetadata("Test", "TestNS"); var entityType = metadata.AddEntityType("MyType", null, null, false); metadata.AddKeyProperty(entityType, "ID", typeof(int)); metadata.AddPrimitiveProperty(entityType, "Pròjè_x00A2_tÎð瑞갂థ్క_x0020_Iiلإَّ", typeof(string)); var resourceSet = metadata.AddResourceSet("EntitySet", entityType); metadata.SetReadOnly(); DSPServiceDefinition service = new DSPServiceDefinition() { Metadata = metadata, Writable = true }; DSPContext data = new DSPContext(); service.CreateDataSource = (m) => { return(data); }; using (TestWebRequest request = service.CreateForInProcessWcf()) { request.StartService(); DataServiceContext context = new DataServiceContext(request.ServiceRoot); string value = "value of Pròjè_x00A2_tÎð瑞갂థ్క_x0020_Iiلإَّ"; context.AddObject("EntitySet", new MyType() { ID = 1, Pròjè_x00A2_tÎð瑞갂థ్క_x0020_Iiلإَّ = value, }); try { context.SaveChanges(); } catch (DataServiceRequestException exception) { Assert.AreEqual(exception.Message, "An error occurred while processing this request."); } } }
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); } } }
public void EdmValidNamesNotAllowedInUri() { DSPMetadata metadata = new DSPMetadata("Test", "TestNS"); var entityType = metadata.AddEntityType("MyType", null, null, false); metadata.AddKeyProperty(entityType, "ID", typeof(int)); metadata.AddPrimitiveProperty(entityType, "Pròjè_x00A2_tÎð瑞갂థ్క_x0020_Iiلإَّ", typeof(string)); var resourceSet = metadata.AddResourceSet("EntitySet", entityType); metadata.SetReadOnly(); DSPServiceDefinition service = new DSPServiceDefinition() { Metadata = metadata, Writable = true }; DSPContext data = new DSPContext(); service.CreateDataSource = (m) => { return(data); }; using (TestWebRequest request = service.CreateForInProcessWcf()) { request.StartService(); DataServiceContext context = new DataServiceContext(request.ServiceRoot); context.EnableAtom = true; context.Format.UseAtom(); string value = "value of Pròjè_x00A2_tÎð瑞갂థ్క_x0020_Iiلإَّ"; context.AddObject("EntitySet", new MyType() { ID = 1, Pròjè_x00A2_tÎð瑞갂థ్క_x0020_Iiلإَّ = value, }); context.SaveChanges(); var result = context.Execute <MyType>(new Uri("EntitySet?$orderby=Pròjè_x00A2_tÎð瑞갂థ్క_x0020_Iiلإَّ", UriKind.Relative)).First(); Assert.AreEqual(value, result.Pròjè_x00A2_tÎð瑞갂థ్క_x0020_Iiلإَّ, "The roundtrip value not as expected"); } }
private static DSPServiceDefinition SetupService() { DSPMetadata metadata = new DSPMetadata("ActionsWithLargePayload", "AstoriaUnitTests.ActionTestsWithLargePayload"); var customer = metadata.AddEntityType("Customer", null, null, false); metadata.AddKeyProperty(customer, "ID", typeof(int)); var customers = metadata.AddResourceSet("Customers", customer); ComplexType = metadata.AddComplexType("AddressComplexType", null, null, false); metadata.AddPrimitiveProperty(ComplexType, "ZipCode", typeof(int)); metadata.AddPrimitiveProperty(ComplexType, "City", typeof(string)); DSPContext context = new DSPContext(); metadata.SetReadOnly(); DSPResource customer1 = new DSPResource(customer); customer1.SetValue("ID", 1); context.GetResourceSetEntities("Customers").Add(customer1); MyDSPActionProvider actionProvider = new MyDSPActionProvider(); SetUpActionWithLargeParameterPayload(actionProvider, metadata, customer); SetUpActionWithLargeCollectionParameterPayload(actionProvider, metadata, customer); SetupLargeNumberOfActions(actionProvider, metadata, customer); DSPServiceDefinition service = new DSPServiceDefinition() { Metadata = metadata, CreateDataSource = (m) => context, ForceVerboseErrors = true, Writable = true, ActionProvider = actionProvider, }; return(service); }
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); }