Datei: IntegrationTests/NdoUnitTests/TimeStampTest.cs
Last Commit (123a4dc)
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 TimeStampTestClasses; |
26 | using NDO; |
27 | using NUnit.Framework; |
28 | using NDO.Query; |
29 | |
30 | namespace NdoUnitTests |
31 | { |
32 | ····[TestFixture] |
33 | ····public class TimeStampTest |
34 | ····{ |
35 | ········PersistenceManager pm1; |
36 | ········PersistenceManager pm2; |
37 | ········TimeStampContainer tsc; |
38 | ········bool collisionHappened = false; |
39 | |
40 | ········[SetUp] |
41 | ········public void Setup() |
42 | ········{ |
43 | ············tsc = new TimeStampContainer("Hans"); |
44 | ············pm1 = PmFactory.NewPersistenceManager(); |
45 | ············pm2 = PmFactory.NewPersistenceManager(); |
46 | ············pm1.MakePersistent(tsc); |
47 | ············pm1.Save(); |
48 | ············pm1.UnloadCache(); |
49 | ········} |
50 | |
51 | ········[TearDown] |
52 | ········public void TearDown() |
53 | ········{ |
54 | ············if (pm2 == null) |
55 | ················pm2 = PmFactory.NewPersistenceManager(); |
56 | ············pm2.UnloadCache(); |
57 | ············IList l = pm2.GetClassExtent(typeof(TimeStampContainer), false); |
58 | ············if (l.Count > 0) |
59 | ············{ |
60 | ················pm2.Delete(l); |
61 | ················pm2.Save(); |
62 | ············} |
63 | ············pm2.Close(); |
64 | ············pm2 = null; |
65 | ············if (pm1 != null) |
66 | ············{ |
67 | ················pm1.Close(); |
68 | ················pm1 = null; |
69 | ············} |
70 | ········} |
71 | |
72 | ········[Test] |
73 | ········public void TestTimeStampsNoException() |
74 | ········{ |
75 | ············IList l1 = pm1.GetClassExtent(typeof(TimeStampContainer)); |
76 | ············Assert.AreEqual(1, l1.Count, "Count sollte 1 sein"); |
77 | ············IList l2 = pm2.GetClassExtent(typeof(TimeStampContainer)); |
78 | ············Assert.AreEqual(1, l2.Count, "Count sollte 1 sein"); |
79 | ············TimeStampContainer tsc1 = (TimeStampContainer) l1[0]; |
80 | ············TimeStampContainer tsc2 = (TimeStampContainer) l2[0]; |
81 | ············pm1.CollisionEvent += new CollisionHandler(OnCollisionEvent); |
82 | ············tsc1.Name = "Friedrich"; |
83 | ············tsc2.Name = "Peter"; |
84 | ············pm2.Save(); |
85 | ············pm1.Save(); |
86 | ············Assert.AreEqual(true, collisionHappened, "Kollision ist nicht erkannt worden"); |
87 | ········} |
88 | |
89 | |
90 | //········[Test] |
91 | //········public void GetMappingFile() |
92 | //········{ |
93 | //············PersistenceManager pm = PmFactory.NewPersistenceManager(); |
94 | //············System.Diagnostics.Debug.WriteLine(pm.NDOMapping.FileName); |
95 | //········} |
96 | |
97 | ········[Test] |
98 | ········public void TestDeleteHollow() |
99 | ········{ |
100 | ············IQuery q = new NDOQuery<TimeStampContainer>(pm1, null, true); |
101 | ············tsc = (TimeStampContainer) q.ExecuteSingle(true); |
102 | ············Assert.AreEqual(NDOObjectState.Hollow, tsc.NDOObjectState, "Object should be hollow"); |
103 | ············Assert.That(((IPersistenceCapable)tsc).NDOTimeStamp != Guid.Empty, "Time Stamp should be there"); |
104 | ············pm1.Delete(tsc); |
105 | ············pm1.Save(); |
106 | ············pm1.UnloadCache(); |
107 | ············IList l = pm1.GetClassExtent(typeof(TimeStampContainer)); |
108 | ············Assert.AreEqual(0, l.Count, "No object should be there"); |
109 | ········} |
110 | |
111 | ········private void OnCollisionEvent(object pc) |
112 | ········{ |
113 | ············this.collisionHappened = true; |
114 | ········} |
115 | ····} |
116 | } |
117 |
New Commit (16046d5)
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 TimeStampTestClasses; |
26 | using NDO; |
27 | using NUnit.Framework; |
28 | using NDO.Query; |
29 | using System.Linq; |
30 | |
31 | namespace NdoUnitTests |
32 | { |
33 | ····[TestFixture] |
34 | ····public class TimeStampTest |
35 | ····{ |
36 | ········PersistenceManager pm1; |
37 | ········PersistenceManager pm2; |
38 | ········TimeStampContainer tsc; |
39 | ········bool collisionHappened = false; |
40 | |
41 | ········[SetUp] |
42 | ········public void Setup() |
43 | ········{ |
44 | ············tsc = new TimeStampContainer("Hans"); |
45 | ············pm1 = PmFactory.NewPersistenceManager(); |
46 | ············pm2 = PmFactory.NewPersistenceManager(); |
47 | ············pm1.MakePersistent(tsc); |
48 | ············pm1.Save(); |
49 | ············pm1.UnloadCache(); |
50 | ········} |
51 | |
52 | ········[TearDown] |
53 | ········public void TearDown() |
54 | ········{ |
55 | ············if (pm2 == null) |
56 | ················pm2 = PmFactory.NewPersistenceManager(); |
57 | ············pm2.UnloadCache(); |
58 | ············pm2.Delete( pm2.Objects<RowVersionClass>().ResultTable ); |
59 | ············IList l = pm2.GetClassExtent(typeof(TimeStampContainer), false); |
60 | ············if (l.Count > 0) |
61 | ············{ |
62 | ················pm2.Delete(l); |
63 | ················pm2.Save(); |
64 | ············} |
65 | ············pm2.Close(); |
66 | ············pm2 = null; |
67 | ············if (pm1 != null) |
68 | ············{ |
69 | ················pm1.Close(); |
70 | ················pm1 = null; |
71 | ············} |
72 | ········} |
73 | |
74 | ········[Test] |
75 | ········public void TestTimeStampsNoException() |
76 | ········{ |
77 | ············IList l1 = pm1.GetClassExtent(typeof(TimeStampContainer)); |
78 | ············Assert.AreEqual(1, l1.Count, "Count sollte 1 sein"); |
79 | ············IList l2 = pm2.GetClassExtent(typeof(TimeStampContainer)); |
80 | ············Assert.AreEqual(1, l2.Count, "Count sollte 1 sein"); |
81 | ············TimeStampContainer tsc1 = (TimeStampContainer) l1[0]; |
82 | ············TimeStampContainer tsc2 = (TimeStampContainer) l2[0]; |
83 | ············pm1.CollisionEvent += new CollisionHandler(OnCollisionEvent); |
84 | ············tsc1.Name = "Friedrich"; |
85 | ············tsc2.Name = "Peter"; |
86 | ············pm2.Save(); |
87 | ············pm1.Save(); |
88 | ············Assert.AreEqual(true, collisionHappened, "Kollision ist nicht erkannt worden"); |
89 | ········} |
90 | |
91 | ········[Test] |
92 | ········public void TestDeleteHollow() |
93 | ········{ |
94 | ············IQuery q = new NDOQuery<TimeStampContainer>(pm1, null, true); |
95 | ············tsc = (TimeStampContainer) q.ExecuteSingle(true); |
96 | ············Assert.AreEqual(NDOObjectState.Hollow, tsc.NDOObjectState, "Object should be hollow"); |
97 | ············Assert.That(((IPersistenceCapable)tsc).NDOTimeStamp != Guid.Empty, "Time Stamp should be there"); |
98 | ············pm1.Delete(tsc); |
99 | ············pm1.Save(); |
100 | ············pm1.UnloadCache(); |
101 | ············IList l = pm1.GetClassExtent(typeof(TimeStampContainer)); |
102 | ············Assert.AreEqual(0, l.Count, "No object should be there"); |
103 | ········} |
104 | |
105 | ········[Test] |
106 | ········public void CanWorkWithRowversions() |
107 | ········{ |
108 | ············RowVersionClass rwc = new RowVersionClass(); |
109 | ············rwc.MyData = "Testdata"; |
110 | ············pm1.MakePersistent( rwc ); |
111 | ············pm1.Save(); |
112 | ············rwc = pm1.Objects<RowVersionClass>().Single(); |
113 | ············var oldVersion = rwc.RowVersion; |
114 | ············Assert.AreNotEqual( oldVersion, (ulong) 0 ); |
115 | ············var changesSince = RowVersionClass.GetNewerThan( pm1, oldVersion ); |
116 | ············Assert.IsFalse( changesSince.Any() ); |
117 | ············rwc.MyData = "Testdata";····// Makes object dirty |
118 | ············pm1.Save();····················// This creates a new version |
119 | ············changesSince = RowVersionClass.GetNewerThan( pm1, oldVersion ); |
120 | ············Assert.IsTrue( changesSince.Any() ); |
121 | ········} |
122 | |
123 | ········private void OnCollisionEvent(object pc) |
124 | ········{ |
125 | ············this.collisionHappened = true; |
126 | ········} |
127 | ····} |
128 | } |
129 |