forked from SharpMap/SharpMap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProviderTest.cs
More file actions
172 lines (148 loc) · 7.58 KB
/
ProviderTest.cs
File metadata and controls
172 lines (148 loc) · 7.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
using System;
using System.IO;
using GeoAPI.Geometries;
using NUnit.Framework;
using SharpMap.Data.Providers;
namespace UnitTests.Serialization
{
public class ProviderTest : BaseSerializationTest
{
[OneTimeSetUp]
public void OneTimeSetUp()
{
GeoAPI.GeometryServiceProvider.Instance = new NetTopologySuite.NtsGeometryServices();
}
internal static IProvider CreateProvider(string name=null)
{
name = name ?? "geometryprovider";
switch (name.ToLower())
{
default:
//case "geometryprovider":
return CreateProvider<GeometryProvider>();
case "shapefile":
return CreateProvider<ShapeFile>();
case "postgis":
return CreateProvider<PostGIS>();
case "managedspatialite":
return CreateProvider<ManagedSpatiaLite>();
case "spatialite":
return CreateProvider<SpatiaLite>();
}
}
internal static T CreateProvider<T>()
where T: IProvider
{
try
{
var gf = GeoAPI.GeometryServiceProvider.Instance.CreateGeometryFactory();
if (typeof(T) == typeof(GeometryProvider))
return (T) (IProvider) new GeometryProvider(gf.CreatePoint(new Coordinate(1, 1)));
if (typeof(T) == typeof(ShapeFile))
return (T) (IProvider) new ShapeFile(TestUtility.GetPathToTestFile("roads_ugl.shp"));
if (typeof(T) == typeof(PostGIS))
return (T) (IProvider) new PostGIS(
"Host=ivv-t3s.ivv-aachen.de;Port=5432;integrated security=true;database=postgis_sample;",
"rivers", "wkb_geometry", "ogc_fid");
if (typeof(T) == typeof(ManagedSpatiaLite))
return (T)(IProvider)new ManagedSpatiaLite($"Data Source={TestUtility.GetPathToTestFile("test-2.3.sqlite")};",
"HighWays", "Geometry", "PK_UID");
if (typeof(T) == typeof(SpatiaLite))
return (T)(IProvider)new SpatiaLite($"Data Source={TestUtility.GetPathToTestFile("test-2.3.sqlite")};",
"HighWays", "Geometry", "PK_UID");
#if !LINUX
if (typeof(T) == typeof(SqlServer2008))
return (T)(IProvider)new SqlServer2008("Data Source=IVV-SQLD; Database=OBE;Integrated Security=SSPI;",
"Roads", "wkb_geometry", "ogc_fid", SqlServerSpatialObjectType.Geometry);
#endif
throw new NotSupportedException();
}
catch (Exception e)
{
Assert.Ignore("Failed to open connection\n{0}\n{1}", e.Message, e.StackTrace);
throw;
}
}
[Test]
public void TestGeometryProvider()
{
var gpS = CreateProvider<GeometryProvider>();
var gpD = SandD(gpS, GetFormatter());
Assert.AreEqual(gpS.GetType(), gpD.GetType());
Assert.AreEqual(gpS.Geometries.Count, gpD.Geometries.Count);
Assert.AreEqual(gpS.GetExtents(), gpD.GetExtents());
Assert.IsTrue(gpS.Geometries[0].Coordinate.X == 1);
}
#if !LINUX
[Test]
public void TestSpatiaLite2()
{
var spatiaLite2S = new ManagedSpatiaLite($"Data Source={Path.Combine("TestData", "test-2.3.sqlite")};Database=Regions;",
"Roads", "Geometry", "PK_UID");
var spatiaLite2 = SandD(spatiaLite2S, GetFormatter());
Assert.AreEqual(spatiaLite2S.ConnectionString, spatiaLite2.ConnectionString);
Assert.AreEqual(spatiaLite2S.Table, spatiaLite2.Table);
Assert.AreEqual(spatiaLite2S.GeometryColumn, spatiaLite2.GeometryColumn);
Assert.AreEqual(spatiaLite2S.ObjectIdColumn, spatiaLite2.ObjectIdColumn);
Assert.AreEqual(spatiaLite2S.SRID, spatiaLite2.SRID);
}
#endif
[Test, Ignore("Postgres Connection string needs to be ok")]
public void TestPostGIS()
{
using (var pS = CreateProvider<PostGIS>())
{
//new PostGIS(Properties.Settings.Default.PostGis,
// "rivers", "wkb_geometry", "ogc_fid");
PostGIS pD = null;
Assert.DoesNotThrow(() => pD = SandD(pS, GetFormatter()));
Assert.AreEqual(pS.ConnectionString, pD.ConnectionString);
Assert.AreEqual(pS.Table, pD.Table);
Assert.AreEqual(pS.GeometryColumn, pD.GeometryColumn);
Assert.AreEqual(pS.ObjectIdColumn, pD.ObjectIdColumn);
Assert.AreEqual(pS.SRID, pD.SRID);
pD.Dispose();
}
}
#if !LINUX
[NUnit.Framework.TestCase(SqlServerSpatialObjectType.Geometry)]
[NUnit.Framework.TestCase(SqlServerSpatialObjectType.Geography)]
public void TestSqlServer2008(SqlServerSpatialObjectType spatialType)
{
var sql2008S = new SqlServer2008("Data Source=IVV-SQLD; Database=OBE;Integrated Security=SSPI;",
"roads", "spatialCol", "idCol",
spatialType,
4326,
SqlServer2008ExtentsMode.EnvelopeAggregate);
var sql2008D = SandD(sql2008S, GetFormatter());
Assert.AreEqual(sql2008S.ConnectionString, sql2008D.ConnectionString);
Assert.AreEqual(sql2008S.Table, sql2008D.Table);
Assert.AreEqual(sql2008S.TableSchema, sql2008D.TableSchema);
Assert.AreEqual(sql2008S.GeometryColumn, sql2008D.GeometryColumn);
Assert.AreEqual(sql2008S.ObjectIdColumn, sql2008D.ObjectIdColumn);
Assert.AreEqual(sql2008S.SpatialObjectType, sql2008D.SpatialObjectType);
Assert.AreEqual(sql2008S.SRID, sql2008D.SRID);
Assert.AreEqual(sql2008S.ExtentsMode, sql2008D.ExtentsMode);
}
[NUnit.Framework.TestCase(SqlServerSpatialObjectType.Geometry)]
[NUnit.Framework.TestCase(SqlServerSpatialObjectType.Geography)]
public void TestSqlServer2008Ex(SqlServerSpatialObjectType spatialType)
{
var sql2008S = new SqlServer2008Ex("Data Source=IVV-SQLD; Database=OBE;Integrated Security=SSPI;",
"roads", "spatialCol", "idCol",
spatialType,
4326,
SqlServer2008ExtentsMode.EnvelopeAggregate);
var sql2008D = SandD(sql2008S, GetFormatter());
Assert.AreEqual(sql2008S.ConnectionString, sql2008D.ConnectionString);
Assert.AreEqual(sql2008S.Table, sql2008D.Table);
Assert.AreEqual(sql2008S.TableSchema, sql2008D.TableSchema);
Assert.AreEqual(sql2008S.GeometryColumn, sql2008D.GeometryColumn);
Assert.AreEqual(sql2008S.ObjectIdColumn, sql2008D.ObjectIdColumn);
Assert.AreEqual(sql2008S.SpatialObjectType, sql2008D.SpatialObjectType);
Assert.AreEqual(sql2008S.SRID, sql2008D.SRID);
Assert.AreEqual(sql2008S.ExtentsMode, sql2008D.ExtentsMode);
}
#endif
}
}