DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
XmlFunctionsTest.cs
Go to the documentation of this file.
1 using System;
2 using System.Text;
3 
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.Xml {
13  [TestFixture]
15  protected override void RegisterServices(ServiceContainer container) {
16  container.UseXml();
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 ToXmlType() {
32  const string text = "TO_XML('<root>value</root>')";
33 
34  var result = ParseAndInvoke(text);
35 
36  Assert.IsNotNull(result);
37  Assert.IsInstanceOf<XmlNodeType>(result.Type);
38  Assert.IsFalse(result.IsNull);
39  }
40 
41  [Test]
42  public void ExtractXml() {
43  const string text = "EXTRACT(TO_XML('<root><child>value</child></root>'), '/root/child')";
44 
45  var result = ParseAndInvoke(text);
46 
47  Assert.IsNotNull(result);
48  Assert.IsInstanceOf<XmlNodeType>(result.Type);
49  Assert.IsFalse(result.IsNull);
50  }
51 
52  [Test]
53  public void ExtractValue() {
54  const string text = "EXTRACTVALUE(TO_XML('<root><child>value</child></root>'), '/root/child/text()')";
55 
56  var result = ParseAndInvoke(text);
57 
58  Assert.IsNotNull(result);
59  Assert.IsInstanceOf<StringType>(result.Type);
60  Assert.IsFalse(result.IsNull);
61  }
62 
63  [Test]
64  public void UpdateText() {
65  const string text = "UPDATEXML(TO_XML('<root><child>value</child></root>'), '/root/child/text()', 'value2')";
66 
67  var result = ParseAndInvoke(text);
68 
69  Assert.IsNotNull(result);
70  Assert.IsInstanceOf<XmlNodeType>(result.Type);
71  Assert.IsFalse(result.IsNull);
72 
73  /*
74  TODO: must inspect why the text fails to compare...
75  var xmlNode = (SqlXmlNode) result.Value;
76  var updated = xmlNode.ToSqlString().Value;
77  var expected = "<root><child>value2</child></root>";
78  Assert.AreEqual(expected, updated);
79  */
80  }
81  }
82 }
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
DataObject ParseAndInvoke(string text)
Defines the base class for instances that represent SQL expression tree nodes.