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 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() }); }
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); }