forked from SharpMap/SharpMap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDbPointProviderTest.cs
More file actions
188 lines (165 loc) · 6.47 KB
/
DbPointProviderTest.cs
File metadata and controls
188 lines (165 loc) · 6.47 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
183
184
185
186
187
188
using System;
using GeoAPI.Geometries;
using NUnit.Framework;
using SharpMap.Data;
using SharpMap.Data.Providers;
namespace UnitTests.Data.Providers
{
[Category("RequiresWindows")]
public class DbPointProviderTest : ProviderTest
{
private System.Data.Common.DbConnection _connection; // Keep connection active; when closed, the in-memory database is dropped
public override void OneTimeSetUp()
{
base.OneTimeSetUp();
_connection = WriteSqlLite();
}
private static System.Data.Common.DbConnection WriteSqlLite()
{
// Set up sample table
var conn = System.Data.SQLite.SQLiteFactory.Instance.CreateConnection();
conn.ConnectionString = "FullUri=file::memory:?cache=shared;ToFullPath=false";
conn.Open();
using (var cmd = conn.CreateCommand())
{
cmd.CommandText =
"CREATE TABLE DbPointProviderTest(ID integer primary key, Name text, X real, Y real);";
cmd.ExecuteNonQuery();
}
using (var cmd = conn.CreateCommand())
{
cmd.CommandText =
"INSERT INTO DbPointProviderTest(ID, Name, X, Y) VALUES" +
" (1, 'One', 429012.5, 360443.18)," +
" (2, 'Two', 429001.59, 360446.98)," +
" (3, 'Three', 429003.31, 360425.45)," +
" (4, 'Four', 429016.9, 360413.04)";
cmd.ExecuteNonQuery();
}
return conn;
}
[OneTimeTearDown]
public void OneTimeTearDown()
{
_connection.Close();
}
private DbPoint CreateProvider()
{
var p = new DbPoint(System.Data.SQLite.SQLiteFactory.Instance,
"FullUri=file::memory:?cache=shared;ToFullPath=false", "DbPointProviderTest", "ID", "X", "Y");
return p;
}
[Test]
public void TestGetExtents()
{
using (var p = CreateProvider())
{
Envelope env = null;
Assert.DoesNotThrow(() => env = p.GetExtents());
Assert.IsNotNull(env);
Assert.IsFalse(env.IsNull);
}
}
[Test]
public void TestGetFeatureCount()
{
using (var p = CreateProvider())
{
var numFeatures = 0;
Assert.DoesNotThrow(() => numFeatures = p.GetFeatureCount());
Assert.AreEqual(4, numFeatures);
p.DefinitionQuery = "Name='Two'";
Assert.DoesNotThrow(() => numFeatures = p.GetFeatureCount());
Assert.AreEqual(1, numFeatures);
}
}
[Test]
public void TestGetFeature()
{
using (var p = CreateProvider())
{
FeatureDataRow feature = null;
Assert.DoesNotThrow(() => feature = p.GetFeature(3));
Assert.IsNotNull(feature);
Assert.AreEqual(3, Convert.ToInt32(feature[p.ObjectIdColumn]));
Assert.AreEqual(feature.Geometry.Centroid.Coordinate,
new Coordinate(429003.31, 360425.45));
}
}
[Test]
public void TestGetGeometryById()
{
using (var p = CreateProvider())
{
IGeometry feature = null;
Assert.DoesNotThrow(() => feature = p.GetGeometryByID(3));
Assert.IsNotNull(feature);
Assert.AreEqual(feature.Centroid.Coordinate,
new Coordinate(429003.31, 360425.45));
}
}
[Test]
public void TestExecuteIntersectionQueryAgainstEnvelope()
{
using (var p = CreateProvider())
{
var fds = new FeatureDataSet();
Assert.DoesNotThrow(() => p.ExecuteIntersectionQuery(p.GetExtents(), fds));
Assert.AreEqual(1, fds.Tables.Count);
var table = fds.Tables[0];
Assert.AreEqual(4, table.Rows.Count);
}
}
[Test]
public void TestExecuteIntersectionQueryAgainstEnvelopeEqualsGetOidsInView()
{
using (var p = CreateProvider())
{
var ext =p.GetExtents();
var fds = new FeatureDataSet();
Assert.DoesNotThrow(() => p.ExecuteIntersectionQuery(ext, fds));
Assert.AreEqual(1, fds.Tables.Count);
var table = fds.Tables[0];
Assert.AreEqual(4, table.Rows.Count);
var oids = p.GetObjectIDsInView(ext);
Assert.AreEqual(table.Rows.Count, oids.Count);
foreach (FeatureDataRow row in table.Select())
Assert.IsTrue(oids.Contains(Convert.ToUInt32(row[0])));
}
}
[Test]
public void TestExecuteIntersectionQueryAgainstEnvelopeEqualsGetGeometriesInView()
{
using (var p = CreateProvider())
{
var ext = p.GetExtents();
var fds = new FeatureDataSet();
Assert.DoesNotThrow(() => p.ExecuteIntersectionQuery(ext, fds));
Assert.AreEqual(1, fds.Tables.Count);
var table = fds.Tables[0];
Assert.AreEqual(4, table.Rows.Count);
var geoms = p.GetGeometriesInView(ext);
Assert.AreEqual(table.Rows.Count, geoms.Count);
foreach (FeatureDataRow row in table.Select())
Assert.IsTrue(geoms.Contains(row.Geometry));
}
}
[Test]
public void TestExecuteIntersectionQueryAgainstGeometry()
{
using (var p = CreateProvider())
{
var reader = new NetTopologySuite.IO.WKTReader();
var poly = reader.Read(
@"POLYGON ((428999.76819468878 360451.93329044303, 428998.25517286535 360420.80827007542,
429023.1119599645 360406.75878171506, 429004.52340613387 360451.71714446822,
429004.52340613387 360451.71714446822, 428999.76819468878 360451.93329044303))");
var fds = new FeatureDataSet();
Assert.DoesNotThrow(() => p.ExecuteIntersectionQuery(poly, fds));
Assert.AreEqual(1, fds.Tables.Count);
var table = fds.Tables[0];
Assert.AreEqual(3, table.Rows.Count);
}
}
}
}