forked from SharpMap/SharpMap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDbTests.cs
More file actions
182 lines (166 loc) · 6.48 KB
/
DbTests.cs
File metadata and controls
182 lines (166 loc) · 6.48 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
173
174
175
176
177
178
179
180
181
182
namespace UnitTests.Data.Providers
{
[NUnit.Framework.TestFixture]
public abstract class DbTests<TProvider> where TProvider : SharpMap.Data.Providers.SpatialDbProvider
{
[NUnit.Framework.OneTimeSetUp]
public void OneTimeSetUp()
{
try
{
using (var cn = GetOpenConnection())
{
cn.Close();
}
}
catch (System.Exception)
{
throw new NUnit.Framework.IgnoreException("Provider cound not be instantiated!");
}
}
protected abstract System.Data.Common.DbConnection GetOpenConnection();
protected TProvider GetProvider()
{
try
{
return GetProviderInternal();
}
catch (System.Exception)
{
throw new NUnit.Framework.IgnoreException("Provider cound not be instantiated!");
}
}
protected abstract TProvider GetProviderInternal();
protected string TestTable;
protected string TestOidColumn;
protected string TestGeometryColumn;
[NUnit.Framework.Test]
public void Test01EstablishConnection()
{
using (var conn = GetOpenConnection())
{
NUnit.Framework.Assert.IsTrue(conn.State == System.Data.ConnectionState.Open);
}
}
[NUnit.Framework.Test]
public void Test02CreateProvider()
{
using (var provider = GetProvider())
{
NUnit.Framework.Assert.IsNotNull(provider, "Creation of provider failed");
NUnit.Framework.Assert.AreEqual(provider.ConnectionID, Properties.Settings.Default.MsSqlSpatial, "ConnectionID is not correct");
NUnit.Framework.Assert.IsTrue(provider.SRID >= 0);
}
}
[NUnit.Framework.Test]
public void Test03GetFeatureCount()
{
using (var provider = GetProvider())
{
var fc = provider.GetFeatureCount();
NUnit.Framework.Assert.IsNotNull(fc > 0);
}
}
[NUnit.Framework.Test]
public void Test04GetExtents()
{
using (var provider = GetProvider())
{
var extent = provider.GetExtents();
NUnit.Framework.Assert.IsNotNull(extent);
NUnit.Framework.Assert.IsFalse(extent.IsNull);
}
}
[NUnit.Framework.Test]
public void Test05GetOidInView()
{
using (var provider = GetProvider())
{
var extent = provider.GetExtents();
var oids = provider.GetObjectIDsInView(extent);
NUnit.Framework.Assert.IsNotNull(oids);
NUnit.Framework.Assert.AreEqual(provider.GetFeatureCount(), oids.Count);
}
}
[NUnit.Framework.Test]
public void Test06GetGeometriesInView()
{
using (var provider = GetProvider())
{
var extent = provider.GetExtents();
var geoms = provider.GetGeometriesInView(extent);
NUnit.Framework.Assert.IsNotNull(geoms);
NUnit.Framework.Assert.AreEqual(provider.GetFeatureCount(), geoms.Count);
}
}
[NUnit.Framework.Test]
public void Test07GetGeometryByID()
{
using (var provider = GetProvider())
{
GeoAPI.Geometries.IGeometry result = null;
NUnit.Framework.Assert.DoesNotThrow( () => result = provider.GetGeometryByID(1));
NUnit.Framework.Assert.IsNotNull(result);
}
}
[NUnit.Framework.Test]
public void Test09ExecuteIntersectionQuery()
{
using (var provider = GetProvider())
{
var ext = provider.GetExtents();
ext.ExpandBy(-0.25*ext.Width, -0.25*ext.Height);
var fds = new SharpMap.Data.FeatureDataSet();
NUnit.Framework.Assert.DoesNotThrow(() => provider.ExecuteIntersectionQuery(ext, fds));
NUnit.Framework.Assert.Greater(fds.Tables.Count, 0);
NUnit.Framework.Assert.Greater(fds.Tables[0].Count, 0);
NUnit.Framework.Assert.Less(fds.Tables[0].Count, provider.GetFeatureCount());
}
}
[NUnit.Framework.Test]
public void Test10ExecuteIntersectionQuery()
{
using (var provider = GetProvider())
{
var ext = provider.GetExtents();
ext.ExpandBy(-0.25 * ext.Width, -0.25 * ext.Height);
var geom = provider.Factory.ToGeometry(ext);
var fds = new SharpMap.Data.FeatureDataSet();
NUnit.Framework.Assert.DoesNotThrow(() => provider.ExecuteIntersectionQuery(geom, fds));
NUnit.Framework.Assert.Greater(fds.Tables.Count, 0);
NUnit.Framework.Assert.Greater(fds.Tables[0].Count, 0);
NUnit.Framework.Assert.Less(fds.Tables[0].Count, provider.GetFeatureCount());
}
}
[NUnit.Framework.Test]
public void Test11GetFeature()
{
using (var provider = GetProvider())
{
SharpMap.Data.FeatureDataRow feature = null;
NUnit.Framework.Assert.DoesNotThrow(()=> feature = provider.GetFeature(5));
NUnit.Framework.Assert.NotNull(feature);
NUnit.Framework.Assert.AreEqual(5, feature[provider.ObjectIdColumn]);
}
}
[NUnit.Framework.Test]
public void Test99GetMap()
{
var m = new SharpMap.Map(new System.Drawing.Size(512, 1048));
var p = GetProvider();
//p.SRID = 4326;
//p.TargetSRID = 25832;
var l = new SharpMap.Layers.VectorLayer("SpDb", p);
m.Layers.Add(l);
m.ZoomToExtents();
var path = System.IO.Path.Combine(UnitTestsFixture.GetImageDirectory(this), $"SpatialDbProvider_{ImplementationName}.png");
using (var i = m.GetMap())
i.Save(path, System.Drawing.Imaging.ImageFormat.Png);
System.Diagnostics.Trace.WriteLine(new System.Uri(path).LocalPath);
}
/// <summary>
/// Gets the name of the test implementation
/// </summary>
public abstract string ImplementationName { get; }
}
}