PageRenderTime 69ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/src/NHibernate.Spatial/src/Tests.NHibernate.Spatial/OgcSfSql11Compliance/ConformanceItemsFixture.cs

https://bitbucket.org/dabide/nhcontrib
C# | 2801 lines | 1533 code | 357 blank | 911 comment | 92 complexity | 832f0a4499690af1260e69e99000766c MD5 | raw file
Possible License(s): BSD-3-Clause, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0, Apache-2.0, LGPL-3.0, LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. using System;
  2. using System.Collections;
  3. using System.Linq;
  4. using GeoAPI.Geometries;
  5. using NHibernate;
  6. using NHibernate.Criterion;
  7. using NHibernate.Linq;
  8. using NHibernate.Spatial.Linq;
  9. using NHibernate.Spatial.Metadata;
  10. using NUnit.Framework;
  11. using Tests.NHibernate.Spatial.OgcSfSql11Compliance.Model;
  12. namespace Tests.NHibernate.Spatial.OgcSfSql11Compliance
  13. {
  14. /// <summary>
  15. /// Adaptation of OGC SFSQL 1.1 Compliance Test Suite.
  16. ///
  17. /// All conformance items should be specified as HQL queries
  18. /// (server-side processed) and NTS methods (client-side processed).
  19. /// For example, see <c>ConformanceItemT11</c> and <c>ConformanceItemT11Hql</c>.
  20. /// </summary>
  21. public abstract class ConformanceItemsFixture : AbstractFixture
  22. {
  23. protected override Type[] Mappings
  24. {
  25. get
  26. {
  27. return new Type[] {
  28. typeof(Bridge),
  29. typeof(Building),
  30. typeof(DividedRoute),
  31. typeof(Forest),
  32. typeof(Lake),
  33. typeof(MapNeatline),
  34. typeof(NamedPlace),
  35. typeof(Pond),
  36. typeof(RoadSegment),
  37. typeof(Stream),
  38. };
  39. }
  40. }
  41. private ISession session;
  42. protected override bool CheckDatabaseWasCleanedOnTearDown
  43. {
  44. get { return false; }
  45. }
  46. private const string SpatialReferenceSystemWKT =
  47. @"PROJCS[""UTM_ZONE_14N"", GEOGCS[""World Geodetic System 72"",
  48. DATUM[""WGS_72"", SPHEROID[""NWL_10D"", 6378135, 298.26]],
  49. PRIMEM[""Greenwich"", 0], UNIT[""Meter"", 1.0]],
  50. PROJECTION[""Transverse_Mercator""],
  51. PARAMETER[""False_Easting"", 500000.0],
  52. PARAMETER[""False_Northing"", 0.0],
  53. PARAMETER[""Central_Meridian"", -99.0],
  54. PARAMETER[""Scale_Factor"", 0.9996],
  55. PARAMETER[""Latitude_of_origin"", 0.0],
  56. UNIT[""Meter"", 1.0]]";
  57. protected override void OnBeforeCreateSchema()
  58. {
  59. using (ISession session = sessions.OpenSession())
  60. {
  61. if (Metadata.SupportsSpatialMetadata(session, MetadataClass.SpatialReferenceSystem))
  62. {
  63. session.Save(new SpatialReferenceSystem(101, "POSC", 32214, SpatialReferenceSystemWKT));
  64. session.Flush();
  65. }
  66. }
  67. }
  68. protected override void OnAfterDropSchema()
  69. {
  70. using (ISession session = sessions.OpenSession())
  71. {
  72. if (Metadata.SupportsSpatialMetadata(session, MetadataClass.SpatialReferenceSystem))
  73. {
  74. session.Delete("from SpatialReferenceSystem where SRID=101");
  75. session.Flush();
  76. }
  77. }
  78. }
  79. protected override void OnTestFixtureSetUp()
  80. {
  81. using (ISession session = sessions.OpenSession())
  82. {
  83. // Lake
  84. session.Save(new Lake(101, "Blue Lake",
  85. Wkt.Read("POLYGON((52 18,66 23,73 9,48 6,52 18),(59 18,67 18,67 13,59 13,59 18))")));
  86. // RoadSegment
  87. session.Save(new RoadSegment(102, "Route 5", null, 2,
  88. Wkt.Read("LINESTRING( 0 18, 10 21, 16 23, 28 26, 44 31 )")));
  89. session.Save(new RoadSegment(103, "Route 5", "Main Street", 4,
  90. Wkt.Read("LINESTRING( 44 31, 56 34, 70 38 )")));
  91. session.Save(new RoadSegment(104, "Route 5", null, 2,
  92. Wkt.Read("LINESTRING( 70 38, 72 48 )")));
  93. session.Save(new RoadSegment(105, "Main Street", null, 4,
  94. Wkt.Read("LINESTRING( 70 38, 84 42 )")));
  95. session.Save(new RoadSegment(106, "Dirt Road by Green Forest", null, 1,
  96. Wkt.Read("LINESTRING( 28 26, 28 0 )")));
  97. // DividedRoute
  98. session.Save(new DividedRoute(119, "Route 75", 4,
  99. Wkt.Read("MULTILINESTRING((10 48,10 21,10 0),(16 0,16 23,16 48))")));
  100. // Forest
  101. session.Save(new Forest(109, "Green Forest",
  102. Wkt.Read("MULTIPOLYGON(((28 26,28 0,84 0,84 42,28 26),(52 18,66 23,73 9,48 6,52 18)),((59 18,67 18,67 13,59 13,59 18)))")));
  103. // Bridge
  104. session.Save(new Bridge(110, "Cam Bridge",
  105. Wkt.Read("POINT( 44 31 )")));
  106. // Stream
  107. session.Save(new Stream(111, "Cam Stream",
  108. Wkt.Read("LINESTRING( 38 48, 44 41, 41 36, 44 31, 52 18 )")));
  109. session.Save(new Stream(112, null,
  110. Wkt.Read("LINESTRING( 76 0, 78 4, 73 9 )")));
  111. // Building
  112. session.Save(new Building(113, "123 Main Street",
  113. Wkt.Read("POINT( 52 30 )"),
  114. Wkt.Read("POLYGON( ( 50 31, 54 31, 54 29, 50 29, 50 31) )")));
  115. session.Save(new Building(114, "215 Main Street",
  116. Wkt.Read("POINT( 64 33 )"),
  117. Wkt.Read("POLYGON( ( 66 34, 62 34, 62 32, 66 32, 66 34) )")));
  118. // Pond
  119. session.Save(new Pond(120, null, "Stock Pond",
  120. Wkt.Read("MULTIPOLYGON( ( ( 24 44, 22 42, 24 40, 24 44) ), ( ( 26 44, 26 40, 28 42, 26 44) ) )")));
  121. // NamedPlace
  122. session.Save(new NamedPlace(117, "Ashton",
  123. Wkt.Read("POLYGON( ( 62 48, 84 48, 84 30, 56 30, 56 34, 62 48) )")));
  124. session.Save(new NamedPlace(118, "Goose Island",
  125. Wkt.Read("POLYGON( ( 67 13, 67 18, 59 18, 59 13, 67 13) )")));
  126. // MapNeatline
  127. session.Save(new MapNeatline(115,
  128. Wkt.Read("POLYGON( ( 0 0, 0 48, 84 48, 84 0, 0 0 ) )")));
  129. session.Flush();
  130. }
  131. }
  132. protected override void OnTestFixtureTearDown()
  133. {
  134. using (ISession session = sessions.OpenSession())
  135. {
  136. DeleteMappings(session);
  137. }
  138. }
  139. protected override void OnSetUp()
  140. {
  141. session = sessions.OpenSession();
  142. }
  143. protected override void OnTearDown()
  144. {
  145. session.Clear();
  146. session.Close();
  147. session.Dispose();
  148. }
  149. #region Queries testing functions in section 3.2.10.2 (T1 - T14)
  150. /// <summary>
  151. /// Conformance Item T1
  152. /// GEOMETRY_COLUMNS table/view is created/updated properly
  153. /// For this test we will check to see that all of the feature tables are
  154. /// represented by entries in the GEOMETRY_COLUMNS table/view
  155. ///
  156. /// ANSWER: lakes, road_segments, divided_routes, buildings, forests, bridges,
  157. /// named_places, streams, ponds, map_neatlines
  158. /// *** ADAPTATION ALERT ***
  159. /// Since there are no quotes around the table names in the CREATE TABLEs,
  160. /// they will be converted to upper case in many DBMSs, and therefore, the
  161. /// answer to this query may be:
  162. /// ANSWER: LAKES, ROAD_SEGMENTS, DIVIDED_ROUTES, BUILDINGS, FORESTS, BRIDGES,
  163. /// NAMED_PLACES, STREAMS, PONDS, MAP_NEATLINES
  164. /// *** ADAPTATION ALERT ***
  165. /// If the implementer made the adaptation concerning the buildings table
  166. /// in sqltsch.sql, then the answer here may differ slightly.
  167. ///
  168. /// Original SQL:
  169. /// <code>
  170. /// SELECT f_table_name
  171. /// FROM geometry_columns;
  172. /// </code>
  173. /// </summary>
  174. [Test]
  175. public void ConformanceItemT01Hql()
  176. {
  177. if (!Metadata.SupportsSpatialMetadata(session, MetadataClass.GeometryColumn))
  178. {
  179. Assert.Ignore("Provider does not support spatial metadata");
  180. }
  181. string[] tables = new string[] {
  182. "lakes",
  183. "road_segments",
  184. "divided_routes",
  185. "buildings",
  186. "forests",
  187. "bridges",
  188. "named_places",
  189. "streams",
  190. "ponds",
  191. "map_neatlines",
  192. };
  193. IList results = session.CreateQuery("select distinct g.TableName from GeometryColumn g").List();
  194. Assert.AreEqual(tables.Length, results.Count);
  195. foreach (string tableName in results)
  196. {
  197. bool found = (Array.IndexOf<string>(tables, tableName) != -1);
  198. Assert.IsTrue(found);
  199. }
  200. }
  201. /// <summary>
  202. /// Conformance Item T2
  203. /// GEOMETRY_COLUMNS table/view is created/updated properly
  204. /// For this test we will check to see that the correct geometry columns for the
  205. /// streams table is represented in the GEOMETRY_COLUMNS table/view
  206. ///
  207. /// ANSWER: centerline
  208. /// *** ADAPTATION ALERT ***
  209. /// Since there are no quotes around the table name, streams, in it's CREATE TABLE,
  210. /// it will be converted to upper case in many DBMSs, and therefore, the WHERE
  211. /// clause may have to be f_table_name = 'STREAMS'.
  212. ///
  213. /// Original SQL:
  214. /// <code>
  215. /// SELECT f_geometry_column
  216. /// FROM geometry_columns
  217. /// WHERE f_table_name = 'streams';
  218. /// </code>
  219. /// </summary>
  220. [Test]
  221. public void ConformanceItemT02Hql()
  222. {
  223. if (!Metadata.SupportsSpatialMetadata(session, MetadataClass.GeometryColumn))
  224. {
  225. Assert.Ignore("Provider does not support spatial metadata");
  226. }
  227. var query = session.CreateQuery(@"
  228. select g.Name
  229. from GeometryColumn g
  230. where g.TableName = 'streams'
  231. ");
  232. string result = query.UniqueResult<string>();
  233. Assert.AreEqual("centerline", result);
  234. }
  235. [Test]
  236. public void ConformanceItemT02Linq()
  237. {
  238. if (!Metadata.SupportsSpatialMetadata(session, MetadataClass.GeometryColumn))
  239. {
  240. Assert.Ignore("Provider does not support spatial metadata");
  241. }
  242. var query =
  243. from g in session.Query<GeometryColumn>()
  244. where g.TableName == "streams"
  245. select g.Name;
  246. string result = query.Single();
  247. Assert.AreEqual("centerline", result);
  248. }
  249. /// <summary>
  250. /// Conformance Item T3
  251. /// GEOMETRY_COLUMNS table/view is created/updated properly
  252. /// For this test we will check to see that the correct coordinate dimension
  253. /// for the streams table is represented in the GEOMETRY_COLUMNS table/view
  254. ///
  255. /// ANSWER: 2
  256. /// *** ADAPTATION ALERT ***
  257. /// Since there are no quotes around the table name, streams, in it's CREATE TABLE,
  258. /// it will be converted to upper case in many DBMSs, and therefore, the WHERE
  259. /// clause may have to be f_table_name = 'STREAMS'.
  260. ///
  261. /// Original SQL:
  262. /// <code>
  263. /// SELECT coord_dimension
  264. /// FROM geometry_columns
  265. /// WHERE f_table_name = 'streams';
  266. /// </code>
  267. /// </summary>
  268. [Test]
  269. public void ConformanceItemT03Hql()
  270. {
  271. if (!Metadata.SupportsSpatialMetadata(session, MetadataClass.GeometryColumn))
  272. {
  273. Assert.Ignore("Provider does not support spatial metadata");
  274. }
  275. var query = session.CreateQuery(@"
  276. select g.Dimension
  277. from GeometryColumn g
  278. where g.TableName = 'streams'
  279. ");
  280. int result = query.UniqueResult<int>();
  281. Assert.AreEqual(2, result);
  282. }
  283. [Test]
  284. public void ConformanceItemT03Linq()
  285. {
  286. if (!Metadata.SupportsSpatialMetadata(session, MetadataClass.GeometryColumn))
  287. {
  288. Assert.Ignore("Provider does not support spatial metadata");
  289. }
  290. var query =
  291. from g in session.Query<GeometryColumn >()
  292. where g.TableName == "streams"
  293. select g.Dimension;
  294. int result = query.Single();
  295. Assert.AreEqual(2, result);
  296. }
  297. /// <summary>
  298. /// Conformance Item T4
  299. /// GEOMETRY_COLUMNS table/view is created/updated properly
  300. /// For this test we will check to see that the correct value of srid for
  301. /// the streams table is represented in the GEOMETRY_COLUMNS table/view
  302. ///
  303. /// ANSWER: 101
  304. /// *** ADAPTATION ALERT ***
  305. /// Since there are no quotes around the table name, streams, in it's CREATE TABLE,
  306. /// it will be converted to upper case in many DBMSs, and therefore, the WHERE
  307. /// clause may have to be f_table_name = 'STREAMS'.
  308. ///
  309. /// Original SQL:
  310. /// <code>
  311. /// SELECT srid
  312. /// FROM geometry_columns
  313. /// WHERE f_table_name = 'streams';
  314. /// </code>
  315. /// </summary>
  316. [Test]
  317. public void ConformanceItemT04Hql()
  318. {
  319. if (!Metadata.SupportsSpatialMetadata(session, MetadataClass.GeometryColumn))
  320. {
  321. Assert.Ignore("Provider does not support spatial metadata");
  322. }
  323. var query = session.CreateQuery(@"
  324. select g.SRID
  325. from GeometryColumn g
  326. where g.TableName = 'streams'
  327. ");
  328. int result = query.UniqueResult<int>();
  329. Assert.AreEqual(101, result);
  330. }
  331. [Test]
  332. public void ConformanceItemT04Linq()
  333. {
  334. if (!Metadata.SupportsSpatialMetadata(session, MetadataClass.GeometryColumn))
  335. {
  336. Assert.Ignore("Provider does not support spatial metadata");
  337. }
  338. var query =
  339. from g in session.Query<GeometryColumn >()
  340. where g.TableName == "streams"
  341. select g.SRID;
  342. int result = query.Single();
  343. Assert.AreEqual(101, result);
  344. }
  345. /// <summary>
  346. /// Conformance Item T5
  347. /// SPATIAL_REF_SYS table/view is created/updated properly
  348. /// For this test we will check to see that the correct value of srtext is
  349. /// represented in the SPATIAL_REF_SYS table/view
  350. ///
  351. /// ANSWER: 'PROJCS["UTM_ZONE_14N", GEOGCS["World Geodetic System 72",
  352. /// DATUM["WGS_72", SPHEROID["NWL_10D", 6378135, 298.26]],
  353. /// PRIMEM["Greenwich", 0], UNIT["Meter", 1.0]],
  354. /// PROJECTION["Traverse_Mercator"], PARAMETER["False_Easting", 500000.0],
  355. /// PARAMETER["False_Northing", 0.0], PARAMETER["Central_Meridian", -99.0],
  356. /// PARAMETER["Scale_Factor", 0.9996], PARAMETER["Latitude_of_origin", 0.0],
  357. /// UNIT["Meter", 1.0]]'
  358. ///
  359. /// Original SQL:
  360. /// <code>
  361. /// SELECT srtext
  362. /// FROM SPATIAL_REF_SYS
  363. /// WHERE SRID = 101;
  364. /// </code>
  365. /// </summary>
  366. [Test]
  367. public void ConformanceItemT05Hql()
  368. {
  369. if (!Metadata.SupportsSpatialMetadata(session, MetadataClass.SpatialReferenceSystem))
  370. {
  371. Assert.Ignore("Provider does not support spatial metadata");
  372. }
  373. SpatialReferenceSystem srs = session.CreateQuery(
  374. "from SpatialReferenceSystem where SRID=101")
  375. .UniqueResult<SpatialReferenceSystem>();
  376. Assert.IsNotNull(srs);
  377. Assert.AreEqual(SpatialReferenceSystemWKT, srs.WellKnownText);
  378. // Alternative syntax for identifiers:
  379. srs = session.CreateQuery(
  380. "from SpatialReferenceSystem s where s=101")
  381. .UniqueResult<SpatialReferenceSystem>();
  382. Assert.IsNotNull(srs);
  383. Assert.AreEqual(SpatialReferenceSystemWKT, srs.WellKnownText);
  384. }
  385. [Test]
  386. public void ConformanceItemT05Linq()
  387. {
  388. if (!Metadata.SupportsSpatialMetadata(session, MetadataClass.SpatialReferenceSystem))
  389. {
  390. Assert.Ignore("Provider does not support spatial metadata");
  391. }
  392. var query =
  393. from s in session.Query<SpatialReferenceSystem>()
  394. where s.SRID == 101
  395. select s;
  396. var srs = query.Single();
  397. Assert.IsNotNull(srs);
  398. Assert.AreEqual(SpatialReferenceSystemWKT, srs.WellKnownText);
  399. }
  400. [Test]
  401. public void ConformanceItemT05Get()
  402. {
  403. if (!Metadata.SupportsSpatialMetadata(session, MetadataClass.SpatialReferenceSystem))
  404. {
  405. Assert.Ignore("Provider does not support spatial metadata");
  406. }
  407. SpatialReferenceSystem srs = session.Get<SpatialReferenceSystem>(101);
  408. Assert.IsNotNull(srs);
  409. Assert.AreEqual(SpatialReferenceSystemWKT, srs.WellKnownText);
  410. }
  411. [Test]
  412. public void ConformanceItemT05Criteria()
  413. {
  414. if (!Metadata.SupportsSpatialMetadata(session, MetadataClass.SpatialReferenceSystem))
  415. {
  416. Assert.Ignore("Provider does not support spatial metadata");
  417. }
  418. SpatialReferenceSystem srs = session.CreateCriteria(typeof(SpatialReferenceSystem))
  419. .Add(Restrictions.IdEq(101))
  420. .UniqueResult<SpatialReferenceSystem>();
  421. Assert.IsNotNull(srs);
  422. Assert.AreEqual(SpatialReferenceSystemWKT, srs.WellKnownText);
  423. }
  424. /// <summary>
  425. /// Conformance Item T6
  426. /// Dimension(g Geometry) : Integer
  427. /// For this test we will determine the dimension of Blue Lake.
  428. ///
  429. /// ANSWER: 2
  430. ///
  431. /// Original SQL:
  432. /// <code>
  433. /// SELECT Dimension(shore)
  434. /// FROM lakes
  435. /// WHERE name = 'Blue Lake';
  436. /// </code>
  437. /// </summary>
  438. [Test]
  439. public void ConformanceItemT06()
  440. {
  441. Lake lake = session.CreateCriteria(typeof(Lake))
  442. .Add(Restrictions.Eq("Name", "Blue Lake"))
  443. .UniqueResult<Lake>();
  444. Assert.AreEqual(2, (int)lake.Shore.Dimension);
  445. }
  446. [Test]
  447. public void ConformanceItemT06Hql()
  448. {
  449. string query =
  450. @"select NHSP.Dimension(t.Shore)
  451. from Lake t
  452. where t.Name = 'Blue Lake'
  453. ";
  454. int result = session.CreateQuery(query)
  455. .UniqueResult<int>();
  456. Assert.AreEqual(2, result);
  457. }
  458. [Test]
  459. public void ConformanceItemT06Linq()
  460. {
  461. var query =
  462. from t in session.Query<Lake>()
  463. where t.Name == "Blue Lake"
  464. select t.Shore.GetDimension();
  465. int result = query.Single();
  466. Assert.AreEqual(2, result);
  467. }
  468. /// <summary>
  469. /// Conformance Item T7
  470. /// GeometryType(g Geometry) : String
  471. /// For this test we will determine the type of Route 75.
  472. ///
  473. /// ANSWER: 9 (which corresponds to 'MULTILINESTRING')
  474. ///
  475. /// Original SQL:
  476. /// <code>
  477. /// SELECT GeometryType(centerlines)
  478. /// FROM lakes
  479. /// WHERE name = 'Route 75';
  480. /// </code>
  481. /// </summary>
  482. /// <remarks>
  483. /// Correction:
  484. /// * Table name should be DIVIDED_ROUTES instead of LAKES
  485. /// </remarks>
  486. [Test]
  487. public void ConformanceItemT07()
  488. {
  489. DividedRoute route = session.CreateCriteria(typeof(DividedRoute))
  490. .Add(Restrictions.Eq("Name", "Route 75"))
  491. .UniqueResult<DividedRoute>();
  492. Assert.AreEqual("MULTILINESTRING", route.Centerlines.GeometryType.ToUpper());
  493. }
  494. [Test]
  495. public void ConformanceItemT07Hql()
  496. {
  497. string query =
  498. @"select NHSP.GeometryType(t.Centerlines)
  499. from DividedRoute t
  500. where t.Name = 'Route 75'
  501. ";
  502. string result = session.CreateQuery(query)
  503. .UniqueResult<string>();
  504. Assert.AreEqual("MULTILINESTRING", result.ToUpper());
  505. }
  506. [Test]
  507. public void ConformanceItemT07Linq()
  508. {
  509. var query =
  510. from t in session.Query<DividedRoute>()
  511. where t.Name == "Route 75"
  512. select t.Centerlines.GeometryType;
  513. string result = query.Single();
  514. Assert.AreEqual("MULTILINESTRING", result.ToUpper());
  515. }
  516. /// <summary>
  517. /// Conformance Item T8
  518. /// AsText(g Geometry) : String
  519. /// For this test we will determine the WKT representation of Goose Island.
  520. ///
  521. /// ANSWER: 'POLYGON( ( 67 13, 67 18, 59 18, 59 13, 67 13) )'
  522. ///
  523. /// Original SQL:
  524. /// <code>
  525. /// SELECT AsText(boundary)
  526. /// FROM named_places
  527. /// WHERE name = 'Goose Island';
  528. /// </code>
  529. /// </summary>
  530. [Test]
  531. public void ConformanceItemT08()
  532. {
  533. NamedPlace place = session.CreateCriteria(typeof(NamedPlace))
  534. .Add(Restrictions.Eq("Name", "Goose Island"))
  535. .UniqueResult<NamedPlace>();
  536. IGeometry expected = Wkt.Read("POLYGON( ( 67 13, 67 18, 59 18, 59 13, 67 13) )");
  537. Assert.IsTrue(expected.Equals(place.Boundary));
  538. }
  539. [Test]
  540. public void ConformanceItemT08Hql()
  541. {
  542. string query =
  543. @"select t.Boundary
  544. from NamedPlace t
  545. where t.Name = 'Goose Island'
  546. ";
  547. IGeometry result = session.CreateQuery(query)
  548. .UniqueResult<IGeometry>();
  549. IGeometry expected = Wkt.Read("POLYGON( ( 67 13, 67 18, 59 18, 59 13, 67 13) )");
  550. Assert.IsTrue(expected.Equals(result));
  551. }
  552. [Test]
  553. public void ConformanceItemT08Linq()
  554. {
  555. var query =
  556. from t in session.Query<NamedPlace>()
  557. where t.Name == "Goose Island"
  558. select t.Boundary;
  559. IGeometry result = query.Single();
  560. IGeometry expected = Wkt.Read("POLYGON( ( 67 13, 67 18, 59 18, 59 13, 67 13) )");
  561. Assert.IsTrue(expected.Equals(result));
  562. }
  563. /// <summary>
  564. /// Conformance Item T9
  565. /// AsBinary(g Geometry) : Blob
  566. /// For this test we will determine the WKB representation of Goose Island.
  567. /// We will test by applying AsText to the result of PolygonFromText to the
  568. /// result of AsBinary.
  569. ///
  570. /// ANSWER: 'POLYGON( ( 67 13, 67 18, 59 18, 59 13, 67 13) )'
  571. ///
  572. /// Original SQL:
  573. /// <code>
  574. /// SELECT AsText(PolygonFromWKB(AsBinary(boundary)))
  575. /// FROM named_places
  576. /// WHERE name = 'Goose Island';
  577. /// </code>
  578. /// </summary>
  579. [Test]
  580. public void ConformanceItemT09Hql()
  581. {
  582. string query =
  583. @"select NHSP.AsText(NHSP.PolyFromWKB(NHSP.AsBinary(t.Boundary), 0))
  584. from NamedPlace t
  585. where t.Name = 'Goose Island'
  586. ";
  587. string result = session.CreateQuery(query)
  588. .UniqueResult<string>();
  589. IGeometry geometry = Wkt.Read(result);
  590. IGeometry expected = Wkt.Read("POLYGON( ( 67 13, 67 18, 59 18, 59 13, 67 13) )");
  591. Assert.IsTrue(expected.Equals(geometry));
  592. }
  593. [Test]
  594. [Ignore("TODO: ToPolygon")]
  595. public void ConformanceItemT09Linq()
  596. {
  597. var query =
  598. from t in session.Query<NamedPlace>()
  599. where t.Name == "Goose Island"
  600. select t.Boundary.AsBinary().ToPolygon(0);
  601. IGeometry geometry = query.Single();
  602. IGeometry expected = Wkt.Read("POLYGON( ( 67 13, 67 18, 59 18, 59 13, 67 13) )");
  603. Assert.IsTrue(expected.Equals(geometry));
  604. }
  605. /// <summary>
  606. /// Conformance Item T10
  607. /// SRID(g Geometry) : Integer
  608. /// For this test we will determine the SRID of Goose Island.
  609. ///
  610. /// ANSWER: 101
  611. ///
  612. /// Original SQL:
  613. /// <code>
  614. /// SELECT SRID(boundary)
  615. /// FROM named_places
  616. /// WHERE name = 'Goose Island';
  617. /// </code>
  618. /// </summary>
  619. [Test]
  620. public void ConformanceItemT10Hql()
  621. {
  622. string query =
  623. @"select NHSP.SRID(t.Boundary)
  624. from NamedPlace t
  625. where t.Name = 'Goose Island'
  626. ";
  627. int result = session.CreateQuery(query)
  628. .UniqueResult<int>();
  629. Assert.AreEqual(101, result);
  630. }
  631. [Test]
  632. public void ConformanceItemT10Linq()
  633. {
  634. var query =
  635. from t in session.Query<NamedPlace>()
  636. where t.Name == "Goose Island"
  637. select t.Boundary.SRID;
  638. int result = query.Single();
  639. Assert.AreEqual(101, result);
  640. }
  641. /// <summary>
  642. /// Conformance Item T11
  643. /// IsEmpty(g Geometry) : Integer
  644. /// For this test we will determine whether the geometry of a
  645. /// segment of Route 5 is empty.
  646. ///
  647. /// ANSWER: 0
  648. /// *** Adaptation Alert ***
  649. /// If the implementer provides IsEmpty as a boolean function, instead of as
  650. /// an INTEGER function, then:
  651. /// ANSWER: FALSE or 'f'
  652. ///
  653. /// Original SQL:
  654. /// <code>
  655. /// SELECT IsEmpty(centerline)
  656. /// FROM road_segments
  657. /// WHERE name = 'Route 5' AND aliases = 'Main Street';
  658. /// </code>
  659. /// </summary>
  660. [Test]
  661. public void ConformanceItemT11()
  662. {
  663. RoadSegment entity = session.CreateCriteria(typeof(RoadSegment))
  664. .Add(Restrictions.Eq("Name", "Route 5"))
  665. .Add(Restrictions.Eq("Aliases", "Main Street"))
  666. .UniqueResult<RoadSegment>();
  667. Assert.IsFalse(entity.Centerline.IsEmpty);
  668. }
  669. [Test]
  670. public void ConformanceItemT11Hql()
  671. {
  672. string query =
  673. @"select NHSP.IsEmpty(t.Centerline)
  674. from RoadSegment t
  675. where t.Name = 'Route 5' and t.Aliases = 'Main Street'
  676. ";
  677. bool result = session.CreateQuery(query)
  678. .UniqueResult<bool>();
  679. Assert.IsFalse(result);
  680. }
  681. [Test]
  682. public void ConformanceItemT11Linq()
  683. {
  684. var query =
  685. from t in session.Query<RoadSegment>()
  686. where t.Name == "Route 5" && t.Aliases == "Main Street"
  687. select t.Centerline.IsEmpty;
  688. bool result = query.Single();
  689. Assert.IsFalse(result);
  690. }
  691. /// <summary>
  692. /// Conformance Item T12
  693. /// IsSimple(g Geometry) : Integer
  694. /// For this test we will determine whether the geometry of a
  695. /// segment of Blue Lake is simple.
  696. ///
  697. /// ANSWER: 1
  698. /// *** Adaptation Alert ***
  699. /// If the implementer provides IsSimple as a boolean function, instead of as
  700. /// an INTEGER function, then:
  701. /// ANSWER: TRUE or 't'
  702. ///
  703. /// Original SQL:
  704. /// <code>
  705. /// SELECT IsSimple(shore)
  706. /// FROM lakes
  707. /// WHERE name = 'Blue Lake';
  708. /// </code>
  709. /// </summary>
  710. [Test]
  711. public void ConformanceItemT12()
  712. {
  713. Lake entity = session.CreateCriteria(typeof(Lake))
  714. .Add(Restrictions.Eq("Name", "Blue Lake"))
  715. .UniqueResult<Lake>();
  716. Assert.IsTrue(entity.Shore.IsSimple);
  717. }
  718. [Test]
  719. public void ConformanceItemT12Hql()
  720. {
  721. string query =
  722. @"select NHSP.IsSimple(t.Shore)
  723. from Lake t
  724. where t.Name = 'Blue Lake'
  725. ";
  726. bool result = session.CreateQuery(query)
  727. .UniqueResult<bool>();
  728. Assert.IsTrue(result);
  729. }
  730. [Test]
  731. public void ConformanceItemT12Linq()
  732. {
  733. var query =
  734. from t in session.Query<Lake>()
  735. where t.Name == "Blue Lake"
  736. select t.Shore.IsSimple;
  737. bool result = query.Single();
  738. Assert.IsTrue(result);
  739. }
  740. /// <summary>
  741. /// Conformance Item T13
  742. /// Boundary(g Geometry) : Geometry
  743. /// For this test we will determine the boundary of Goose Island.
  744. /// NOTE: The boundary result is as defined in 3.12.3.2 of 96-015R1.
  745. ///
  746. /// ANSWER: 'LINESTRING( 67 13, 67 18, 59 18, 59 13, 67 13 )'
  747. ///
  748. /// Original SQL:
  749. /// <code>
  750. /// SELECT AsText(Boundary((boundary))
  751. /// FROM named_places
  752. /// WHERE name = 'Goose Island';
  753. /// </code>
  754. /// </summary>
  755. [Test]
  756. public void ConformanceItemT13()
  757. {
  758. NamedPlace entity = session.CreateCriteria(typeof(NamedPlace))
  759. .Add(Restrictions.Eq("Name", "Goose Island"))
  760. .UniqueResult<NamedPlace>();
  761. IGeometry expected = Wkt.Read("LINESTRING( 67 13, 67 18, 59 18, 59 13, 67 13 )");
  762. Assert.IsTrue(expected.Equals(entity.Boundary.Boundary));
  763. }
  764. [Test]
  765. public void ConformanceItemT13Hql()
  766. {
  767. string query =
  768. @"select NHSP.AsText(NHSP.Boundary(t.Boundary))
  769. from NamedPlace t
  770. where t.Name = 'Goose Island'
  771. ";
  772. string result = session.CreateQuery(query)
  773. .UniqueResult<string>();
  774. IGeometry geometry = Wkt.Read(result);
  775. IGeometry expected = Wkt.Read("LINESTRING( 67 13, 67 18, 59 18, 59 13, 67 13 )");
  776. Assert.IsTrue(expected.Equals(geometry));
  777. }
  778. [Test]
  779. public void ConformanceItemT13Linq()
  780. {
  781. var query =
  782. from t in session.Query<NamedPlace>()
  783. where t.Name == "Goose Island"
  784. select t.Boundary.Boundary;
  785. IGeometry geometry = query.Single();
  786. IGeometry expected = Wkt.Read("LINESTRING( 67 13, 67 18, 59 18, 59 13, 67 13 )");
  787. Assert.IsTrue(expected.Equals(geometry));
  788. }
  789. /// <summary>
  790. /// Conformance Item T14
  791. /// Envelope(g Geometry) : Geometry
  792. /// For this test we will determine the envelope of Goose Island.
  793. ///
  794. /// ANSWER: 'POLYGON( ( 59 13, 59 18, 67 18, 67 13, 59 13) )'
  795. ///
  796. /// Original SQL:
  797. /// <code>
  798. /// SELECT AsText(Envelope((boundary))
  799. /// FROM named_places
  800. /// WHERE name = 'Goose Island';
  801. /// </code>
  802. /// </summary>
  803. [Test]
  804. public void ConformanceItemT14Hql()
  805. {
  806. string query =
  807. @"select NHSP.AsText(NHSP.Envelope(t.Boundary))
  808. from NamedPlace t
  809. where t.Name = 'Goose Island'
  810. ";
  811. string result = session.CreateQuery(query)
  812. .UniqueResult<string>();
  813. IGeometry geometry = Wkt.Read(result);
  814. IGeometry expected = Wkt.Read("POLYGON( ( 59 13, 59 18, 67 18, 67 13, 59 13) )");
  815. Assert.IsTrue(expected.Equals(geometry));
  816. }
  817. [Test]
  818. public void ConformanceItemT14Linq()
  819. {
  820. var query =
  821. from t in session.Query<NamedPlace>()
  822. where t.Name == "Goose Island"
  823. select t.Boundary.Envelope;
  824. IGeometry geometry = query.Single();
  825. IGeometry expected = Wkt.Read("POLYGON( ( 59 13, 59 18, 67 18, 67 13, 59 13) )");
  826. Assert.IsTrue(expected.Equals(geometry));
  827. }
  828. #endregion
  829. #region Queries testing functions in section 3.2.11.2 (T15 - T16)
  830. /// <summary>
  831. /// Conformance Item T15
  832. /// X(p Point) : Double Precision
  833. /// For this test we will determine the X coordinate of Cam Bridge.
  834. ///
  835. /// ANSWER: 44.00
  836. ///
  837. /// Original SQL:
  838. /// <code>
  839. /// SELECT X(position)
  840. /// FROM bridges
  841. /// WHERE name = 'Bridges';
  842. /// </code>
  843. /// </summary>
  844. /// <remarks>
  845. /// Correction:
  846. /// * Bridge name should be 'Cam Bridge'
  847. /// </remarks>
  848. [Test]
  849. public void ConformanceItemT15Hql()
  850. {
  851. string query =
  852. @"select NHSP.X(t.Position)
  853. from Bridge t
  854. where t.Name = 'Cam Bridge'
  855. ";
  856. double result = session.CreateQuery(query)
  857. .UniqueResult<double>();
  858. Assert.AreEqual(44, result);
  859. }
  860. [Test]
  861. public void ConformanceItemT15Linq()
  862. {
  863. var query =
  864. from t in session.Query<Bridge>()
  865. where t.Name == "Cam Bridge"
  866. select ((IPoint)t.Position).X;
  867. double result = query.Single();
  868. Assert.AreEqual(44, result);
  869. }
  870. /// <summary>
  871. /// Conformance Item T16
  872. /// Y(p Point) : Double Precision
  873. /// For this test we will determine the Y coordinate of Cam Bridge.
  874. ///
  875. /// ANSWER: 31.00
  876. ///
  877. /// Original SQL:
  878. /// <code>
  879. /// SELECT Y(position)
  880. /// FROM bridges
  881. /// WHERE name = 'Bridges';
  882. /// </code>
  883. /// </summary>
  884. /// <remarks>
  885. /// Correction:
  886. /// * Bridge name should be 'Cam Bridge'
  887. /// </remarks>
  888. [Test]
  889. public void ConformanceItemT16Hql()
  890. {
  891. string query =
  892. @"select NHSP.Y(t.Position)
  893. from Bridge t
  894. where t.Name = 'Cam Bridge'
  895. ";
  896. double result = session.CreateQuery(query)
  897. .UniqueResult<double>();
  898. Assert.AreEqual(31, result);
  899. }
  900. [Test]
  901. public void ConformanceItemT16Linq()
  902. {
  903. var query =
  904. from t in session.Query<Bridge >()
  905. where t.Name == "Cam Bridge"
  906. select ((IPoint)t.Position).Y;
  907. double result = query.Single();
  908. Assert.AreEqual(31, result);
  909. }
  910. #endregion
  911. #region Queries testing functions in section 3.2.12.2 (T17 - T21)
  912. /// <summary>
  913. /// Conformance Item T17
  914. /// StartPoint(c Curve) : Point
  915. /// For this test we will determine the start point of road segment 102.
  916. ///
  917. /// ANSWER: 'POINT( 0 18 )'
  918. ///
  919. /// Original SQL:
  920. /// <code>
  921. /// SELECT AsText(StartPoint(centerline))
  922. /// FROM road_segments
  923. /// WHERE fid = 102;
  924. /// </code>
  925. /// </summary>
  926. [Test]
  927. public void ConformanceItemT17Hql()
  928. {
  929. string query =
  930. @"select NHSP.AsText(NHSP.StartPoint(t.Centerline))
  931. from RoadSegment t
  932. where t.Fid = 102
  933. ";
  934. string result = session.CreateQuery(query)
  935. .UniqueResult<string>();
  936. IGeometry geometry = Wkt.Read(result);
  937. IGeometry expected = Wkt.Read("POINT( 0 18 )");
  938. Assert.IsTrue(expected.Equals(geometry));
  939. }
  940. [Test]
  941. public void ConformanceItemT17Linq()
  942. {
  943. var query =
  944. from t in session.Query<RoadSegment>()
  945. where t.Fid == 102
  946. select ((ICurve)t.Centerline).StartPoint;
  947. IGeometry geometry = query.Single();
  948. IGeometry expected = Wkt.Read("POINT( 0 18 )");
  949. Assert.IsTrue(expected.Equals(geometry));
  950. }
  951. /// <summary>
  952. /// Conformance Item T18
  953. /// EndPoint(c Curve) : Point
  954. /// For this test we will determine the end point of road segment 102.
  955. ///
  956. /// ANSWER: 'POINT( 44 31 )'
  957. ///
  958. /// Original SQL:
  959. /// <code>
  960. /// SELECT AsText(EndPoint(centerline))
  961. /// FROM road_segments
  962. /// WHERE fid = 102;
  963. /// </code>
  964. /// </summary>
  965. [Test]
  966. public void ConformanceItemT18Hql()
  967. {
  968. string query =
  969. @"select NHSP.AsText(NHSP.EndPoint(t.Centerline))
  970. from RoadSegment t
  971. where t.Fid = 102
  972. ";
  973. string result = session.CreateQuery(query)
  974. .UniqueResult<string>();
  975. IGeometry geometry = Wkt.Read(result);
  976. IGeometry expected = Wkt.Read("POINT( 44 31 )");
  977. Assert.IsTrue(expected.Equals(geometry));
  978. }
  979. [Test]
  980. public void ConformanceItemT18Linq()
  981. {
  982. var query =
  983. from t in session.Query<RoadSegment>()
  984. where t.Fid == 102
  985. select ((ICurve)t.Centerline).EndPoint;
  986. IGeometry geometry = query.Single();
  987. IGeometry expected = Wkt.Read("POINT( 44 31 )");
  988. Assert.IsTrue(expected.Equals(geometry));
  989. }
  990. /// <summary>
  991. /// Conformance Item T19
  992. /// IsClosed(c Curve) : Integer
  993. /// For this test we will determine the boundary of Goose Island.
  994. ///
  995. /// ANSWER: 1
  996. /// *** Adaptation Alert ***
  997. /// If the implementer provides IsClosed as a boolean function, instead of as
  998. /// an INTEGER function, then:
  999. /// ANSWER: TRUE or 't'
  1000. ///
  1001. /// Original SQL:
  1002. /// <code>
  1003. /// SELECT IsClosed(Boundary(boundary))
  1004. /// FROM named_places
  1005. /// WHERE name = 'Goose Island';
  1006. /// </code>
  1007. /// </summary>
  1008. [Test]
  1009. public void ConformanceItemT19Hql()
  1010. {
  1011. string query =
  1012. @"select NHSP.IsClosed(NHSP.Boundary(t.Boundary))
  1013. from NamedPlace t
  1014. where t.Name = 'Goose Island'
  1015. ";
  1016. bool result = session.CreateQuery(query)
  1017. .UniqueResult<bool>();
  1018. Assert.IsTrue(result);
  1019. }
  1020. [Test]
  1021. public void ConformanceItemT19Linq()
  1022. {
  1023. var query =
  1024. from t in session.Query<NamedPlace>()
  1025. where t.Name == "Goose Island"
  1026. select ((ICurve)t.Boundary.Boundary).IsClosed;
  1027. bool result = query.Single();
  1028. Assert.IsTrue(result);
  1029. }
  1030. /// <summary>
  1031. /// Conformance Item T20
  1032. /// IsRing(c Curve) : Integer
  1033. /// For this test we will determine the boundary of Goose Island.
  1034. ///
  1035. /// ANSWER: 1
  1036. /// *** Adaptation Alert ***
  1037. /// If the implementer provides IsRing as a boolean function, instead of as
  1038. /// an INTEGER function, then:
  1039. /// ANSWER: TRUE or 't'
  1040. ///
  1041. /// Original SQL:
  1042. /// <code>
  1043. /// SELECT IsRing(Boundary(boundary))
  1044. /// FROM named_places
  1045. /// WHERE name = 'Goose Island';
  1046. /// </code>
  1047. /// </summary>
  1048. [Test]
  1049. public void ConformanceItemT20Hql()
  1050. {
  1051. string query =
  1052. @"select NHSP.IsRing(NHSP.Boundary(t.Boundary))
  1053. from NamedPlace t
  1054. where t.Name = 'Goose Island'
  1055. ";
  1056. bool result = session.CreateQuery(query)
  1057. .UniqueResult<bool>();
  1058. Assert.IsTrue(result);
  1059. }
  1060. [Test]
  1061. public void ConformanceItemT20Linq()
  1062. {
  1063. var query =
  1064. from t in session.Query<NamedPlace>()
  1065. where t.Name == "Goose Island"
  1066. select ((ICurve)t.Boundary.Boundary).IsRing;
  1067. bool result = query.Single();
  1068. Assert.IsTrue(result);
  1069. }
  1070. /// <summary>
  1071. /// Conformance Item T21
  1072. /// Length(c Curve) : Double Precision
  1073. /// For this test we will determine the length of road segment 106.
  1074. ///
  1075. /// ANSWER: 26.00 (meters)
  1076. ///
  1077. /// Original SQL:
  1078. /// <code>
  1079. /// SELECT Length(centerline)
  1080. /// FROM road_segments
  1081. /// WHERE fid = 106;
  1082. /// </code>
  1083. /// </summary>
  1084. [Test]
  1085. public void ConformanceItemT21Hql()
  1086. {
  1087. string query =
  1088. @"select NHSP.Length(t.Centerline)
  1089. from RoadSegment t
  1090. where t.Fid = 106
  1091. ";
  1092. double result = session.CreateQuery(query)
  1093. .UniqueResult<double>();
  1094. Assert.AreEqual(26, result);
  1095. }
  1096. [Test]
  1097. public void ConformanceItemT21Linq()
  1098. {
  1099. var query =
  1100. from t in session.Query<RoadSegment>()
  1101. where t.Fid == 106
  1102. select t.Centerline.Length;
  1103. double result = query.Single();
  1104. Assert.AreEqual(26, result);
  1105. }
  1106. #endregion
  1107. #region Queries testing functions in section 3.2.13.2 (T22 - T23)
  1108. /// <summary>
  1109. /// Conformance Item T22
  1110. /// NumPoints(l LineString) : Integer
  1111. /// For this test we will determine the number of points in road segment 102.
  1112. ///
  1113. /// ANSWER: 5
  1114. ///
  1115. /// Original SQL:
  1116. /// <code>
  1117. /// SELECT NumPoints(centerline)
  1118. /// FROM road_segments
  1119. /// WHERE fid = 102;
  1120. /// </code>
  1121. /// </summary>
  1122. [Test]
  1123. public void ConformanceItemT22Hql()
  1124. {
  1125. string query =
  1126. @"select NHSP.NumPoints(t.Centerline)
  1127. from RoadSegment t
  1128. where t.Fid = 102
  1129. ";
  1130. int result = session.CreateQuery(query)
  1131. .UniqueResult<int>();
  1132. Assert.AreEqual(5, result);
  1133. }
  1134. [Test]
  1135. public void ConformanceItemT22Linq()
  1136. {
  1137. var query =
  1138. from t in session.Query<RoadSegment>()
  1139. where t.Fid == 102
  1140. select t.Centerline.NumPoints;
  1141. int result = query.Single();
  1142. Assert.AreEqual(5, result);
  1143. }
  1144. /// <summary>
  1145. /// Conformance Item T23
  1146. /// PointN(l LineString, n Integer) : Point
  1147. /// For this test we will determine the 1st point in road segment 102.
  1148. ///
  1149. /// ANSWER: 'POINT( 0 18 )'
  1150. ///
  1151. /// Original SQL:
  1152. /// <code>
  1153. /// SELECT AsText(PointN(centerline, 1))
  1154. /// FROM road_segments
  1155. /// WHERE fid = 102;
  1156. /// </code>
  1157. /// </summary>
  1158. [Test]
  1159. public void ConformanceItemT23Hql()
  1160. {
  1161. string query =
  1162. @"select NHSP.AsText(NHSP.PointN(t.Centerline, 1))
  1163. from RoadSegment t
  1164. where t.Fid = 102
  1165. ";
  1166. string result = session.CreateQuery(query)
  1167. .UniqueResult<string>();
  1168. IGeometry geometry = Wkt.Read(result);
  1169. IGeometry expected = Wkt.Read("POINT( 0 18 )");
  1170. Assert.IsTrue(expected.Equals(geometry));
  1171. }
  1172. [Test]
  1173. public void ConformanceItemT23Linq()
  1174. {
  1175. var query =
  1176. from t in session.Query<RoadSegment>()
  1177. where t.Fid == 102
  1178. select ((ILineString)t.Centerline).GetPointN(0);
  1179. IGeometry geometry = query.Single();
  1180. IGeometry expected = Wkt.Read("POINT( 0 18 )");
  1181. Assert.IsTrue(expected.Equals(geometry));
  1182. }
  1183. #endregion
  1184. #region Queries testing functions in section 3.2.14. (T24 - T26)
  1185. /// <summary>
  1186. /// Conformance Item T24
  1187. /// Centroid(s Surface) : Point
  1188. /// For this test we will determine the centroid of Goose Island.
  1189. ///
  1190. /// ANSWER: 'POINT( 63 15.5 )'
  1191. ///
  1192. /// Original SQL:
  1193. /// <code>
  1194. /// SELECT AsText(Centroid(boundary))
  1195. /// FROM named_places
  1196. /// WHERE name = 'Goose Island';
  1197. /// </code>
  1198. /// </summary>
  1199. [Test]
  1200. public void ConformanceItemT24Hql()
  1201. {
  1202. string query =
  1203. @"select NHSP.AsText(NHSP.Centroid(t.Boundary))
  1204. from NamedPlace t
  1205. where t.Name = 'Goose Island'
  1206. ";
  1207. string result = session.CreateQuery(query)
  1208. .UniqueResult<string>();
  1209. IGeometry geometry = Wkt.Read(result);
  1210. IGeometry expected = Wkt.Read("POINT( 63 15.5 )");
  1211. Assert.IsTrue(expected.Equals(geometry));
  1212. }
  1213. [Test]
  1214. public void ConformanceItemT24Linq()
  1215. {
  1216. var query =
  1217. from t in session.Query<NamedPlace>()
  1218. where t.Name == "Goose Island"
  1219. select t.Boundary.Centroid;
  1220. IGeometry geometry = query.Single();
  1221. IGeometry expected = Wkt.Read("POINT( 63 15.5 )");
  1222. Assert.IsTrue(expected.Equals(geometry));
  1223. }
  1224. /// <summary>
  1225. /// Conformance Item T25
  1226. /// PointOnSurface(s Surface) : Point
  1227. /// For this test we will determine a point on Goose Island.
  1228. /// NOTE: For this test we will have to uses the Contains function
  1229. /// (which we don't test until later).
  1230. ///
  1231. /// ANSWER: 1
  1232. /// *** Adaptation Alert ***
  1233. /// If the implementer provides Contains as a boolean function, instead of as
  1234. /// an INTEGER function, then:
  1235. /// ANSWER: TRUE or 't'
  1236. ///
  1237. /// Original SQL:
  1238. /// <code>
  1239. /// SELECT Contains(boundary, PointOnSurface(boundary))
  1240. /// FROM named_places
  1241. /// WHERE name = 'Goose Island';
  1242. /// </code>
  1243. /// </summary>
  1244. [Test]
  1245. public void ConformanceItemT25()
  1246. {
  1247. NamedPlace entity = session.CreateCriteria(typeof(NamedPlace))
  1248. .Add(Restrictions.Eq("Name", "Goose Island"))
  1249. .UniqueResult<NamedPlace>();
  1250. Assert.IsTrue(entity.Boundary.Contains(entity.Boundary.PointOnSurface));
  1251. }
  1252. [Test]
  1253. public void ConformanceItemT25Hql()
  1254. {
  1255. string query =
  1256. @"select NHSP.Contains(t.Boundary, NHSP.PointOnSurface(t.Boundary))
  1257. from NamedPlace t
  1258. where t.Name = 'Goose Island'
  1259. ";
  1260. bool result = session.CreateQuery(query)
  1261. .UniqueResult<bool>();
  1262. Assert.IsTrue(result);
  1263. }
  1264. [Test]
  1265. public void ConformanceItemT25Linq()
  1266. {
  1267. var query =
  1268. from t in session.Query<NamedPlace>()
  1269. where t.Name == "Goose Island"
  1270. select t.Boundary.Contains(t.Boundary.PointOnSurface);
  1271. bool result = query.Single();
  1272. Assert.IsTrue(result);
  1273. }
  1274. /// <summary>
  1275. /// Conformance Item T26
  1276. /// Area(s Surface) : Double Precision
  1277. /// For this test we will determine the area of Goose Island.
  1278. ///
  1279. /// ANSWER: 40.00 (square meters)
  1280. ///
  1281. /// Original SQL:
  1282. /// <code>
  1283. /// SELECT Area(boundary)
  1284. /// FROM named_places
  1285. /// WHERE name = 'Goose Island';
  1286. /// </code>
  1287. /// </summary>
  1288. [Test]
  1289. public void ConformanceItemT26Hql()
  1290. {
  1291. string query =
  1292. @"select NHSP.Area(t.Boundary)
  1293. from NamedPlace t
  1294. where t.Name = 'Goose Island'
  1295. ";
  1296. double result = session.CreateQuery(query)
  1297. .UniqueResult<double>();
  1298. Assert.AreEqual(40, result);
  1299. }
  1300. [Test]
  1301. public void ConformanceItemT26Linq()
  1302. {
  1303. var query =
  1304. from t in session.Query<NamedPlace>()
  1305. where t.Name == "Goose Island"
  1306. select t.Boundary.Area;
  1307. double result = query.Single();
  1308. Assert.AreEqual(40, result);
  1309. }
  1310. #endregion
  1311. #region Queries testing functions in section 3.2.15.2 (T27 - T29)
  1312. /// <summary>
  1313. /// Conformance Item T27
  1314. /// ExteriorRing(p Polygon) : LineString
  1315. /// For this test we will determine the exteroir ring of Blue Lake.
  1316. ///
  1317. /// ANSWER: 'LINESTRING(52 18, 66 23, 73 9, 48 6, 52 18)'
  1318. ///
  1319. /// Original SQL:
  1320. /// <code>
  1321. /// SELECT AsText(ExteriorRing(shore))
  1322. /// FROM lakes
  1323. /// WHERE name = 'Blue Lake';
  1324. /// </code>
  1325. /// </summary>
  1326. [Test]
  1327. public void ConformanceItemT27Hql()
  1328. {
  1329. string query =
  1330. @"select NHSP.AsText(NHSP.ExteriorRing(t.Shore))
  1331. from Lake t
  1332. where t.Name = 'Blue Lake'
  1333. ";
  1334. string result = session.CreateQuery(query)
  1335. .UniqueResult<string>();
  1336. IGeometry geometry = Wkt.Read(result);
  1337. IGeometry expected = Wkt.Read("LINESTRING(52 18, 66 23, 73 9, 48 6, 52 18)");
  1338. Assert.IsTrue(expected.Equals(geometry));
  1339. }
  1340. [Test]
  1341. public void ConformanceItemT27Linq()
  1342. {
  1343. var query =
  1344. from t in session.Query<Lake>()
  1345. where t.Name == "Blue Lake"
  1346. select ((IPolygon)t.Shore).ExteriorRing;
  1347. IGeometry geometry = query.Single();
  1348. IGeometry expected = Wkt.Read("LINESTRING(52 18, 66 23, 73 9, 48 6, 52 18)");
  1349. Assert.IsTrue(expected.Equals(geometry));
  1350. }
  1351. /// <summary>
  1352. /// Conformance Item T28
  1353. /// NumInteriorRings(p Polygon) : Integer
  1354. /// For this test we will determine the number of interior rings of Blue Lake.
  1355. ///
  1356. /// ANSWER: 1
  1357. ///
  1358. /// Original SQL:
  1359. /// <code>
  1360. /// SELECT NumInteriorRings(shore)
  1361. /// FROM lakes
  1362. /// WHERE name = 'Blue Lake';
  1363. /// </code>
  1364. /// </summary>
  1365. [Test]
  1366. public void ConformanceItemT28Hql()
  1367. {
  1368. string query =
  1369. @"select NHSP.NumInteriorRings(t.Shore)
  1370. from Lake t
  1371. where t.Name = 'Blue Lake'
  1372. ";
  1373. int result = session.CreateQuery(query)
  1374. .UniqueResult<int>();
  1375. Assert.AreEqual(1, result);
  1376. }
  1377. [Test]
  1378. public void ConformanceItemT28Linq()
  1379. {
  1380. var query =
  1381. from t in session.Query<Lake>()
  1382. where t.Name == "Blue Lake"
  1383. select ((IPolygon)t.Shore).NumInteriorRings;
  1384. int result = query.Single();
  1385. Assert.AreEqual(1, result);
  1386. }
  1387. /// <summary>
  1388. /// Conformance Item T29
  1389. /// InteriorRingN(p Polygon, n Integer) : LineString
  1390. /// For this test we will determine the first interior ring of Blue Lake.
  1391. ///
  1392. /// ANSWER: 'LINESTRING(59 18, 67 18, 67 13, 59 13, 59 18)'
  1393. ///
  1394. /// Original SQL:
  1395. /// <code>
  1396. /// SELECT AsText(InteriorRingN(shore, 1))
  1397. /// FROM lakes
  1398. /// WHERE name = 'Blue Lake';
  1399. /// </code>
  1400. /// </summary>
  1401. [Test]
  1402. public void ConformanceItemT29()
  1403. {
  1404. Lake entity = session.CreateCriteria(typeof(Lake))
  1405. .Add(Restrictions.Eq("Name", "Blue Lake"))
  1406. .UniqueResult<Lake>();
  1407. IGeometry geometry = (entity.Shore as IPolygon).InteriorRings[0];
  1408. IGeometry expected = Wkt.Read("LINESTRING(59 18, 67 18, 67 13, 59 13, 59 18)");
  1409. Assert.IsTrue(expected.Equals(geometry));
  1410. }
  1411. [Test]
  1412. public void ConformanceItemT29Hql()
  1413. {
  1414. string query =
  1415. @"select NHSP.AsText(NHSP.InteriorRingN(t.Shore, 1))
  1416. from Lake t
  1417. where t.Name = 'Blue Lake'
  1418. ";
  1419. string result = session.CreateQuery(query)
  1420. .UniqueResult<string>();
  1421. IGeometry geometry = Wkt.Read(result);
  1422. IGeometry expected = Wkt.Read("LINESTRING(59 18, 67 18, 67 13, 59 13, 59 18)");
  1423. Assert.IsTrue(expected.Equals(geometry));
  1424. }
  1425. [Test]
  1426. public void ConformanceItemT29Linq()
  1427. {
  1428. var query =
  1429. from t in session.Query<Lake>()
  1430. where t.Name == "Blue Lake"
  1431. select ((IPolygon)t.Shore).GetInteriorRingN(0);
  1432. IGeometry geometry = query.Single();
  1433. IGeometry expected = Wkt.Read("LINESTRING(59 18, 67 18, 67 13, 59 13, 59 18)");
  1434. Assert.IsTrue(expected.Equals(geometry));
  1435. }
  1436. #endregion
  1437. #region Queries testing functions in section 3.2.16.2 (T30 - T31)
  1438. /// <summary>
  1439. /// Conformance Item T30
  1440. /// NumGeometries(g GeometryCollection) : Integer
  1441. /// For this test we will determine the number of geometries in Route 75.
  1442. ///
  1443. /// ANSWER: 2
  1444. ///
  1445. /// Original SQL:
  1446. /// <code>
  1447. /// SELECT NumGeometries(centerlines)
  1448. /// FROM divided_routes
  1449. /// WHERE name = 'Route 75';
  1450. /// </code>
  1451. /// </summary>
  1452. [Test]
  1453. public void ConformanceItemT30Hql()
  1454. {
  1455. string query =
  1456. @"select NHSP.NumGeometries(t.Centerlines)
  1457. from DividedRoute t
  1458. where t.Name = 'Route 75'
  1459. ";
  1460. int result = session.CreateQuery(query)
  1461. .UniqueResult<int>();
  1462. Assert.AreEqual(2, result);
  1463. }
  1464. [Test]
  1465. public void ConformanceItemT30Linq()
  1466. {
  1467. var query =
  1468. from t in session.Query<DividedRoute>()
  1469. where t.Name == "Route 75"
  1470. select t.Centerlines.NumGeometries;
  1471. int result = query.Single();
  1472. Assert.AreEqual(2, result);
  1473. }
  1474. /// <summary>
  1475. /// Conformance Item T31
  1476. /// GeometryN(g GeometryCollection, n Integer) : Geometry
  1477. /// For this test we will determine the second geometry in Route 75.
  1478. ///
  1479. /// ANSWER: 'LINESTRING( 16 0, 16 23, 16 48 )'
  1480. ///
  1481. /// Original SQL:
  1482. /// <code>
  1483. /// SELECT GeometryN(centerlines, 2)
  1484. /// FROM divided_routes
  1485. /// WHERE name = 'Route 75';
  1486. /// </code>
  1487. /// </summary>
  1488. [Test]
  1489. public void ConformanceItemT31()
  1490. {
  1491. DividedRoute entity = session.CreateCriteria(typeof(DividedRoute))
  1492. .Add(Restrictions.Eq("Name", "Route 75"))
  1493. .UniqueResult<DividedRoute>();
  1494. IGeometry geometry = (entity.Centerlines as IMultiLineString).Geometries[1];
  1495. IGeometry expected = Wkt.Read("LINESTRING( 16 0, 16 23, 16 48 )");
  1496. Assert.IsTrue(expected.Equals(geometry));
  1497. }
  1498. [Test]
  1499. public void ConformanceItemT31Hql()
  1500. {
  1501. string query =
  1502. @"select NHSP.AsText(NHSP.GeometryN(t.Centerlines, 2))
  1503. from DividedRoute t
  1504. where t.Name = 'Route 75'
  1505. ";
  1506. string result = session.CreateQuery(query)
  1507. .UniqueResult<string>();
  1508. IGeometry geometry = Wkt.Read(result);
  1509. IGeometry expected = Wkt.Read("LINESTRING( 16 0, 16 23, 16 48 )");
  1510. Assert.IsTrue(expected.Equals(geometry));
  1511. }
  1512. [Test]
  1513. public void ConformanceItemT31Linq()
  1514. {
  1515. var query =
  1516. from t in session.Query<DividedRoute>()
  1517. where t.Name == "Route 75"
  1518. select t.Centerlines.GetGeometryN(1);
  1519. IGeometry geometry = query.Single();
  1520. IGeometry expected = Wkt.Read("LINESTRING( 16 0, 16 23, 16 48 )");
  1521. Assert.IsTrue(expected.Equals(geometry));
  1522. }
  1523. #endregion
  1524. #region Queries testing functions in section 3.2.17.2 (T31 - T33)
  1525. /// <summary>
  1526. /// Conformance Item T32
  1527. /// IsClosed(mc MultiCurve) : Integer
  1528. /// For this test we will determine if the geometry of Route 75 is closed.
  1529. ///
  1530. /// ANSWER: 0
  1531. /// *** Adaptation Alert ***
  1532. /// If the implementer provides IsClosed as a boolean function, instead of as
  1533. /// an INTEGER function, then:
  1534. /// ANSWER: FALSE or 'f'
  1535. ///
  1536. /// Original SQL:
  1537. /// <code>
  1538. /// SELECT IsClosed(centerlines)
  1539. /// FROM divided_routes
  1540. /// WHERE name = 'Route 75';
  1541. /// </code>
  1542. /// </summary>
  1543. [Test]
  1544. public void ConformanceItemT32Hql()
  1545. {
  1546. string query =
  1547. @"select NHSP.IsClosed(t.Centerlines)
  1548. from DividedRoute t
  1549. where t.Name = 'Route 75'
  1550. ";
  1551. bool result = session.CreateQuery(query)
  1552. .UniqueResult<bool>();
  1553. Assert.IsFalse(result);
  1554. }
  1555. [Test]
  1556. public void ConformanceItemT32Linq()
  1557. {
  1558. var query =
  1559. from t in session.Query<DividedRoute>()
  1560. where t.Name == "Route 75"
  1561. select ((ICurve)t.Centerlines).IsClosed;
  1562. bool result = query.Single();
  1563. Assert.IsFalse(result);
  1564. }
  1565. /// <summary>
  1566. /// Conformance Item T33
  1567. /// Length(mc MultiCurve) : Double Precision
  1568. /// For this test we will determine the length of Route 75.
  1569. /// NOTE: This makes no semantic sense in our example...
  1570. ///
  1571. /// ANSWER: 96.00 (meters)
  1572. ///
  1573. /// Original SQL:
  1574. /// <code>
  1575. /// SELECT Length(centerlines)
  1576. /// FROM divided_routes
  1577. /// WHERE name = 'Route 75';
  1578. /// </code>
  1579. /// </summary>
  1580. [Test]
  1581. public void ConformanceItemT33Hql()
  1582. {
  1583. string query =
  1584. @"select NHSP.Length(t.Centerlines)
  1585. from DividedRoute t
  1586. where t.Name = 'Route 75'
  1587. ";
  1588. double result = session.CreateQuery(query)
  1589. .UniqueResult<double>();
  1590. Assert.AreEqual(96, result);
  1591. }
  1592. [Test]
  1593. public void ConformanceItemT33Linq()
  1594. {
  1595. var query =
  1596. from t in session.Query<DividedRoute>()
  1597. where t.Name == "Route 75"
  1598. select t.Centerlines.Length;
  1599. double result = query.Single();
  1600. Assert.AreEqual(96, result);
  1601. }
  1602. #endregion
  1603. #region Queries testing functions in section 3.2.18.2 (T34 - T36)
  1604. /// <summary>
  1605. /// Conformance Item T34
  1606. /// Centroid(ms MultiSurface) : Point
  1607. /// For this test we will determine the centroid of the ponds.
  1608. ///
  1609. /// ANSWER: 'POINT( 25 42 )'
  1610. ///
  1611. /// Original SQL:
  1612. /// <code>
  1613. /// SELECT AsText(Centroid(shores))
  1614. /// FROM ponds
  1615. /// WHERE fid = 120;
  1616. /// </code>
  1617. /// </summary>
  1618. [Test]
  1619. public void ConformanceItemT34Hql()
  1620. {
  1621. string query =
  1622. @"select NHSP.AsText(NHSP.Centroid(t.Shores))
  1623. from Pond t
  1624. where t.Fid = 120
  1625. ";
  1626. string result = session.CreateQuery(query)
  1627. .UniqueResult<string>();
  1628. IGeometry geometry = Wkt.Read(result);
  1629. IGeometry expected = Wkt.Read("POINT( 25 42 )");
  1630. Assert.IsTrue(expected.Equals(geometry));
  1631. }
  1632. [Test]
  1633. public void ConformanceItemT34Linq()
  1634. {
  1635. var query =
  1636. from t in session.Query<Pond>()
  1637. where t.Fid == 120
  1638. select t.Shores.Centroid;
  1639. IGeometry geometry = query.Single();
  1640. IGeometry

Large files files are truncated, but you can click here to view the full file