protected override DSPMetadata CreateDSPMetadata() { DSPMetadata metadata = new DSPMetadata("DemoService", "DataServiceProviderDemo"); ResourceType product = metadata.AddEntityType("Product"); metadata.AddKeyProperty(product, "ID", typeof(int)); metadata.AddPrimitiveProperty(product, "Name", typeof(string)); metadata.AddPrimitiveProperty(product, "Description", typeof(string)); metadata.AddPrimitiveProperty(product, "ReleaseDate", typeof(DateTime)); metadata.AddPrimitiveProperty(product, "DiscontinueDate", typeof(DateTime?)); metadata.AddPrimitiveProperty(product, "Rating", typeof(int)); ResourceSet products = metadata.AddResourceSet("Products", product); ResourceType category = metadata.AddEntityType("Category"); metadata.AddKeyProperty(category, "ID", typeof(int)); metadata.AddPrimitiveProperty(category, "Name", typeof(string)); ResourceSet categories = metadata.AddResourceSet("Categories", category); // Add reference properties between category and product metadata.AddResourceReferenceProperty(product, "Category", categories); metadata.AddResourceSetReferenceProperty(category, "Products", products); return(metadata); }
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(); } } }
private DSPServiceDefinition CreateCollectionReadService(Dictionary <Type, object> data) { DSPMetadata metadata = new DSPMetadata("SpatialServerIntegration", "AstoriaUnitTests.Tests"); var entityType = metadata.AddEntityType("EntityType", null, null, false); metadata.AddResourceSet("Entities", entityType); metadata.AddKeyProperty(entityType, "ID", typeof(int)); foreach (Type t in data.Keys) { metadata.AddCollectionProperty(entityType, "Collection" + t.Name, t); } DSPContext dataSource = new DSPContext(); var entities = dataSource.GetResourceSetEntities("Entities"); var resource = new DSPResource(entityType); resource.SetValue("ID", 0); foreach (KeyValuePair <Type, object> d in data) { resource.SetValue("Collection" + d.Key.Name, d.Value); } entities.Add(resource); return(new DSPServiceDefinition() { Metadata = metadata, DataSource = dataSource }); }
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); }
internal static void AddEntityType(DSPMetadata metadata, string entityTypeName, KeyValuePair <string, Type>[] properties, bool useComplexType, bool useOpenTypes) { var entityType = metadata.AddEntityType(entityTypeName, null, null, false); metadata.AddKeyProperty(entityType, "ID", typeof(int)); entityType.IsOpenType = useOpenTypes; if (!useOpenTypes) { Microsoft.OData.Service.Providers.ResourceType resourceTypeForProps; if (useComplexType) { string complexTypeName = GetComplexTypeName(entityTypeName); resourceTypeForProps = metadata.AddComplexType(complexTypeName, null, null, false); metadata.AddComplexProperty(entityType, "ComplexProperty", resourceTypeForProps); } else { resourceTypeForProps = entityType; } foreach (KeyValuePair <string, Type> property in properties) { metadata.AddPrimitiveProperty(resourceTypeForProps, property.Key, property.Value); } } string resourceSetName = GetResourceSetName(entityTypeName); metadata.AddResourceSet(resourceSetName, entityType); }
protected override void PopulateMetadata(DSPMetadata metadata, MongoContext context) { foreach (var collectionName in GetCollectionNames(context)) { var collection = context.Database.GetCollection(collectionName); var document = collection.FindOne(); if (document != null) { var collectionType = metadata.AddEntityType(collectionName); foreach (var element in document.Elements) { var elementType = GetElementType(context, element); if (element.Name == "_id") { metadata.AddKeyProperty(collectionType, "ID", elementType); } else if (elementType == typeof(BsonDocument)) { string referencedCollectionName = GetDocumentCollection(context, element.Value.AsBsonDocument).Name; resourceReferences.Add(new Tuple <ResourceType, string, string>(collectionType, element.Name, referencedCollectionName)); } else if (elementType == typeof(BsonArray)) { var bsonArray = element.Value.AsBsonArray; if (bsonArray != null && bsonArray.Count > 0) { string referencedCollectionName = GetDocumentCollection(context, bsonArray[0].AsBsonDocument).Name; resourceSetReferences.Add(new Tuple <ResourceType, string, string>(collectionType, element.Name, referencedCollectionName)); } } else { metadata.AddPrimitiveProperty(collectionType, element.Name, elementType); } } metadata.AddResourceSet(collectionName, collectionType); } } foreach (var reference in resourceReferences) { var referencedResourceSet = metadata.ResourceSets.Where(x => x.Name == reference.Item3).SingleOrDefault(); if (referencedResourceSet != null) { metadata.AddResourceSetReferenceProperty(reference.Item1, reference.Item2, referencedResourceSet); } } foreach (var reference in resourceSetReferences) { var referencedResourceSet = metadata.ResourceSets.Where(x => x.Name == reference.Item3).SingleOrDefault(); if (referencedResourceSet != null) { metadata.AddResourceSetReferenceProperty(reference.Item1, reference.Item2, referencedResourceSet); } } }
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(); }
/// <summary> /// Create a service for a specific spatial property type. /// </summary> /// <remarks> /// DEVNOTE(pqian): /// The service will populate with properties named after the property type, with a sequence number /// indicating which test sample it holds. For example, if the method is called with 3 sample data, /// and the target type is GeographyPoint, then the service will look like /// EntityType: /// ID /// GeographyPoint1 /// GeographyPoint2 /// GeographyPoint3 /// </remarks> /// <typeparam name="T">The target type</typeparam> /// <param name="data">Sample Data</param> /// <param name="overrideType">Use this type instead of typeof(T)</param> /// <param name="openProperty">Use Open Type</param> /// <param name="writable">Writable service</param> /// <returns>The constructed service definition</returns> private DSPServiceDefinition CreateSpatialPropertyService <T>(T[] data, Type overrideType = null, bool openProperty = false, bool writable = false) { Type propertyType = overrideType ?? typeof(T); DSPMetadata metadata = new DSPMetadata("SpatialServerIntegration", "AstoriaUnitTests.Tests"); var entityType = metadata.AddEntityType("EntityType", null, null, false); metadata.AddResourceSet("Entities", entityType); metadata.AddKeyProperty(entityType, "ID", typeof(int)); if (!openProperty) { for (int i = 0; i < data.Length; ++i) { metadata.AddPrimitiveProperty(entityType, propertyType.Name + i, propertyType); } } entityType.IsOpenType = openProperty; var definition = new DSPServiceDefinition() { Metadata = metadata }; if (writable) { definition.CreateDataSource = (m) => new DSPContext(); definition.Writable = true; } else { DSPContext dataSource = new DSPContext(); var entities = dataSource.GetResourceSetEntities("Entities"); var resource = new DSPResource(entityType); resource.SetValue("ID", 0); for (int i = 0; i < data.Length; ++i) { if (!openProperty) { metadata.AddPrimitiveProperty(entityType, propertyType.Name + i, propertyType); } resource.SetValue(propertyType.Name + i, data[i]); } entities.Add(resource); definition.DataSource = dataSource; } return(definition); }
protected override void PopulateMetadata(DSPMetadata metadata, MongoContext context) { var itemsType = new ResourceType(typeof(Dictionary <string, object>), ResourceTypeKind.ComplexType, null, "Northwind", "Items", false); foreach (var collectionName in GetCollectionNames(context)) { var collectionType = metadata.AddEntityType(collectionName); metadata.AddKeyProperty(collectionType, "Id", typeof(string)); metadata.AddComplexProperty(collectionType, "Items", itemsType); metadata.AddResourceSet(collectionName, collectionType); } }
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."); } } }
public void SpatialAsKeys() { var types = testData.Select(kvp => SpatialTestUtil.GeographyTypeFor(kvp.Key)) .Union(testData.Select(kvp => SpatialTestUtil.GeometryTypeFor(kvp.Key))) .Union(new Type[] { typeof(Geography), typeof(Geometry) }) .ToArray(); TestUtil.RunCombinations(types, (t) => { DSPMetadata metadata = new DSPMetadata("SpatialServerIntegration", "AstoriaUnitTests.Tests"); var entityType = metadata.AddEntityType("EntityType", null, null, false); metadata.AddResourceSet("Entities", entityType); Exception ex = TestUtil.RunCatching <InvalidOperationException>( () => metadata.AddKeyProperty(entityType, "ID", t)); Assert.IsNotNull(ex); Assert.AreEqual(DataServicesResourceUtil.GetString("ResourceType_SpatialKeyOrETag", "ID", "EntityType"), ex.Message); }); }
private DSPServiceDefinition CreateCollectionWriteService(List <Type> types) { DSPMetadata metadata = new DSPMetadata("SpatialServerIntegration", "AstoriaUnitTests.Tests"); var entityType = metadata.AddEntityType("EntityType", null, null, false); metadata.AddResourceSet("Entities", entityType); metadata.AddKeyProperty(entityType, "ID", typeof(int)); foreach (Type t in types) { metadata.AddCollectionProperty(entityType, "Collection" + t.Name, t); } return(new DSPServiceDefinition() { Metadata = metadata, Writable = true, CreateDataSource = (m) => new DSPContext() }); }
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"); } }
public void SetsMustBeReadOnlyTest() { var resourceSetEntryPoints = new Action <DataServiceMetadataProviderWrapper, string>[] { (wrapper, name) => wrapper.TryResolveResourceSet(name), (wrapper, name) => wrapper.ResourceSets.Cast <object>().Count() }; AstoriaTestNS.TestUtil.RunCombinations( resourceSetEntryPoints, (resourceSetEntryPoint) => { var metadataProvider = new DSPMetadata("Test", "TestNS"); var resourceType = metadataProvider.AddEntityType("EntityType", null, null, false); var resourceSet = metadataProvider.AddResourceSet("Entities", resourceType); resourceType.SetReadOnly(); var wrapper = new DataServiceMetadataProviderWrapper(metadataProvider); ExceptionUtils.ExpectedException <DataServiceException>( () => resourceSetEntryPoint(wrapper, resourceSet.Name), "The resource set '" + resourceSet.Name + "' returned by the provider is not read-only. Please make sure that all the resource sets are set to read-only.", "Accessing writable resource set should fail."); }); }
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); }
internal static DSPServiceDefinition SetUpNamedStreamService() { DSPMetadata metadata = new DSPMetadata("NamedStreamIDSPContainer", "NamedStreamTest"); // entity with streams ResourceType entityWithNamedStreams = metadata.AddEntityType("EntityWithNamedStreams", null, null, false); metadata.AddKeyProperty(entityWithNamedStreams, "ID", typeof(int)); metadata.AddPrimitiveProperty(entityWithNamedStreams, "Name", typeof(string)); ResourceProperty streamInfo1 = new ResourceProperty("Stream1", ResourcePropertyKind.Stream, ResourceType.GetPrimitiveResourceType(typeof(Stream))); entityWithNamedStreams.AddProperty(streamInfo1); ResourceProperty streamInfo2 = new ResourceProperty("Stream2", ResourcePropertyKind.Stream, ResourceType.GetPrimitiveResourceType(typeof(Stream))); entityWithNamedStreams.AddProperty(streamInfo2); // entity1 with streams ResourceType entityWithNamedStreams1 = metadata.AddEntityType("EntityWithNamedStreams1", null, null, false); metadata.AddKeyProperty(entityWithNamedStreams1, "ID", typeof(int)); metadata.AddPrimitiveProperty(entityWithNamedStreams1, "Name", typeof(string)); ResourceProperty refStreamInfo1 = new ResourceProperty("RefStream1", ResourcePropertyKind.Stream, ResourceType.GetPrimitiveResourceType(typeof(Stream))); entityWithNamedStreams1.AddProperty(refStreamInfo1); // entity2 with streams ResourceType entityWithNamedStreams2 = metadata.AddEntityType("EntityWithNamedStreams2", null, null, false); metadata.AddKeyProperty(entityWithNamedStreams2, "ID", typeof(string)); metadata.AddPrimitiveProperty(entityWithNamedStreams2, "Name", typeof(string)); ResourceProperty collectionStreamInfo = new ResourceProperty("ColStream", ResourcePropertyKind.Stream, ResourceType.GetPrimitiveResourceType(typeof(Stream))); entityWithNamedStreams2.AddProperty(collectionStreamInfo); ResourceSet set1 = metadata.AddResourceSet("MySet1", entityWithNamedStreams); ResourceSet set2 = metadata.AddResourceSet("MySet2", entityWithNamedStreams1); ResourceSet set3 = metadata.AddResourceSet("MySet3", entityWithNamedStreams2); // add navigation property to entityWithNamedStreams metadata.AddResourceReferenceProperty(entityWithNamedStreams, "Ref", set2, entityWithNamedStreams1); metadata.AddResourceSetReferenceProperty(entityWithNamedStreams, "Collection", set3, entityWithNamedStreams2); metadata.AddResourceSetReferenceProperty(entityWithNamedStreams2, "Collection1", set2, entityWithNamedStreams1); DSPServiceDefinition service = new DSPServiceDefinition(); service.Metadata = metadata; service.MediaResourceStorage = new DSPMediaResourceStorage(); service.SupportMediaResource = true; service.SupportNamedStream = true; service.ForceVerboseErrors = true; service.PageSizeCustomizer = (config, type) => { config.SetEntitySetPageSize("MySet3", 1); }; // populate data DSPContext context = new DSPContext(); DSPResource entity1 = new DSPResource(entityWithNamedStreams); { context.GetResourceSetEntities("MySet1").Add(entity1); entity1.SetValue("ID", 1); entity1.SetValue("Name", "Foo"); DSPMediaResource namedStream1 = service.MediaResourceStorage.CreateMediaResource(entity1, streamInfo1); namedStream1.ContentType = "image/jpeg"; byte[] data1 = new byte[] { 0, 1, 2, 3, 4 }; namedStream1.GetWriteStream().Write(data1, 0, data1.Length); DSPMediaResource namedStream2 = service.MediaResourceStorage.CreateMediaResource(entity1, streamInfo2); namedStream2.ContentType = "image/jpeg"; byte[] data2 = new byte[] { 0, 1, 2, 3, 4 }; namedStream2.GetWriteStream().Write(data2, 0, data2.Length); } DSPResource entity2 = new DSPResource(entityWithNamedStreams1); { context.GetResourceSetEntities("MySet2").Add(entity2); entity2.SetValue("ID", 3); entity2.SetValue("Name", "Bar"); DSPMediaResource refNamedStream1 = service.MediaResourceStorage.CreateMediaResource(entity2, refStreamInfo1); refNamedStream1.ContentType = "image/jpeg"; byte[] data1 = new byte[] { 0, 1, 2, 3, 4 }; refNamedStream1.GetWriteStream().Write(data1, 0, data1.Length); // set the navigation property entity1.SetValue("Ref", entity2); } { DSPResource entity3 = new DSPResource(entityWithNamedStreams2); context.GetResourceSetEntities("MySet3").Add(entity3); entity3.SetValue("ID", "ABCDE"); entity3.SetValue("Name", "Bar"); DSPMediaResource stream = service.MediaResourceStorage.CreateMediaResource(entity3, collectionStreamInfo); stream.ContentType = "image/jpeg"; byte[] data1 = new byte[] { 0, 1, 2, 3, 4 }; stream.GetWriteStream().Write(data1, 0, data1.Length); entity3.SetValue("Collection1", new List <DSPResource>() { entity2 }); DSPResource entity4 = new DSPResource(entityWithNamedStreams2); context.GetResourceSetEntities("MySet3").Add(entity4); entity4.SetValue("ID", "XYZ"); entity4.SetValue("Name", "Foo"); DSPMediaResource stream1 = service.MediaResourceStorage.CreateMediaResource(entity3, collectionStreamInfo); stream1.ContentType = "image/jpeg"; stream1.GetWriteStream().Write(data1, 0, data1.Length); entity4.SetValue("Collection1", new List <DSPResource>() { entity2 }); entity1.SetValue("Collection", new List <DSPResource>() { entity3, entity4 }); } service.DataSource = context; 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); }