DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
ObjectNameTest.cs
Go to the documentation of this file.
1 //
2 // Copyright 2010-2014 Deveel
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 using System;
17 
18 using Deveel.Data.Sql;
19 
20 using NUnit.Framework;
21 
22 namespace Deveel.Data {
23  [TestFixture]
24  [Category("Object Name")]
25  public class ObjectNameTest {
26  [Test]
27  public void SimpleName() {
28  var objName = new ObjectName("id");
29  Assert.IsNotNull(objName);
30  Assert.IsNull(objName.Parent);
31  Assert.AreEqual("id", objName.Name);
32  Assert.AreEqual("id", objName.FullName);
33  Assert.IsFalse(objName.IsGlob);
34  }
35 
36  [Test]
37  public void ComplexName() {
38  var objName = new ObjectName(new ObjectName("parent"), "id");
39  Assert.IsNotNull(objName);
40  Assert.IsNotNull(objName.Parent);
41  Assert.AreEqual("parent", objName.Parent.Name);
42  Assert.IsNotNull(objName.Name);
43  Assert.AreEqual("id", objName.Name);
44  Assert.AreEqual("parent.id", objName.FullName);
45  Assert.IsFalse(objName.IsGlob);
46  }
47 
48  [Test]
49  public void ComplexNameWithGlob() {
50  var objName = new ObjectName(new ObjectName("parent"), "*");
51  Assert.IsNotNull(objName);
52  Assert.IsNotNull(objName.Parent);
53  Assert.AreEqual("parent", objName.Parent.Name);
54  Assert.IsNotNull(objName.Name);
55  Assert.AreEqual("*", objName.Name);
56  Assert.AreEqual("parent.*", objName.FullName);
57  Assert.IsTrue(objName.IsGlob);
58  }
59 
60  [Test]
61  public void SimpleName_Parse() {
62  ObjectName objName = null;
63  Assert.DoesNotThrow(() => objName = ObjectName.Parse("id"));
64  Assert.IsNotNull(objName);
65  Assert.AreEqual("id", objName.Name);
66  Assert.AreEqual("id", objName.FullName);
67  Assert.IsFalse(objName.IsGlob);
68  }
69 
70  [Test]
71  public void ComplexName_Parse() {
72  ObjectName objName = null;
73  Assert.DoesNotThrow(() => objName = ObjectName.Parse("parent.id"));
74  Assert.IsNotNull(objName);
75  Assert.IsNotNull(objName.Parent);
76  Assert.AreEqual("parent", objName.Parent.Name);
77  Assert.IsNotNull(objName.Name);
78  Assert.AreEqual("id", objName.Name);
79  Assert.AreEqual("parent.id", objName.FullName);
80  Assert.IsFalse(objName.IsGlob);
81  }
82 
83  [Test]
84  public void SimpleName_Compare() {
85  var objName1 = new ObjectName("id1");
86  var objName2 = new ObjectName("id2");
87 
88  int i = -2;
89  Assert.DoesNotThrow(() => i = objName1.CompareTo(objName2));
90  Assert.AreEqual(-1, i);
91  }
92 
93  [Test]
94  public void SimpleName_Equals() {
95  var objName1 = new ObjectName("id1");
96  var objName2 = new ObjectName("id1");
97  Assert.IsTrue(objName1.Equals(objName2));
98  }
99 
100  [Test]
101  public void SimpleName_NotEquals() {
102  var objName1 = new ObjectName("id1");
103  var objName2 = new ObjectName("id2");
104  Assert.IsFalse(objName1.Equals(objName2));
105  }
106  }
107 }
static ObjectName Parse(string s)
Parses the given string into a ObjectName object.
Definition: ObjectName.cs:139
Describes the name of an object within a database.
Definition: ObjectName.cs:44
bool IsGlob
Indicates if this reference equivales to GlobName.
Definition: ObjectName.cs:121
string FullName
Gets the full reference name formatted.
Definition: ObjectName.cs:114
ObjectName Parent
Gets the parent reference of the current one, if any or null if none.
Definition: ObjectName.cs:99
string Name
Gets the name of the object being referenced.
Definition: ObjectName.cs:108