Datei: IntegrationTests/IntegrationTests/KeyTests.cs

Last Commit (9d1552b)
1 //
2 // Copyright (c) 2002-2016 Mirko Matytschak
3 // (www.netdataobjects.de)
4 //
5 // Author: Mirko Matytschak
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
8 // documentation files (the "Software"), to deal in the Software without restriction, including without limitation
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
10 // Software, and to permit persons to whom the Software is furnished to do so, subject to the following
11 // conditions:
12
13 // The above copyright notice and this permission notice shall be included in all copies or substantial portions
14 // of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
17 // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
19 // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 // DEALINGS IN THE SOFTWARE.
21
22
23 using System;
24 using System.Collections;
25 using System.Text;
26 using NUnit.Framework;
27 using NDO;
28 using NDO.Mapping;
29 using PureBusinessClasses;
30
31 namespace NdoUnitTests
32 {
33 ····[TestFixture]
34 public class KeyTests
35 ····{
36 ········[SetUp]
37 ········public void Setup()
38 ········{
39 ········}
40
41 ········[TearDown]
42 ········public void TearDown()
43 ········{
44 ········}
45
46 ········[Ignore("This tests must be reworked")]
47 ········[Test]
48 ········public void GuidKeyEquality()
49 ········{
50 ············PersistenceManager pm = PmFactory.NewPersistenceManager();
51 ············Class cl = pm.NDOMapping.FindClass(typeof(OrderDetail));
52 ············IPersistenceCapable testObj1 = pm.FindObject( typeof( OrderDetail ), new object[] { new Guid( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ), new Guid( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ) } );
53 ············IPersistenceCapable testObj2 = pm.FindObject( typeof( OrderDetail ), new object[] { new Guid( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ), new Guid( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ) } );
54 ············ObjectId oid1 = testObj1.NDOObjectId;
55 ············ObjectId oid2 = testObj2.NDOObjectId;
56
57 ············Assert.That(oid1.GetHashCode() == oid2.GetHashCode(), "HashCodes should be equal");
58 ············Assert.That(oid1 == oid2, "Keys should be equal #1");
59 ············Assert.That(oid1.Equals(oid2), "Keys should be equal #2");
60 ············Assert.That(oid2.Equals(oid1), "Keys should be equal #3");
61
62 ············Hashtable ht = new Hashtable();
63 ············ht.Add(oid1, null);
64 ············Assert.That(ht.Contains(oid2));
65
66 ············Key key1 = oid1.Id;
67 ············Key key2 = oid2.Id;
68 ············Assert.That(key1.GetHashCode() == key2.GetHashCode(), "HashCodes should be equal");
69 ············Assert.That(key1 == key2, "Keys should be equal #4");
70 ············Assert.That(key1.Equals(key2), "Keys should be equal #5");
71 ············Assert.That(key2.Equals(key1), "Keys should be equal #6");
72
73 ············ht.Clear();
74 ············ht.Add(key1, null);
75 ············Assert.That(ht.Contains(key2));
76
77 ············oid1 = new ObjectId(key1);
78 ············oid2 = new ObjectId(key2);
79
80 ············Assert.That(oid1.GetHashCode() == oid2.GetHashCode(), "HashCodes should be equal");
81 ············Assert.That(oid1 == oid2, "Keys should be equal #7");
82 ············Assert.That(oid1.Equals(oid2), "Keys should be equal #8");
83 ············Assert.That(oid2.Equals(oid1), "Keys should be equal #9");
84 ········}
85
86
87
88 ········[Ignore("This tests must be reworked")]
89 ········[Test]
90 ········public void IntKeyEquality()
91 ········{
92 ············PersistenceManager pm = PmFactory.NewPersistenceManager();
93 ············Class cl = pm.NDOMapping.FindClass(typeof(OrderDetail));
94 ············IPersistenceCapable testObj1 = pm.FindObject( typeof( OrderDetail ), new object[] { 4711,4712 });
95 ············IPersistenceCapable testObj2 = pm.FindObject( typeof( OrderDetail ), new object[] { 4711,4712 });
96 ············ObjectId oid1 = testObj1.NDOObjectId;
97 ············ObjectId oid2 = testObj2.NDOObjectId;
98
99 ············Assert.That(oid1.GetHashCode() == oid2.GetHashCode(), "HashCodes should be equal");
100 ············Assert.That(oid1 == oid2, "Keys should be equal #1");
101 ············Assert.That(oid1.Equals(oid2), "Keys should be equal #2");
102 ············Assert.That(oid2.Equals(oid1), "Keys should be equal #3");
103
104 ············Hashtable ht = new Hashtable();
105 ············ht.Add(oid1, null);
106 ············Assert.That(ht.Contains(oid2));
107
108 ············Key key1 = oid1.Id;
109 ············Key key2 = oid2.Id;
110 ············Assert.That(key1.GetHashCode() == key2.GetHashCode(), "HashCodes should be equal");
111 ············Assert.That(key1 == key2, "Keys should be equal #4");
112 ············Assert.That(key1.Equals(key2), "Keys should be equal #5");
113 ············Assert.That(key2.Equals(key1), "Keys should be equal #6");
114
115 ············ht.Clear();
116 ············ht.Add(key1, null);
117 ············Assert.That(ht.Contains(key2));
118
119 ············oid1 = new ObjectId(key1);
120 ············oid2 = new ObjectId(key2);
121
122 ············Assert.That(oid1.GetHashCode() == oid2.GetHashCode(), "HashCodes should be equal");
123 ············Assert.That(oid1 == oid2, "Keys should be equal #7");
124 ············Assert.That(oid1.Equals(oid2), "Keys should be equal #8");
125 ············Assert.That(oid2.Equals(oid1), "Keys should be equal #9");
126 ········}
127 ····}
128 }
129
New Commit (60cb179)
1 //
2 // Copyright (c) 2002-2016 Mirko Matytschak
3 // (www.netdataobjects.de)
4 //
5 // Author: Mirko Matytschak
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
8 // documentation files (the "Software"), to deal in the Software without restriction, including without limitation
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
10 // Software, and to permit persons to whom the Software is furnished to do so, subject to the following
11 // conditions:
12
13 // The above copyright notice and this permission notice shall be included in all copies or substantial portions
14 // of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
17 // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
19 // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 // DEALINGS IN THE SOFTWARE.
21
22
23 using System;
24 using System.Collections;
25 using System.Text;
26 using NUnit.Framework;
27 using NDO;
28 using NDO.Mapping;
29 using PureBusinessClasses;
30
31 namespace NdoUnitTests
32 {
33 ····[TestFixture]
34 public class KeyTests : NDOTest
35 ····{
36 ········[SetUp]
37 ········public void Setup()
38 ········{
39 ········}
40
41 ········[TearDown]
42 ········public void TearDown()
43 ········{
44 ········}
45
46 ········[Ignore("This tests must be reworked")]
47 ········[Test]
48 ········public void GuidKeyEquality()
49 ········{
50 ············PersistenceManager pm = PmFactory.NewPersistenceManager();
51 ············Class cl = pm.NDOMapping.FindClass(typeof(OrderDetail));
52 ············IPersistenceCapable testObj1 = pm.FindObject( typeof( OrderDetail ), new object[] { new Guid( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ), new Guid( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ) } );
53 ············IPersistenceCapable testObj2 = pm.FindObject( typeof( OrderDetail ), new object[] { new Guid( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ), new Guid( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ) } );
54 ············ObjectId oid1 = testObj1.NDOObjectId;
55 ············ObjectId oid2 = testObj2.NDOObjectId;
56
57 ············Assert.That(oid1.GetHashCode() == oid2.GetHashCode(), "HashCodes should be equal");
58 ············Assert.That(oid1 == oid2, "Keys should be equal #1");
59 ············Assert.That(oid1.Equals(oid2), "Keys should be equal #2");
60 ············Assert.That(oid2.Equals(oid1), "Keys should be equal #3");
61
62 ············Hashtable ht = new Hashtable();
63 ············ht.Add(oid1, null);
64 ············Assert.That(ht.Contains(oid2));
65
66 ············Key key1 = oid1.Id;
67 ············Key key2 = oid2.Id;
68 ············Assert.That(key1.GetHashCode() == key2.GetHashCode(), "HashCodes should be equal");
69 ············Assert.That(key1 == key2, "Keys should be equal #4");
70 ············Assert.That(key1.Equals(key2), "Keys should be equal #5");
71 ············Assert.That(key2.Equals(key1), "Keys should be equal #6");
72
73 ············ht.Clear();
74 ············ht.Add(key1, null);
75 ············Assert.That(ht.Contains(key2));
76
77 ············oid1 = new ObjectId(key1);
78 ············oid2 = new ObjectId(key2);
79
80 ············Assert.That(oid1.GetHashCode() == oid2.GetHashCode(), "HashCodes should be equal");
81 ············Assert.That(oid1 == oid2, "Keys should be equal #7");
82 ············Assert.That(oid1.Equals(oid2), "Keys should be equal #8");
83 ············Assert.That(oid2.Equals(oid1), "Keys should be equal #9");
84 ········}
85
86
87
88 ········[Ignore("This tests must be reworked")]
89 ········[Test]
90 ········public void IntKeyEquality()
91 ········{
92 ············PersistenceManager pm = PmFactory.NewPersistenceManager();
93 ············Class cl = pm.NDOMapping.FindClass(typeof(OrderDetail));
94 ············IPersistenceCapable testObj1 = pm.FindObject( typeof( OrderDetail ), new object[] { 4711,4712 });
95 ············IPersistenceCapable testObj2 = pm.FindObject( typeof( OrderDetail ), new object[] { 4711,4712 });
96 ············ObjectId oid1 = testObj1.NDOObjectId;
97 ············ObjectId oid2 = testObj2.NDOObjectId;
98
99 ············Assert.That(oid1.GetHashCode() == oid2.GetHashCode(), "HashCodes should be equal");
100 ············Assert.That(oid1 == oid2, "Keys should be equal #1");
101 ············Assert.That(oid1.Equals(oid2), "Keys should be equal #2");
102 ············Assert.That(oid2.Equals(oid1), "Keys should be equal #3");
103
104 ············Hashtable ht = new Hashtable();
105 ············ht.Add(oid1, null);
106 ············Assert.That(ht.Contains(oid2));
107
108 ············Key key1 = oid1.Id;
109 ············Key key2 = oid2.Id;
110 ············Assert.That(key1.GetHashCode() == key2.GetHashCode(), "HashCodes should be equal");
111 ············Assert.That(key1 == key2, "Keys should be equal #4");
112 ············Assert.That(key1.Equals(key2), "Keys should be equal #5");
113 ············Assert.That(key2.Equals(key1), "Keys should be equal #6");
114
115 ············ht.Clear();
116 ············ht.Add(key1, null);
117 ············Assert.That(ht.Contains(key2));
118
119 ············oid1 = new ObjectId(key1);
120 ············oid2 = new ObjectId(key2);
121
122 ············Assert.That(oid1.GetHashCode() == oid2.GetHashCode(), "HashCodes should be equal");
123 ············Assert.That(oid1 == oid2, "Keys should be equal #7");
124 ············Assert.That(oid1.Equals(oid2), "Keys should be equal #8");
125 ············Assert.That(oid2.Equals(oid1), "Keys should be equal #9");
126 ········}
127 ····}
128 }
129