DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
SpatialFunctionsTest.cs
Go to the documentation of this file.
1 using System;
2 
3 using Deveel.Data;
4 using Deveel.Data.Routines;
5 using Deveel.Data.Services;
7 using Deveel.Data.Sql.Objects;
8 using Deveel.Data.Types;
9 
10 using NUnit.Framework;
11 
12 namespace Deveel.Data.Spatial {
13  [TestFixture]
15  protected override void RegisterServices(ServiceContainer container) {
16  container.UseSpatial();
17  }
18 
19  private DataObject ParseAndInvoke(string text) {
20  var exp = SqlExpression.Parse(text);
21  Assert.IsInstanceOf<SqlFunctionCallExpression>(exp);
22 
23  var functionName = ((SqlFunctionCallExpression) exp).FunctioName;
24  var args = ((SqlFunctionCallExpression) exp).Arguments;
25  var invoke = new Invoke(functionName, args);
26 
27  return Query.InvokeFunction(invoke);
28  }
29 
30  [Test]
31  public void PointFromWkt() {
32  const string text = "FROM_WKT('POINT(50.100299 12.3399)')";
33 
34  var result = ParseAndInvoke(text);
35 
36  Assert.IsNotNull(result);
37  Assert.IsFalse(result.IsNull);
38 
39  Assert.IsInstanceOf<SpatialType>(result.Type);
40 
41  var geometry = (SqlGeometry) result.Value;
42 
43  // TODO: Vrify strings equal to SqlString
44  // Assert.AreEqual("POINT", geometry.GeometryType.ToString());
45  }
46 
47  [Test]
48  public void DistanceCalculate() {
49  const string text = "DISTANCE(FROM_WKT('POINT(59.9308785 10.7893356)'), FROM_WKT('POINT(59.9284945 10.7786121)'))";
50 
51  var result = ParseAndInvoke(text);
52 
53  Assert.IsNotNull(result);
54  Assert.IsFalse(result.IsNull);
55 
56  Assert.IsInstanceOf<NumericType>(result.Type);
57 
58  var number = (SqlNumber) result.Value;
59 
60  // TODO: Assess the distance is right
61  }
62  }
63 }
static SqlExpression Parse(string s)
Parses the given SQL string to an expression that can be evaluated.
override void RegisterServices(ServiceContainer container)
Represents a dynamic object that encapsulates a defined SqlType and a compatible constant ISqlObject ...
Definition: DataObject.cs:35
The information about the invocation of a routine, including the full name and arguments (as SqlExpre...
Definition: Invoke.cs:30
Defines the base class for instances that represent SQL expression tree nodes.