PageRenderTime 62ms CodeModel.GetById 17ms app.highlight 34ms RepoModel.GetById 1ms 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

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

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

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