Datei: IntegrationTests/IntegrationTests/LandFlughafenTests.cs

Last Commit (08b23aa)
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.Diagnostics;
25 using System.Reflection;
26 using System.Collections;
27 using NUnit.Framework;
28 using NDO;
29 using NDO.Query;
30 using Reisekosten;
31
32 namespace NdoUnitTests
33 {
34 ····/// <summary>
35 ····/// Combined Tests of Land and Flughafen to test uniqueness of object ids.
36 ····/// </summary>
37 ····[TestFixture]
38 public class LandFlughafenTests
39 ····{
40 ········public LandFlughafenTests()
41 ········{
42 ········}
43
44 ········private PersistenceManager pm;
45 ········private Land l;
46 ········private Flughafen f;
47
48 ········[SetUp]
49 ········public void Setup()
50 ········{
51 ············pm = PmFactory.NewPersistenceManager();
52 ············l = CreateLand("Deutschland");
53 ············f = CreateFlughafen("MUC");
54 ········}
55
56 ········[TearDown]
57 ········public void TearDown()
58 ········{
59 ············pm.Abort();
60 ············IList l = pm.GetClassExtent(typeof(Land));
61 ············pm.Delete(l);
62 ············l = pm.GetClassExtent(typeof(Flughafen));
63 ············pm.Delete(l);
64 ············pm.Save();
65 ············pm.Close();
66 ········}
67
68 ········[Test]
69 ········public void TestCreateObjects()
70 ········{
71 ············pm.MakePersistent(l);
72 ············pm.MakePersistent(f);
73 ············if (!pm.HasOwnerCreatedIds)
74 ············{
75 ················if (l.NDOObjectId.Id[0] is Int32)
76 ····················Assert.That(-1 == (int) l.NDOObjectId.Id[0], "Land key wrong");
77 ················if (f.NDOObjectId.Id[0] is Int32)
78 ····················Assert.That(-1 == (int) f.NDOObjectId.Id[0], "Flughafen key wrong");
79 ············}
80 ············Assert.That(!l.NDOObjectId.Equals(f.NDOObjectId), "Ids should be different");
81 ············l = (Land)pm.FindObject(l.NDOObjectId);
82 ············f = (Flughafen)pm.FindObject(f.NDOObjectId);
83 ········}
84
85 ········[Test]
86 ········public void TestCreateObjectsSave()
87 ········{
88 ············
89 ············pm.MakePersistent(l);
90 ············pm.MakePersistent(f);
91 ············l.AddFlughafen(f);
92 ············pm.Save();
93 ············Assert.That(!l.NDOObjectId.Equals(f.NDOObjectId), "Ids should be different");
94 ············l = (Land)pm.FindObject(l.NDOObjectId);
95 ············f = (Flughafen)pm.FindObject(f.NDOObjectId);
96 ············Assert.That(l != null, "1. Land not found");
97 ············Assert.That(f != null, "1. Flughafen not found");
98
99 ············pm.UnloadCache();
100 ············l = (Land)pm.FindObject(l.NDOObjectId);
101 ············f = (Flughafen)pm.FindObject(f.NDOObjectId);
102 ············Assert.That(l != null, "2. Land not found");
103 ············Assert.That(f != null, "2. Flughafen not found");
104 ········}
105
106 ········[Test]
107 ········public void TestCreateObjectsSaveReload()
108 ········{
109
110 ············pm.MakePersistent( l );
111 ············pm.MakePersistent( f );
112 ············l.AddFlughafen( f );
113 ············pm.Save();
114 ············pm.UnloadCache();
115 ············Land l2 = new NDOQuery<Land>(pm).ExecuteSingle();
116 ············Assert.That(l2··!= null);
117 ············Assert.That(1 ==··l.Flughäfen.Count, "1. Wrong number of objects" );
118 ········}
119
120 ········[Test]
121 ········public void TestAddObjectSave()
122 ········{
123 ············pm.MakePersistent(l);
124 ············pm.Save();
125 ············pm.MakePersistent(f);
126 ············l.AddFlughafen(f);
127 ············Assert.That(NDOObjectState.Created ==··f.NDOObjectState, "1. Wrong state");
128 ············pm.Save();
129 ············l = (Land)pm.FindObject(l.NDOObjectId);
130 ············f = (Flughafen)pm.FindObject(f.NDOObjectId);
131 ············Assert.That(l != null, "1. Land not found");
132 ············Assert.That(f != null, "1. Flughafen not found");
133 ············Assert.That(NDOObjectState.Persistent ==··f.NDOObjectState, "2. Wrong state");
134 ········}
135 ············
136 ········[Test]
137 ········public void TestAddObjectAbort()
138 ········{
139 ············pm.MakePersistent(l);
140 ············pm.Save();
141 ············pm.MakePersistent(f);
142 ············l.AddFlughafen(f);
143 ············Assert.That(NDOObjectState.Created ==··f.NDOObjectState, "1. Wrong state");
144 ············Assert.That(1 ==··l.Flughäfen.Count, "1. Wrong number of objects");
145 ············pm.Abort();
146 ············Assert.That(NDOObjectState.Transient ==··f.NDOObjectState, "2. Wrong state");
147 ············Assert.That(0 ==··l.Flughäfen.Count, "2. Wrong number of objects");
148 ········}
149
150 ········[Test]
151 ········public void TestRemoveObjectSave()
152 ········{
153 ············pm.MakePersistent(l);
154 ············pm.MakePersistent(f);
155 ············l.AddFlughafen(f);
156 ············pm.Save();
157 ············Assert.That(1 ==··l.Flughäfen.Count, "1. Wrong number of objects");
158 ············l.RemoveFlughafen(f);
159 ············// f keeps the foreign key - so it get's dirty
160 ············Assert.That(NDOObjectState.PersistentDirty ==··f.NDOObjectState, "1. Wrong state");
161 ············Assert.That(0 ==··l.Flughäfen.Count, "2. Wrong number of objects");
162 ············pm.Save();
163 ············Assert.That(0 ==··l.Flughäfen.Count, "3. Wrong number of objects");
164 ············Assert.That(NDOObjectState.Persistent ==··f.NDOObjectState, "2. Wrong state");
165 ········}
166
167 ········[Test]
168 ········public void TestRemoveObjectSaveReload()
169 ········{
170 ············pm.MakePersistent( l );
171 ············pm.MakePersistent( f );
172 ············l.AddFlughafen( f );
173 ············pm.Save();
174 ············pm.UnloadCache();
175 ············NDOQuery<Land> q = new NDOQuery<Land>( pm );
176 ············l = q.ExecuteSingle(true);
177 ············Assert.That(NDOObjectState.Persistent ==··l.NDOObjectState, "1. Wrong state");
178 ············Assert.That(1 ==··l.Flughäfen.Count, "1. Wrong number of objects");
179 ············f = (Flughafen) l.Flughäfen[0];
180 ············l.RemoveFlughafen(f);
181 ············// f keeps the foreign key - so it get's dirty
182 ············Assert.That(NDOObjectState.PersistentDirty ==··f.NDOObjectState, "2. Wrong state");
183 ············Assert.That(0 ==··l.Flughäfen.Count, "2. Wrong number of objects");
184 ············pm.Save();
185 ············l = (Land) q.ExecuteSingle(true);
186 ············pm.UnloadCache();
187 ············Assert.That(0 ==··l.Flughäfen.Count, "3. Wrong number of objects");
188 ········}
189
190 ········[Test]
191 ········public void TestRemoveObjectSaveReloadNonHollow()
192 ········{
193 ············pm.MakePersistent(l);
194 ············pm.MakePersistent(f);
195 ············l.AddFlughafen(f);
196 ············pm.Save();
197 ············pm.UnloadCache();
198 ············IQuery q = new NDOQuery<Land>(pm, null, false);
199 ············l = (Land) q.ExecuteSingle(true);
200 ············Assert.That(NDOObjectState.Persistent ==··l.NDOObjectState, "1. Wrong state");
201 ············Assert.That(1 ==··l.Flughäfen.Count, "1. Wrong number of objects");
202 ············f = (Flughafen) l.Flughäfen[0];
203 ············l.RemoveFlughafen(f);
204 ············// f keeps the foreign key - so it get's dirty
205 ············Assert.That(NDOObjectState.PersistentDirty ==··f.NDOObjectState, "2. Wrong state");
206 ············Assert.That(0 ==··l.Flughäfen.Count, "2. Wrong number of objects");
207 ············pm.Save();
208 ············l = (Land) q.ExecuteSingle(true);
209 ············pm.UnloadCache();
210 ············Assert.That(0 ==··l.Flughäfen.Count, "3. Wrong number of objects");
211 ········}
212
213 ········[Test]
214 ········public void TestRemoveObjectAbort()
215 ········{
216 ············pm.MakePersistent(l);
217 ············pm.MakePersistent(f);
218 ············l.AddFlughafen(f);
219 ············pm.Save();
220 ············Assert.That(1 ==··l.Flughäfen.Count, "1. Wrong number of objects");
221 ············l.RemoveFlughafen(f);
222 ············Assert.That(NDOObjectState.PersistentDirty ==··f.NDOObjectState, "1. Wrong state");
223 ············Assert.That(0 ==··l.Flughäfen.Count, "2. Wrong number of objects");
224 ············pm.Abort();
225 ············Assert.That(1 ==··l.Flughäfen.Count, "3. Wrong number of objects");
226 ············Assert.That(NDOObjectState.Persistent ==··f.NDOObjectState, "2. Wrong state");
227 ········}
228
229 ········[Test]
230 ········public void TestDeleteSave()
231 ········{
232 ············pm.MakePersistent(l);
233 ············pm.MakePersistent(f);
234 ············l.AddFlughafen(f);
235 ············pm.Save();
236 ············pm.Delete(l); // sollte Exception geben
237 ············Assert.That(NDOObjectState.Deleted ==··l.NDOObjectState, "1. Wrong state");
238 ············Assert.That(NDOObjectState.PersistentDirty ==··f.NDOObjectState, "2. Wrong state");
239 ············pm.Save();
240 ············Assert.That(NDOObjectState.Transient ==··l.NDOObjectState, "1. Wrong state");
241 ············Assert.That(NDOObjectState.Persistent ==··f.NDOObjectState, "2. Wrong state");
242 ········}
243
244
245
246 ········[Test]
247 ········public void TestDeleteAbort()
248 ········{
249 ············pm.MakePersistent(l);
250 ············pm.MakePersistent(f);
251 ············l.AddFlughafen(f);
252 ············pm.Save();
253 ············pm.Delete(l);··// sollte Exception geben
254 ············Assert.That(NDOObjectState.Deleted ==··l.NDOObjectState, "1. Wrong state");
255 ············Assert.That(NDOObjectState.PersistentDirty ==··f.NDOObjectState, "2. Wrong state");
256 ············pm.Abort();
257 ············Assert.That(NDOObjectState.Persistent ==··l.NDOObjectState, "1. Wrong state");
258 ············Assert.That(NDOObjectState.Persistent ==··f.NDOObjectState, "2. Wrong state");
259 ········}
260
261 ········[Test]
262 ········public void TestAddRemoveSave()
263 ········{
264 ············pm.MakePersistent(l);
265 ············pm.Save();
266 ············pm.MakePersistent(f);
267 ············l.AddFlughafen(f);
268 ············l.RemoveFlughafen(f);
269 ············Assert.That(NDOObjectState.Created ==··f.NDOObjectState, "1. Wrong state");
270 ············pm.Save();
271 ············Assert.That(NDOObjectState.Persistent ==··f.NDOObjectState, "2. Wrong state");
272 ········}
273
274 ········[Test]
275 ········public void TestAddRemoveAbort()
276 ········{
277 ············pm.MakePersistent(l);
278 ············pm.Save();
279 ············pm.MakePersistent(f);
280 ············l.AddFlughafen(f);
281 ············l.RemoveFlughafen(f);
282 ············Assert.That(NDOObjectState.Created ==··f.NDOObjectState, "1. Wrong state");
283 ············pm.Abort();
284 ············Assert.That(NDOObjectState.Transient ==··f.NDOObjectState, "2. Wrong state");
285 ········}
286
287 ········[Test]
288 ········public void TestClearRelatedObjectsSave()
289 ········{
290 ············pm.MakePersistent(l);
291 ············for(int i = 0; i < 10; i++)
292 ············{
293 ················Flughafen f = CreateFlughafen(i.ToString());
294 ················pm.MakePersistent(f);
295 ················l.AddFlughafen(f);
296 ············}
297 ············pm.Save();
298 ············IList ff = new ArrayList(l.Flughäfen);
299 ············l.LöscheFlughäfen();
300 ············Assert.That(0 ==··l.Flughäfen.Count, "1. Wrong number of objects");
301 ············for(int i = 0; i < 10; i++)
302 ············{
303 ················Assert.That(NDOObjectState.PersistentDirty ==··((Flughafen)ff[i]).NDOObjectState, "2. Wrong state");
304 ············}
305 ············pm.Save();
306 ············Assert.That(0 ==··l.Flughäfen.Count, "3. Wrong number of objects");
307 ············for(int i = 0; i < 10; i++)
308 ············{
309 ················Assert.That(NDOObjectState.Persistent ==··((Flughafen)ff[i]).NDOObjectState, "4. Wrong state");
310 ············}
311 ········}
312
313 ········[Test]
314 ········public void TestClearRelatedObjectsAbort()
315 ········{
316 ············pm.MakePersistent(l);
317 ············for(int i = 0; i < 10; i++)
318 ············{
319 ················Flughafen f = CreateFlughafen(i.ToString());
320 ················pm.MakePersistent(f);
321 ················l.AddFlughafen(f);
322 ············}
323 ············pm.Save();
324 ············IList ff = new ArrayList(l.Flughäfen);
325 ············l.LöscheFlughäfen();
326 ············Assert.That(0 ==··l.Flughäfen.Count, "1. Wrong number of objects");
327 ············for(int i = 0; i < 10; i++)
328 ············{
329 ················Assert.That(NDOObjectState.PersistentDirty ==··((Flughafen)ff[i]).NDOObjectState, "2. Wrong state");
330 ············}
331 ············pm.Abort();
332 ············Assert.That(10 ==··l.Flughäfen.Count, "3. Wrong number of objects");
333 ············for(int i = 0; i < 10; i++)
334 ············{
335 ················Assert.That(NDOObjectState.Persistent ==··((Flughafen)ff[i]).NDOObjectState, "4. Wrong state");
336 ············}
337 ········}
338
339 ········[Test]
340 ········public void TestAssignRelatedObjectsNullSave()
341 ········{
342 ············pm.MakePersistent(l);
343 ············for(int i = 0; i < 3; i++)
344 ············{
345 ················Flughafen f = CreateFlughafen(i.ToString());
346 ················pm.MakePersistent(f);
347 ················l.AddFlughafen(f);
348 ············}
349 ············pm.Save();
350 ············IList ff = new ArrayList(l.Flughäfen);
351 ············l.ErsetzeFlughäfen(null);
352 ············Assert.That(l.Flughäfen == null, "Flughäfen should be null");
353 ············for(int i = 0; i < 3; i++)
354 ············{
355 ················Assert.That(NDOObjectState.PersistentDirty ==··((Flughafen)ff[i]).NDOObjectState, "2. Wrong state");
356 ············}
357 ············pm.Save();
358 ············Assert.That(l.Flughäfen == null, "Flughäfen should be null");
359 ············for(int i = 0; i < 3; i++)
360 ············{
361 ················Assert.That(NDOObjectState.Persistent ==··((Flughafen)ff[i]).NDOObjectState, "4. Wrong state");
362 ············}
363 ········}
364
365 ········[Test]
366 ········public void TestAssignRelatedObjectsNullAbort()
367 ········{
368 ············pm.MakePersistent(l);
369 ············for(int i = 0; i < 3; i++)
370 ············{
371 ················Flughafen f = CreateFlughafen(i.ToString());
372 ················pm.MakePersistent(f);
373 ················l.AddFlughafen(f);
374 ············}
375 ············pm.Save();
376 ············IList ff = new ArrayList(l.Flughäfen);
377 ············l.ErsetzeFlughäfen(null);
378 ············Assert.That(l.Flughäfen == null, "No objects should be there");
379 ············for(int i = 0; i < 3; i++)
380 ············{
381 ················Assert.That(NDOObjectState.PersistentDirty ==··((Flughafen)ff[i]).NDOObjectState, "2. Wrong state");
382 ············}
383 ············pm.Abort();
384 ············Assert.That(3 ==··l.Flughäfen.Count, "3. Wrong number of objects");
385 ············for(int i = 0; i < 3; i++)
386 ············{
387 ················Assert.That(NDOObjectState.Persistent ==··((Flughafen)ff[i]).NDOObjectState, "4. Wrong state");
388 ············}
389 ········}
390
391 ········[Test]
392 ········public void TestAssignRelatedObjectsSave()
393 ········{
394 ············pm.MakePersistent(l);
395 ············for(int i = 0; i < 3; i++)
396 ············{
397 ················Flughafen f = CreateFlughafen(i.ToString());
398 ················pm.MakePersistent(f);
399 ················l.AddFlughafen(f);
400 ············}
401 ············pm.Save();
402 ············IList neueFlughäfen = new ArrayList();
403 ············Flughafen nr = CreateFlughafen("Test");
404 ············pm.MakePersistent(nr);
405 ············neueFlughäfen.Add(nr);
406
407 ············IList ff = new ArrayList(l.Flughäfen);
408 ············l.ErsetzeFlughäfen(neueFlughäfen);
409 ············Assert.That(1 ==··l.Flughäfen.Count, "1. Wrong number of objects");
410 ············for(int i = 0; i < 3; i++)
411 ············{
412 ················Assert.That(NDOObjectState.PersistentDirty ==··((Flughafen)ff[i]).NDOObjectState, "2. Wrong state");
413 ············}
414 ············Assert.That(NDOObjectState.Created ==··nr.NDOObjectState, "3. Wrong state");
415
416 ············pm.Save();
417 ············Assert.That(1 ==··l.Flughäfen.Count, "4. Wrong number of objects");
418 ············for(int i = 0; i < 3; i++)
419 ············{
420 ················Assert.That(NDOObjectState.Persistent ==··((Flughafen)ff[i]).NDOObjectState, "5. Wrong state");
421 ············}
422 ············Assert.That(NDOObjectState.Persistent ==··nr.NDOObjectState, "6. Wrong state");
423 ········}
424 /*
425 ········[Test]
426 ········public void TestAssignRelatedObjectsAbort()
427 ········{
428 ············pm.MakePersistent(l);
429 ············for(int i = 0; i < 3; i++)
430 ············{
431 ················Flughafen f = CreateFlughafen(i.ToString);
432 ················pm.MakePersistent(f);
433 ················l.AddFlughafen(f);
434 ············}
435 ············pm.Save();
436 ············IList neueFlughäfen = new ArrayList();
437 ············Flughafen nr = CreateFlughafen("Test");
438 ············neueFlughäfen.Add(nr);
439
440 ············IList ff = new ArrayList(l.Flughäfen);
441 ············l.ErsetzeFlughafenn(neueFlughäfen);
442 ············Assert.That(1 ==··l.Flughäfen.Count, "1. Wrong number of objects");
443 ············for(int i = 0; i < 3; i++)
444 ············{
445 ················Assert.That(NDOObjectState.Deleted ==··((Flughafen)ff[i]).NDOObjectState, "2. Wrong state");
446 ············}
447 ············Assert.That(NDOObjectState.Created ==··nr.NDOObjectState, "3. Wrong state");
448
449 ············pm.Abort();
450 ············Assert.That(3 ==··l.Flughäfen.Count, "4. Wrong number of objects");
451 ············for(int i = 0; i < 3; i++)
452 ············{
453 ················Assert.That(NDOObjectState.Persistent ==··((Flughafen)ff[i]).NDOObjectState, "5. Wrong state");
454 ············}
455 ············Assert.That(NDOObjectState.Transient ==··nr.NDOObjectState, "6. Wrong state");
456 ········}
457
458
459 ········[Test]
460 ········public void TestHollow()
461 ········{
462 ············pm.MakePersistent(l);
463 ············pm.MakePersistent(f);
464 ············l.AddFlughafen(f);
465 ············pm.Save();
466 ············pm.MakeHollow(l);
467 ············Assert.That(NDOObjectState.Hollow ==··l.NDOObjectState, "1: Land should be hollow");
468 ············Assert.That(NDOObjectState.Persistent ==··f.NDOObjectState, "1: Flughafen should be persistent");
469 ············IList Flughafen = l.Flughäfen;
470
471 ············pm.MakeHollow(l, true);
472 ············Assert.That(NDOObjectState.Hollow ==··l.NDOObjectState, "2: Land should be hollow");
473 ············Assert.That(NDOObjectState.Hollow ==··f.NDOObjectState, "2: Flughafen should be hollow");
474
475 ············Flughafen = l.Flughäfen;
476 ············Assert.That(NDOObjectState.Persistent ==··l.NDOObjectState, "3: Land should be persistent");
477 ············Assert.That(NDOObjectState.Hollow ==··f.NDOObjectState, "3: Flughafen should be hollow");
478 ············Assert.That("ADC" ==··f.Zweck, "3: Flughafen should have correct Zweck");
479 ············Assert.That(NDOObjectState.Persistent ==··f.NDOObjectState, "4: Flughafen should be persistent");
480 ········}
481
482 ········[Test]
483 ········public void··TestMakeAllHollow()
484 ········{
485 ············pm.MakePersistent(l);
486 ············pm.MakePersistent(m);
487 ············l.AddFlughafen(f);
488 ············pm.Save();
489 ············pm.MakeAllHollow();
490 ············Assert.That(NDOObjectState.Hollow ==··l.NDOObjectState, "1: Land should be hollow");
491 ············Assert.That(NDOObjectState.Hollow ==··f.NDOObjectState, "1: Flughafen should be hollow");
492 ············pm.UnloadCache();
493 ········}
494
495 ········[Test]
496 ········public void··TestMakeAllHollowUnsaved()
497 ········{
498 ············pm.MakePersistent(l);
499 ············pm.MakePersistent(f);
500 ············l.AddFlughafen(f);
501 ············pm.MakeAllHollow();··// before save, objects cannot be made hollow. => in locked objects
502 ············Assert.That(NDOObjectState.Created ==··l.NDOObjectState, "1: Land should be created");
503 ············Assert.That(NDOObjectState.Created ==··f.NDOObjectState, "1: Flughafen should be created");
504 ········}
505
506 ········[Test]
507 ········public void TestLoadRelatedObjects()
508 ········{
509 ············IQuery q = new NDOQuery<Land>(pm, null);
510 ············IList dellist = q.Execute();
511 ············pm.Delete(dellist);
512 ············pm.Save();
513 ············pm.UnloadCache();
514
515 ············for(int i = 0; i < 10; i++)
516 ············{
517 ················Flughafen f = CreateFlughafen(i.ToString());
518 ················pm.MakePersistent(f);
519 ················l.AddFlughafen(f);
520 ············}
521 ············pm.MakePersistent(l);
522 ············pm.Save();
523 ············pm.MakeHollow(l, true);
524
525 ············IList Flughafenn = new ArrayList(l.Flughäfen);
526 ············Assert.That(10 ==··Flughafenn.Count, "Array size should be 10");
527
528 ············for(int i = 0; i < 10; i++)
529 ············{
530 ················Flughafen ff = (Flughafen)Flughafenn[i];
531 ················Assert.That(NDOObjectState.Hollow ==··ff.NDOObjectState, "1: Flughafen should be hollow");
532 ················//················if (i.ToString()!= ff.Zweck)
533 ················//················{
534 ················//····················for (int j = 0; j < 10; j++)
535 ················//························System.Diagnostics.Debug.WriteLine("Flughafen: " + ((Flughafen)Flughafenn[j]).Zweck);
536 ················//················}
537 #if !ORACLE && !MYSQL && !FIREBIRD
538 ················if (ff.NDOObjectId.Id[0] is Int32)
539 ····················Assert.That(i.ToString() ==··ff.Zweck, "2: Flughafen should be in right order");
540 #endif
541 ············}
542
543
544 ············pm.MakeAllHollow();
545 ············pm.UnloadCache();
546 ············IList Flughafenn2 = l.Flughäfen;
547 ············for(int i = 0; i < 10; i++)
548 ············{
549 ················Flughafen r1 = (Flughafen)Flughafenn[i];
550 ················Flughafen r2 = (Flughafen)Flughafenn2[i];
551 #if !ORACLE && !MYSQL && !FIREBIRD
552 ················if (r1.NDOObjectId.Id[0] is Int32)
553 ····················Assert.That(i.ToString() ==··r1.Zweck, "3: Flughafen should be in right order");
554 #endif
555 ················Assert.That(r1 !=··r2, "Objects should be different");
556 ············}
557 ········}
558
559 ········[Test]
560 ········public void TestLoadRelatedObjectsSave()
561 ········{
562 ············pm.MakePersistent(l);
563 ············pm.Save();
564 ············for(int i = 0; i < 10; i++)
565 ············{
566 ················Flughafen f = CreateFlughafen(i.ToString());
567 ················pm.MakePersistent(f);
568 ················l.AddFlughafen(f);
569 ············}
570 ············pm.Save();
571 ············pm.MakeHollow(l, true);
572
573 ············IList Flughafenn = new ArrayList(l.Flughäfen);
574
575 ············for(int i = 0; i < 10; i++)
576 ············{
577 ················Flughafen ff = (Flughafen)Flughafenn[i];
578 ················Assert.That(NDOObjectState.Hollow ==··ff.NDOObjectState, "1: Flughafen should be hollow");
579 #if !ORACLE && !MYSQL && !FIREBIRD
580 ················if (ff.NDOObjectId.Id[0] is Int32)
581 ····················Assert.That(i.ToString() ==··ff.Zweck, "2: Flughafen should be in right order");
582 #endif
583 ············}
584
585
586 ············pm.MakeAllHollow();
587 ············pm.UnloadCache();
588 ············IList Flughafenn2 = l.Flughäfen;
589 ············for(int i = 0; i < 10; i++)
590 ············{
591 ················Flughafen r1 = (Flughafen)Flughafenn[i];
592 ················Flughafen r2 = (Flughafen)Flughafenn2[i];
593 #if !ORACLE && !MYSQL && !FIREBIRD
594 ················if (r1.NDOObjectId.Id[0] is Int32)
595 ····················Assert.That(i.ToString() ==··r1.Zweck, "3: Flughafen should be in right order");
596 #endif
597 ················Assert.That(r1 !=··r2, "Objects should be different");
598 ············}
599 ········}
600
601 ········[Test]
602 ········public void TestExtentRelatedObjects()
603 ········{
604 ············pm.MakePersistent(l);
605 ············pm.MakePersistent(f);
606 ············l.AddFlughafen(f);
607 ············pm.Save();
608 ············IList liste = pm.GetClassExtent(typeof(Land));
609 ············l = (Land)liste[0];
610 ············Assert.That(NDOObjectState.Persistent ==··l.NDOObjectState, "1: Land should be persistent");
611 ············Assert.That(l.Flughäfen != null, "2. Relation is missing");
612 ············Assert.That(1 ==··l.Flughäfen.Count, "3. Wrong number of objects");
613 ············Assert.That(NDOObjectState.Persistent ==··((Flughafen)l.Flughäfen[0]).NDOObjectState, "4.: Flughafen should be hollow");
614
615 ············pm.UnloadCache();
616 ············liste = pm.GetClassExtent(typeof(Land));
617 ············l = (Land)liste[0];
618 ············Assert.That(NDOObjectState.Hollow ==··l.NDOObjectState, "5: Land should be hollow");
619 ············Assert.That(l.Flughäfen != null, "6. Relation is missing");
620 ············Assert.That(1 ==··l.Flughäfen.Count, "7. Wrong number of objects");
621 ············Assert.That(NDOObjectState.Hollow ==··((Flughafen)l.Flughäfen[0]).NDOObjectState, "8.: Flughafen should be hollow");
622
623 ············pm.UnloadCache();
624 ············liste = pm.GetClassExtent(typeof(Land), false);
625 ············l = (Land)liste[0];
626 ············Assert.That(NDOObjectState.Persistent ==··l.NDOObjectState, "9: Land should be persistent");
627 ············Assert.That(l.Flughäfen != null, "10. Relation is missing");
628 ············Assert.That(1 ==··l.Flughäfen.Count, "11. Wrong number of objects");
629 ············Assert.That(NDOObjectState.Hollow ==··((Flughafen)l.Flughäfen[0]).NDOObjectState, "12.: Flughafen should be hollow");
630 ········}
631
632 ········[Test]
633 ········public void RelationEmptyAssignment()
634 ········{
635 ············pm.MakePersistent(l);
636 ············pm.MakePersistent(f);
637 ············l.AddFlughafen(f);
638 ············pm.Save();
639 ············pm.UnloadCache();
640 ············l = (Land) pm.FindObject(l.NDOObjectId);
641 ············//Assert.That(l.Flughäfen.Count == 1);
642 ············l.ErsetzeFlughafenn(new ArrayList());
643 ············pm.Save();
644 ············pm.UnloadCache();
645 ············l = (Land) pm.FindObject(l.NDOObjectId);
646 Assert.That(l.Flughäfen == null, "Flughafenn should be null");
647 ············Assert.That(l.Flughäfen.Count == 0, "Flughafenn should be empty");
648 ········}
649
650 ········[Test]
651 ········public void RelationNullAssignment()
652 ········{
653 ············pm.MakePersistent(l);
654 ············pm.MakePersistent(f);
655 ············l.AddFlughafen(f);
656 ············pm.Save();
657 ············pm.UnloadCache();
658 ············l = (Land) pm.FindObject(l.NDOObjectId);
659 ············//Assert.That(l.Flughäfen.Count == 1);
660 ············l.ErsetzeFlughafenn(null);
661 ············pm.Save();
662 ············pm.UnloadCache();
663 ············l = (Land) pm.FindObject(l.NDOObjectId);
664 Assert.That(l.Flughäfen == null, "Flughafenn should be null");
665 ············Assert.That(l.Flughäfen.Count == 0, "Flughafenn should be empty");
666 ········}
667
668 #if !MYSQL
669 ········[Test]
670 ········public void AbortedTransaction()
671 ········{
672 ············pm.MakePersistent(l);
673 ············pm.MakePersistent(f);
674 ············l.AddFlughafen(f);
675 ············pm.Save();
676 ············pm.UnloadCache();
677
678 ············pm.TransactionMode = TransactionMode.Optimistic;
679
680 ············IQuery q = new NDOQuery<Land>(pm, null);
681 ············l = (Land) q.ExecuteSingle(true);
682 ············l.Vorname = "Hans";
683 ············((Flughafen)l.Flughäfen[0]).Zweck = "Neuer Zweck";
684
685 ············FieldInfo fi = pm.NDOMapping.GetType().GetField("persistenceHandler", BindingFlags.Instance | BindingFlags.NonPublic);
686 ············Hashtable ht = (Hashtable) fi.GetValue(pm.NDOMapping);
687 ············ht.Clear();
688 ············pm.NDOMapping.FindClass(typeof(Flughafen)).FindField("zweck").ColumnName = "nix";
689 ············
690 ············try
691 ············{
692 ················pm.Save();
693 ············}
694 ············catch
695 ············{
696 ················ht.Clear();
697 ················pm.NDOMapping.FindClass(typeof(Flughafen)).FindField("zweck").ColumnName = "Zweck";
698 ················pm.Abort();
699 ············}
700 ············pm.UnloadCache();
701 ············l = (Land) q.ExecuteSingle(true);
702 ············Assert.That("Hartmut" ==··l.Vorname, "Vorname falsch");
703 ············Assert.That("ADC" ==··((Flughafen)l.Flughäfen[0]).Zweck, "Vorname falsch");
704 ············
705 ········}
706 #endif
707
708 ········[Test]
709 ········public void TestListEnumerator()
710 ········{
711 ············pm.MakePersistent(l);
712 ············pm.MakePersistent(f);
713 ············l.AddFlughafen(f);
714 ············pm.Save();
715 ············pm.UnloadCache();
716 ············IQuery q = new NDOQuery<Land>(pm, null);
717 ············l = (Land) q.ExecuteSingle(true);
718 ············IEnumerator ie = l.Flughäfen.GetEnumerator();
719 ············bool result = ie.MoveNext();
720 ············Assert.That(result, "Enumerator should give a result");
721 ············Assert.That(ie.Current != null);
722 ········}
723 */
724
725 ········[Test]
726 ········public void TestListCount()
727 ········{
728 ············pm.MakePersistent(l);
729 ············pm.MakePersistent(f);
730 ············l.AddFlughafen(f);
731 ············pm.Save();
732 ············pm.UnloadCache();
733 ············IQuery q = new NDOQuery<Land>(pm, null);
734 ············l = (Land) q.ExecuteSingle(true);
735 ············Assert.That(1 ==··l.Flughäfen.Count, "Count should be 1");
736 ········}
737
738
739 ········[Test]
740 ········public void TestAddFlughafen()
741 ········{
742 ············pm.MakePersistent(l);
743 ············pm.MakePersistent(f);
744 ············l.AddFlughafen(f);
745 ············pm.Save();
746 ············pm.UnloadCache();
747 ············IQuery q = new NDOQuery<Land>(pm, null);
748 ············l = (Land) q.ExecuteSingle(true);
749 ············Assert.That(l != null, "Land not found");
750 ············Assert.That(1 ==··l.Flughäfen.Count, "Count wrong");
751 ············Flughafen f2 = CreateFlughafen("FRA");
752 ············pm.MakePersistent(f2);
753 ············l.AddFlughafen(f2);
754 ············pm.Save();
755 ············pm.UnloadCache();
756 ············l = (Land) q.ExecuteSingle(true);
757 ············Assert.That(2 ==··l.Flughäfen.Count, "Count wrong");
758 ········}
759
760 ········public void TestAddFlughafen2()
761 ········{
762 ············pm.MakePersistent(l);
763 ············pm.MakePersistent(f);
764 ············pm.Save();
765 ············l.AddFlughafen(f);
766 ············pm.Save();
767 ············pm.UnloadCache();
768 ············l = (Land) pm.FindObject(l.NDOObjectId);
769 ············Assert.That(1 ==··l.Flughäfen.Count, "Count wrong");
770 ········}
771
772 ········[Test]
773 ········public void TestRelatedObject()
774 ········{
775 ············pm.MakePersistent(l);
776 ············pm.MakePersistent(f);
777 ············l.AddFlughafen(f);
778 ············pm.Save();
779 ············pm.MakeHollow(f);
780 ············f.Kürzel = "XXX";
781 ············pm.Save();··// Bug would overwrite foreign key in database.
782 ············Assert.That("XXX" ==··f.Kürzel, "Kürzel should be changed");
783 ············ObjectId id = l.NDOObjectId;
784 ············pm.UnloadCache();
785 ············l = (Land) pm.FindObject(id);
786 ············Assert.That(1 ==··l.Flughäfen.Count, "Number of children");
787 ········}
788
789 ········private Land CreateLand(string name)
790 ········{
791 ············Land l = new Land();
792 ············l.Name = name;
793 ············return l;
794 ········}
795
796 ········private Flughafen CreateFlughafen(string name)
797 ········{
798 ············Flughafen f = new Flughafen();
799 ············f.Kürzel = name;
800 ············return f;
801 ········}
802 ····}
803 }
804
New Commit (60aa080)
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.Diagnostics;
25 using System.Reflection;
26 using System.Collections;
27 using NUnit.Framework;
28 using NDO;
29 using NDO.Query;
30 using Reisekosten;
31
32 namespace NdoUnitTests
33 {
34 ····/// <summary>
35 ····/// Combined Tests of Land and Flughafen to test uniqueness of object ids.
36 ····/// </summary>
37 ····[TestFixture]
38 public class LandFlughafenTests : NDOTest
39 ····{
40 ········public LandFlughafenTests()
41 ········{
42 ········}
43
44 ········private PersistenceManager pm;
45 ········private Land l;
46 ········private Flughafen f;
47
48 ········[SetUp]
49 ········public void Setup()
50 ········{
51 ············pm = PmFactory.NewPersistenceManager();
52 ············l = CreateLand("Deutschland");
53 ············f = CreateFlughafen("MUC");
54 ········}
55
56 ········[TearDown]
57 ········public void TearDown()
58 ········{
59 ············pm.Abort();
60 ············IList l = pm.GetClassExtent(typeof(Land));
61 ············pm.Delete(l);
62 ············l = pm.GetClassExtent(typeof(Flughafen));
63 ············pm.Delete(l);
64 ············pm.Save();
65 ············pm.Close();
66 ········}
67
68 ········[Test]
69 ········public void TestCreateObjects()
70 ········{
71 ············pm.MakePersistent(l);
72 ············pm.MakePersistent(f);
73 ············if (!pm.HasOwnerCreatedIds)
74 ············{
75 ················if (l.NDOObjectId.Id[0] is Int32)
76 ····················Assert.That(-1 == (int) l.NDOObjectId.Id[0], "Land key wrong");
77 ················if (f.NDOObjectId.Id[0] is Int32)
78 ····················Assert.That(-1 == (int) f.NDOObjectId.Id[0], "Flughafen key wrong");
79 ············}
80 ············Assert.That(!l.NDOObjectId.Equals(f.NDOObjectId), "Ids should be different");
81 ············l = (Land)pm.FindObject(l.NDOObjectId);
82 ············f = (Flughafen)pm.FindObject(f.NDOObjectId);
83 ········}
84
85 ········[Test]
86 ········public void TestCreateObjectsSave()
87 ········{
88 ············
89 ············pm.MakePersistent(l);
90 ············pm.MakePersistent(f);
91 ············l.AddFlughafen(f);
92 ············pm.Save();
93 ············Assert.That(!l.NDOObjectId.Equals(f.NDOObjectId), "Ids should be different");
94 ············l = (Land)pm.FindObject(l.NDOObjectId);
95 ············f = (Flughafen)pm.FindObject(f.NDOObjectId);
96 ············Assert.That(l != null, "1. Land not found");
97 ············Assert.That(f != null, "1. Flughafen not found");
98
99 ············pm.UnloadCache();
100 ············l = (Land)pm.FindObject(l.NDOObjectId);
101 ············f = (Flughafen)pm.FindObject(f.NDOObjectId);
102 ············Assert.That(l != null, "2. Land not found");
103 ············Assert.That(f != null, "2. Flughafen not found");
104 ········}
105
106 ········[Test]
107 ········public void TestCreateObjectsSaveReload()
108 ········{
109
110 ············pm.MakePersistent( l );
111 ············pm.MakePersistent( f );
112 ············l.AddFlughafen( f );
113 ············pm.Save();
114 ············pm.UnloadCache();
115 ············Land l2 = new NDOQuery<Land>(pm).ExecuteSingle();
116 ············Assert.That(l2··!= null);
117 ············Assert.That(1 ==··l.Flughäfen.Count, "1. Wrong number of objects" );
118 ········}
119
120 ········[Test]
121 ········public void TestAddObjectSave()
122 ········{
123 ············pm.MakePersistent(l);
124 ············pm.Save();
125 ············pm.MakePersistent(f);
126 ············l.AddFlughafen(f);
127 ············Assert.That(NDOObjectState.Created ==··f.NDOObjectState, "1. Wrong state");
128 ············pm.Save();
129 ············l = (Land)pm.FindObject(l.NDOObjectId);
130 ············f = (Flughafen)pm.FindObject(f.NDOObjectId);
131 ············Assert.That(l != null, "1. Land not found");
132 ············Assert.That(f != null, "1. Flughafen not found");
133 ············Assert.That(NDOObjectState.Persistent ==··f.NDOObjectState, "2. Wrong state");
134 ········}
135 ············
136 ········[Test]
137 ········public void TestAddObjectAbort()
138 ········{
139 ············pm.MakePersistent(l);
140 ············pm.Save();
141 ············pm.MakePersistent(f);
142 ············l.AddFlughafen(f);
143 ············Assert.That(NDOObjectState.Created ==··f.NDOObjectState, "1. Wrong state");
144 ············Assert.That(1 ==··l.Flughäfen.Count, "1. Wrong number of objects");
145 ············pm.Abort();
146 ············Assert.That(NDOObjectState.Transient ==··f.NDOObjectState, "2. Wrong state");
147 ············Assert.That(0 ==··l.Flughäfen.Count, "2. Wrong number of objects");
148 ········}
149
150 ········[Test]
151 ········public void TestRemoveObjectSave()
152 ········{
153 ············pm.MakePersistent(l);
154 ············pm.MakePersistent(f);
155 ············l.AddFlughafen(f);
156 ············pm.Save();
157 ············Assert.That(1 ==··l.Flughäfen.Count, "1. Wrong number of objects");
158 ············l.RemoveFlughafen(f);
159 ············// f keeps the foreign key - so it get's dirty
160 ············Assert.That(NDOObjectState.PersistentDirty ==··f.NDOObjectState, "1. Wrong state");
161 ············Assert.That(0 ==··l.Flughäfen.Count, "2. Wrong number of objects");
162 ············pm.Save();
163 ············Assert.That(0 ==··l.Flughäfen.Count, "3. Wrong number of objects");
164 ············Assert.That(NDOObjectState.Persistent ==··f.NDOObjectState, "2. Wrong state");
165 ········}
166
167 ········[Test]
168 ········public void TestRemoveObjectSaveReload()
169 ········{
170 ············pm.MakePersistent( l );
171 ············pm.MakePersistent( f );
172 ············l.AddFlughafen( f );
173 ············pm.Save();
174 ············pm.UnloadCache();
175 ············NDOQuery<Land> q = new NDOQuery<Land>( pm );
176 ············l = q.ExecuteSingle(true);
177 ············Assert.That(NDOObjectState.Persistent ==··l.NDOObjectState, "1. Wrong state");
178 ············Assert.That(1 ==··l.Flughäfen.Count, "1. Wrong number of objects");
179 ············f = (Flughafen) l.Flughäfen[0];
180 ············l.RemoveFlughafen(f);
181 ············// f keeps the foreign key - so it get's dirty
182 ············Assert.That(NDOObjectState.PersistentDirty ==··f.NDOObjectState, "2. Wrong state");
183 ············Assert.That(0 ==··l.Flughäfen.Count, "2. Wrong number of objects");
184 ············pm.Save();
185 ············l = (Land) q.ExecuteSingle(true);
186 ············pm.UnloadCache();
187 ············Assert.That(0 ==··l.Flughäfen.Count, "3. Wrong number of objects");
188 ········}
189
190 ········[Test]
191 ········public void TestRemoveObjectSaveReloadNonHollow()
192 ········{
193 ············pm.MakePersistent(l);
194 ············pm.MakePersistent(f);
195 ············l.AddFlughafen(f);
196 ············pm.Save();
197 ············pm.UnloadCache();
198 ············IQuery q = new NDOQuery<Land>(pm, null, false);
199 ············l = (Land) q.ExecuteSingle(true);
200 ············Assert.That(NDOObjectState.Persistent ==··l.NDOObjectState, "1. Wrong state");
201 ············Assert.That(1 ==··l.Flughäfen.Count, "1. Wrong number of objects");
202 ············f = (Flughafen) l.Flughäfen[0];
203 ············l.RemoveFlughafen(f);
204 ············// f keeps the foreign key - so it get's dirty
205 ············Assert.That(NDOObjectState.PersistentDirty ==··f.NDOObjectState, "2. Wrong state");
206 ············Assert.That(0 ==··l.Flughäfen.Count, "2. Wrong number of objects");
207 ············pm.Save();
208 ············l = (Land) q.ExecuteSingle(true);
209 ············pm.UnloadCache();
210 ············Assert.That(0 ==··l.Flughäfen.Count, "3. Wrong number of objects");
211 ········}
212
213 ········[Test]
214 ········public void TestRemoveObjectAbort()
215 ········{
216 ············pm.MakePersistent(l);
217 ············pm.MakePersistent(f);
218 ············l.AddFlughafen(f);
219 ············pm.Save();
220 ············Assert.That(1 ==··l.Flughäfen.Count, "1. Wrong number of objects");
221 ············l.RemoveFlughafen(f);
222 ············Assert.That(NDOObjectState.PersistentDirty ==··f.NDOObjectState, "1. Wrong state");
223 ············Assert.That(0 ==··l.Flughäfen.Count, "2. Wrong number of objects");
224 ············pm.Abort();
225 ············Assert.That(1 ==··l.Flughäfen.Count, "3. Wrong number of objects");
226 ············Assert.That(NDOObjectState.Persistent ==··f.NDOObjectState, "2. Wrong state");
227 ········}
228
229 ········[Test]
230 ········public void TestDeleteSave()
231 ········{
232 ············pm.MakePersistent(l);
233 ············pm.MakePersistent(f);
234 ············l.AddFlughafen(f);
235 ············pm.Save();
236 ············pm.Delete(l); // sollte Exception geben
237 ············Assert.That(NDOObjectState.Deleted ==··l.NDOObjectState, "1. Wrong state");
238 ············Assert.That(NDOObjectState.PersistentDirty ==··f.NDOObjectState, "2. Wrong state");
239 ············pm.Save();
240 ············Assert.That(NDOObjectState.Transient ==··l.NDOObjectState, "1. Wrong state");
241 ············Assert.That(NDOObjectState.Persistent ==··f.NDOObjectState, "2. Wrong state");
242 ········}
243
244
245
246 ········[Test]
247 ········public void TestDeleteAbort()
248 ········{
249 ············pm.MakePersistent(l);
250 ············pm.MakePersistent(f);
251 ············l.AddFlughafen(f);
252 ············pm.Save();
253 ············pm.Delete(l);··// sollte Exception geben
254 ············Assert.That(NDOObjectState.Deleted ==··l.NDOObjectState, "1. Wrong state");
255 ············Assert.That(NDOObjectState.PersistentDirty ==··f.NDOObjectState, "2. Wrong state");
256 ············pm.Abort();
257 ············Assert.That(NDOObjectState.Persistent ==··l.NDOObjectState, "1. Wrong state");
258 ············Assert.That(NDOObjectState.Persistent ==··f.NDOObjectState, "2. Wrong state");
259 ········}
260
261 ········[Test]
262 ········public void TestAddRemoveSave()
263 ········{
264 ············pm.MakePersistent(l);
265 ············pm.Save();
266 ············pm.MakePersistent(f);
267 ············l.AddFlughafen(f);
268 ············l.RemoveFlughafen(f);
269 ············Assert.That(NDOObjectState.Created ==··f.NDOObjectState, "1. Wrong state");
270 ············pm.Save();
271 ············Assert.That(NDOObjectState.Persistent ==··f.NDOObjectState, "2. Wrong state");
272 ········}
273
274 ········[Test]
275 ········public void TestAddRemoveAbort()
276 ········{
277 ············pm.MakePersistent(l);
278 ············pm.Save();
279 ············pm.MakePersistent(f);
280 ············l.AddFlughafen(f);
281 ············l.RemoveFlughafen(f);
282 ············Assert.That(NDOObjectState.Created ==··f.NDOObjectState, "1. Wrong state");
283 ············pm.Abort();
284 ············Assert.That(NDOObjectState.Transient ==··f.NDOObjectState, "2. Wrong state");
285 ········}
286
287 ········[Test]
288 ········public void TestClearRelatedObjectsSave()
289 ········{
290 ············pm.MakePersistent(l);
291 ············for(int i = 0; i < 10; i++)
292 ············{
293 ················Flughafen f = CreateFlughafen(i.ToString());
294 ················pm.MakePersistent(f);
295 ················l.AddFlughafen(f);
296 ············}
297 ············pm.Save();
298 ············IList ff = new ArrayList(l.Flughäfen);
299 ············l.LöscheFlughäfen();
300 ············Assert.That(0 ==··l.Flughäfen.Count, "1. Wrong number of objects");
301 ············for(int i = 0; i < 10; i++)
302 ············{
303 ················Assert.That(NDOObjectState.PersistentDirty ==··((Flughafen)ff[i]).NDOObjectState, "2. Wrong state");
304 ············}
305 ············pm.Save();
306 ············Assert.That(0 ==··l.Flughäfen.Count, "3. Wrong number of objects");
307 ············for(int i = 0; i < 10; i++)
308 ············{
309 ················Assert.That(NDOObjectState.Persistent ==··((Flughafen)ff[i]).NDOObjectState, "4. Wrong state");
310 ············}
311 ········}
312
313 ········[Test]
314 ········public void TestClearRelatedObjectsAbort()
315 ········{
316 ············pm.MakePersistent(l);
317 ············for(int i = 0; i < 10; i++)
318 ············{
319 ················Flughafen f = CreateFlughafen(i.ToString());
320 ················pm.MakePersistent(f);
321 ················l.AddFlughafen(f);
322 ············}
323 ············pm.Save();
324 ············IList ff = new ArrayList(l.Flughäfen);
325 ············l.LöscheFlughäfen();
326 ············Assert.That(0 ==··l.Flughäfen.Count, "1. Wrong number of objects");
327 ············for(int i = 0; i < 10; i++)
328 ············{
329 ················Assert.That(NDOObjectState.PersistentDirty ==··((Flughafen)ff[i]).NDOObjectState, "2. Wrong state");
330 ············}
331 ············pm.Abort();
332 ············Assert.That(10 ==··l.Flughäfen.Count, "3. Wrong number of objects");
333 ············for(int i = 0; i < 10; i++)
334 ············{
335 ················Assert.That(NDOObjectState.Persistent ==··((Flughafen)ff[i]).NDOObjectState, "4. Wrong state");
336 ············}
337 ········}
338
339 ········[Test]
340 ········public void TestAssignRelatedObjectsNullSave()
341 ········{
342 ············pm.MakePersistent(l);
343 ············for(int i = 0; i < 3; i++)
344 ············{
345 ················Flughafen f = CreateFlughafen(i.ToString());
346 ················pm.MakePersistent(f);
347 ················l.AddFlughafen(f);
348 ············}
349 ············pm.Save();
350 ············IList ff = new ArrayList(l.Flughäfen);
351 ············l.ErsetzeFlughäfen(null);
352 ············Assert.That(l.Flughäfen == null, "Flughäfen should be null");
353 ············for(int i = 0; i < 3; i++)
354 ············{
355 ················Assert.That(NDOObjectState.PersistentDirty ==··((Flughafen)ff[i]).NDOObjectState, "2. Wrong state");
356 ············}
357 ············pm.Save();
358 ············Assert.That(l.Flughäfen == null, "Flughäfen should be null");
359 ············for(int i = 0; i < 3; i++)
360 ············{
361 ················Assert.That(NDOObjectState.Persistent ==··((Flughafen)ff[i]).NDOObjectState, "4. Wrong state");
362 ············}
363 ········}
364
365 ········[Test]
366 ········public void TestAssignRelatedObjectsNullAbort()
367 ········{
368 ············pm.MakePersistent(l);
369 ············for(int i = 0; i < 3; i++)
370 ············{
371 ················Flughafen f = CreateFlughafen(i.ToString());
372 ················pm.MakePersistent(f);
373 ················l.AddFlughafen(f);
374 ············}
375 ············pm.Save();
376 ············IList ff = new ArrayList(l.Flughäfen);
377 ············l.ErsetzeFlughäfen(null);
378 ············Assert.That(l.Flughäfen == null, "No objects should be there");
379 ············for(int i = 0; i < 3; i++)
380 ············{
381 ················Assert.That(NDOObjectState.PersistentDirty ==··((Flughafen)ff[i]).NDOObjectState, "2. Wrong state");
382 ············}
383 ············pm.Abort();
384 ············Assert.That(3 ==··l.Flughäfen.Count, "3. Wrong number of objects");
385 ············for(int i = 0; i < 3; i++)
386 ············{
387 ················Assert.That(NDOObjectState.Persistent ==··((Flughafen)ff[i]).NDOObjectState, "4. Wrong state");
388 ············}
389 ········}
390
391 ········[Test]
392 ········public void TestAssignRelatedObjectsSave()
393 ········{
394 ············pm.MakePersistent(l);
395 ············for(int i = 0; i < 3; i++)
396 ············{
397 ················Flughafen f = CreateFlughafen(i.ToString());
398 ················pm.MakePersistent(f);
399 ················l.AddFlughafen(f);
400 ············}
401 ············pm.Save();
402 ············IList neueFlughäfen = new ArrayList();
403 ············Flughafen nr = CreateFlughafen("Test");
404 ············pm.MakePersistent(nr);
405 ············neueFlughäfen.Add(nr);
406
407 ············IList ff = new ArrayList(l.Flughäfen);
408 ············l.ErsetzeFlughäfen(neueFlughäfen);
409 ············Assert.That(1 ==··l.Flughäfen.Count, "1. Wrong number of objects");
410 ············for(int i = 0; i < 3; i++)
411 ············{
412 ················Assert.That(NDOObjectState.PersistentDirty ==··((Flughafen)ff[i]).NDOObjectState, "2. Wrong state");
413 ············}
414 ············Assert.That(NDOObjectState.Created ==··nr.NDOObjectState, "3. Wrong state");
415
416 ············pm.Save();
417 ············Assert.That(1 ==··l.Flughäfen.Count, "4. Wrong number of objects");
418 ············for(int i = 0; i < 3; i++)
419 ············{
420 ················Assert.That(NDOObjectState.Persistent ==··((Flughafen)ff[i]).NDOObjectState, "5. Wrong state");
421 ············}
422 ············Assert.That(NDOObjectState.Persistent ==··nr.NDOObjectState, "6. Wrong state");
423 ········}
424 /*
425 ········[Test]
426 ········public void TestAssignRelatedObjectsAbort()
427 ········{
428 ············pm.MakePersistent(l);
429 ············for(int i = 0; i < 3; i++)
430 ············{
431 ················Flughafen f = CreateFlughafen(i.ToString);
432 ················pm.MakePersistent(f);
433 ················l.AddFlughafen(f);
434 ············}
435 ············pm.Save();
436 ············IList neueFlughäfen = new ArrayList();
437 ············Flughafen nr = CreateFlughafen("Test");
438 ············neueFlughäfen.Add(nr);
439
440 ············IList ff = new ArrayList(l.Flughäfen);
441 ············l.ErsetzeFlughafenn(neueFlughäfen);
442 ············Assert.That(1 ==··l.Flughäfen.Count, "1. Wrong number of objects");
443 ············for(int i = 0; i < 3; i++)
444 ············{
445 ················Assert.That(NDOObjectState.Deleted ==··((Flughafen)ff[i]).NDOObjectState, "2. Wrong state");
446 ············}
447 ············Assert.That(NDOObjectState.Created ==··nr.NDOObjectState, "3. Wrong state");
448
449 ············pm.Abort();
450 ············Assert.That(3 ==··l.Flughäfen.Count, "4. Wrong number of objects");
451 ············for(int i = 0; i < 3; i++)
452 ············{
453 ················Assert.That(NDOObjectState.Persistent ==··((Flughafen)ff[i]).NDOObjectState, "5. Wrong state");
454 ············}
455 ············Assert.That(NDOObjectState.Transient ==··nr.NDOObjectState, "6. Wrong state");
456 ········}
457
458
459 ········[Test]
460 ········public void TestHollow()
461 ········{
462 ············pm.MakePersistent(l);
463 ············pm.MakePersistent(f);
464 ············l.AddFlughafen(f);
465 ············pm.Save();
466 ············pm.MakeHollow(l);
467 ············Assert.That(NDOObjectState.Hollow ==··l.NDOObjectState, "1: Land should be hollow");
468 ············Assert.That(NDOObjectState.Persistent ==··f.NDOObjectState, "1: Flughafen should be persistent");
469 ············IList Flughafen = l.Flughäfen;
470
471 ············pm.MakeHollow(l, true);
472 ············Assert.That(NDOObjectState.Hollow ==··l.NDOObjectState, "2: Land should be hollow");
473 ············Assert.That(NDOObjectState.Hollow ==··f.NDOObjectState, "2: Flughafen should be hollow");
474
475 ············Flughafen = l.Flughäfen;
476 ············Assert.That(NDOObjectState.Persistent ==··l.NDOObjectState, "3: Land should be persistent");
477 ············Assert.That(NDOObjectState.Hollow ==··f.NDOObjectState, "3: Flughafen should be hollow");
478 ············Assert.That("ADC" ==··f.Zweck, "3: Flughafen should have correct Zweck");
479 ············Assert.That(NDOObjectState.Persistent ==··f.NDOObjectState, "4: Flughafen should be persistent");
480 ········}
481
482 ········[Test]
483 ········public void··TestMakeAllHollow()
484 ········{
485 ············pm.MakePersistent(l);
486 ············pm.MakePersistent(m);
487 ············l.AddFlughafen(f);
488 ············pm.Save();
489 ············pm.MakeAllHollow();
490 ············Assert.That(NDOObjectState.Hollow ==··l.NDOObjectState, "1: Land should be hollow");
491 ············Assert.That(NDOObjectState.Hollow ==··f.NDOObjectState, "1: Flughafen should be hollow");
492 ············pm.UnloadCache();
493 ········}
494
495 ········[Test]
496 ········public void··TestMakeAllHollowUnsaved()
497 ········{
498 ············pm.MakePersistent(l);
499 ············pm.MakePersistent(f);
500 ············l.AddFlughafen(f);
501 ············pm.MakeAllHollow();··// before save, objects cannot be made hollow. => in locked objects
502 ············Assert.That(NDOObjectState.Created ==··l.NDOObjectState, "1: Land should be created");
503 ············Assert.That(NDOObjectState.Created ==··f.NDOObjectState, "1: Flughafen should be created");
504 ········}
505
506 ········[Test]
507 ········public void TestLoadRelatedObjects()
508 ········{
509 ············IQuery q = new NDOQuery<Land>(pm, null);
510 ············IList dellist = q.Execute();
511 ············pm.Delete(dellist);
512 ············pm.Save();
513 ············pm.UnloadCache();
514
515 ············for(int i = 0; i < 10; i++)
516 ············{
517 ················Flughafen f = CreateFlughafen(i.ToString());
518 ················pm.MakePersistent(f);
519 ················l.AddFlughafen(f);
520 ············}
521 ············pm.MakePersistent(l);
522 ············pm.Save();
523 ············pm.MakeHollow(l, true);
524
525 ············IList Flughafenn = new ArrayList(l.Flughäfen);
526 ············Assert.That(10 ==··Flughafenn.Count, "Array size should be 10");
527
528 ············for(int i = 0; i < 10; i++)
529 ············{
530 ················Flughafen ff = (Flughafen)Flughafenn[i];
531 ················Assert.That(NDOObjectState.Hollow ==··ff.NDOObjectState, "1: Flughafen should be hollow");
532 ················//················if (i.ToString()!= ff.Zweck)
533 ················//················{
534 ················//····················for (int j = 0; j < 10; j++)
535 ················//························System.Diagnostics.Debug.WriteLine("Flughafen: " + ((Flughafen)Flughafenn[j]).Zweck);
536 ················//················}
537 #if !ORACLE && !MYSQL && !FIREBIRD
538 ················if (ff.NDOObjectId.Id[0] is Int32)
539 ····················Assert.That(i.ToString() ==··ff.Zweck, "2: Flughafen should be in right order");
540 #endif
541 ············}
542
543
544 ············pm.MakeAllHollow();
545 ············pm.UnloadCache();
546 ············IList Flughafenn2 = l.Flughäfen;
547 ············for(int i = 0; i < 10; i++)
548 ············{
549 ················Flughafen r1 = (Flughafen)Flughafenn[i];
550 ················Flughafen r2 = (Flughafen)Flughafenn2[i];
551 #if !ORACLE && !MYSQL && !FIREBIRD
552 ················if (r1.NDOObjectId.Id[0] is Int32)
553 ····················Assert.That(i.ToString() ==··r1.Zweck, "3: Flughafen should be in right order");
554 #endif
555 ················Assert.That(r1 !=··r2, "Objects should be different");
556 ············}
557 ········}
558
559 ········[Test]
560 ········public void TestLoadRelatedObjectsSave()
561 ········{
562 ············pm.MakePersistent(l);
563 ············pm.Save();
564 ············for(int i = 0; i < 10; i++)
565 ············{
566 ················Flughafen f = CreateFlughafen(i.ToString());
567 ················pm.MakePersistent(f);
568 ················l.AddFlughafen(f);
569 ············}
570 ············pm.Save();
571 ············pm.MakeHollow(l, true);
572
573 ············IList Flughafenn = new ArrayList(l.Flughäfen);
574
575 ············for(int i = 0; i < 10; i++)
576 ············{
577 ················Flughafen ff = (Flughafen)Flughafenn[i];
578 ················Assert.That(NDOObjectState.Hollow ==··ff.NDOObjectState, "1: Flughafen should be hollow");
579 #if !ORACLE && !MYSQL && !FIREBIRD
580 ················if (ff.NDOObjectId.Id[0] is Int32)
581 ····················Assert.That(i.ToString() ==··ff.Zweck, "2: Flughafen should be in right order");
582 #endif
583 ············}
584
585
586 ············pm.MakeAllHollow();
587 ············pm.UnloadCache();
588 ············IList Flughafenn2 = l.Flughäfen;
589 ············for(int i = 0; i < 10; i++)
590 ············{
591 ················Flughafen r1 = (Flughafen)Flughafenn[i];
592 ················Flughafen r2 = (Flughafen)Flughafenn2[i];
593 #if !ORACLE && !MYSQL && !FIREBIRD
594 ················if (r1.NDOObjectId.Id[0] is Int32)
595 ····················Assert.That(i.ToString() ==··r1.Zweck, "3: Flughafen should be in right order");
596 #endif
597 ················Assert.That(r1 !=··r2, "Objects should be different");
598 ············}
599 ········}
600
601 ········[Test]
602 ········public void TestExtentRelatedObjects()
603 ········{
604 ············pm.MakePersistent(l);
605 ············pm.MakePersistent(f);
606 ············l.AddFlughafen(f);
607 ············pm.Save();
608 ············IList liste = pm.GetClassExtent(typeof(Land));
609 ············l = (Land)liste[0];
610 ············Assert.That(NDOObjectState.Persistent ==··l.NDOObjectState, "1: Land should be persistent");
611 ············Assert.That(l.Flughäfen != null, "2. Relation is missing");
612 ············Assert.That(1 ==··l.Flughäfen.Count, "3. Wrong number of objects");
613 ············Assert.That(NDOObjectState.Persistent ==··((Flughafen)l.Flughäfen[0]).NDOObjectState, "4.: Flughafen should be hollow");
614
615 ············pm.UnloadCache();
616 ············liste = pm.GetClassExtent(typeof(Land));
617 ············l = (Land)liste[0];
618 ············Assert.That(NDOObjectState.Hollow ==··l.NDOObjectState, "5: Land should be hollow");
619 ············Assert.That(l.Flughäfen != null, "6. Relation is missing");
620 ············Assert.That(1 ==··l.Flughäfen.Count, "7. Wrong number of objects");
621 ············Assert.That(NDOObjectState.Hollow ==··((Flughafen)l.Flughäfen[0]).NDOObjectState, "8.: Flughafen should be hollow");
622
623 ············pm.UnloadCache();
624 ············liste = pm.GetClassExtent(typeof(Land), false);
625 ············l = (Land)liste[0];
626 ············Assert.That(NDOObjectState.Persistent ==··l.NDOObjectState, "9: Land should be persistent");
627 ············Assert.That(l.Flughäfen != null, "10. Relation is missing");
628 ············Assert.That(1 ==··l.Flughäfen.Count, "11. Wrong number of objects");
629 ············Assert.That(NDOObjectState.Hollow ==··((Flughafen)l.Flughäfen[0]).NDOObjectState, "12.: Flughafen should be hollow");
630 ········}
631
632 ········[Test]
633 ········public void RelationEmptyAssignment()
634 ········{
635 ············pm.MakePersistent(l);
636 ············pm.MakePersistent(f);
637 ············l.AddFlughafen(f);
638 ············pm.Save();
639 ············pm.UnloadCache();
640 ············l = (Land) pm.FindObject(l.NDOObjectId);
641 ············//Assert.That(l.Flughäfen.Count == 1);
642 ············l.ErsetzeFlughafenn(new ArrayList());
643 ············pm.Save();
644 ············pm.UnloadCache();
645 ············l = (Land) pm.FindObject(l.NDOObjectId);
646 Assert.That(l.Flughäfen == null, "Flughafenn should be null");
647 ············Assert.That(l.Flughäfen.Count == 0, "Flughafenn should be empty");
648 ········}
649
650 ········[Test]
651 ········public void RelationNullAssignment()
652 ········{
653 ············pm.MakePersistent(l);
654 ············pm.MakePersistent(f);
655 ············l.AddFlughafen(f);
656 ············pm.Save();
657 ············pm.UnloadCache();
658 ············l = (Land) pm.FindObject(l.NDOObjectId);
659 ············//Assert.That(l.Flughäfen.Count == 1);
660 ············l.ErsetzeFlughafenn(null);
661 ············pm.Save();
662 ············pm.UnloadCache();
663 ············l = (Land) pm.FindObject(l.NDOObjectId);
664 Assert.That(l.Flughäfen == null, "Flughafenn should be null");
665 ············Assert.That(l.Flughäfen.Count == 0, "Flughafenn should be empty");
666 ········}
667
668 #if !MYSQL
669 ········[Test]
670 ········public void AbortedTransaction()
671 ········{
672 ············pm.MakePersistent(l);
673 ············pm.MakePersistent(f);
674 ············l.AddFlughafen(f);
675 ············pm.Save();
676 ············pm.UnloadCache();
677
678 ············pm.TransactionMode = TransactionMode.Optimistic;
679
680 ············IQuery q = new NDOQuery<Land>(pm, null);
681 ············l = (Land) q.ExecuteSingle(true);
682 ············l.Vorname = "Hans";
683 ············((Flughafen)l.Flughäfen[0]).Zweck = "Neuer Zweck";
684
685 ············FieldInfo fi = pm.NDOMapping.GetType().GetField("persistenceHandler", BindingFlags.Instance | BindingFlags.NonPublic);
686 ············Hashtable ht = (Hashtable) fi.GetValue(pm.NDOMapping);
687 ············ht.Clear();
688 ············pm.NDOMapping.FindClass(typeof(Flughafen)).FindField("zweck").ColumnName = "nix";
689 ············
690 ············try
691 ············{
692 ················pm.Save();
693 ············}
694 ············catch
695 ············{
696 ················ht.Clear();
697 ················pm.NDOMapping.FindClass(typeof(Flughafen)).FindField("zweck").ColumnName = "Zweck";
698 ················pm.Abort();
699 ············}
700 ············pm.UnloadCache();
701 ············l = (Land) q.ExecuteSingle(true);
702 ············Assert.That("Hartmut" ==··l.Vorname, "Vorname falsch");
703 ············Assert.That("ADC" ==··((Flughafen)l.Flughäfen[0]).Zweck, "Vorname falsch");
704 ············
705 ········}
706 #endif
707
708 ········[Test]
709 ········public void TestListEnumerator()
710 ········{
711 ············pm.MakePersistent(l);
712 ············pm.MakePersistent(f);
713 ············l.AddFlughafen(f);
714 ············pm.Save();
715 ············pm.UnloadCache();
716 ············IQuery q = new NDOQuery<Land>(pm, null);
717 ············l = (Land) q.ExecuteSingle(true);
718 ············IEnumerator ie = l.Flughäfen.GetEnumerator();
719 ············bool result = ie.MoveNext();
720 ············Assert.That(result, "Enumerator should give a result");
721 ············Assert.That(ie.Current != null);
722 ········}
723 */
724
725 ········[Test]
726 ········public void TestListCount()
727 ········{
728 ············pm.MakePersistent(l);
729 ············pm.MakePersistent(f);
730 ············l.AddFlughafen(f);
731 ············pm.Save();
732 ············pm.UnloadCache();
733 ············IQuery q = new NDOQuery<Land>(pm, null);
734 ············l = (Land) q.ExecuteSingle(true);
735 ············Assert.That(1 ==··l.Flughäfen.Count, "Count should be 1");
736 ········}
737
738
739 ········[Test]
740 ········public void TestAddFlughafen()
741 ········{
742 ············pm.MakePersistent(l);
743 ············pm.MakePersistent(f);
744 ············l.AddFlughafen(f);
745 ············pm.Save();
746 ············pm.UnloadCache();
747 ············IQuery q = new NDOQuery<Land>(pm, null);
748 ············l = (Land) q.ExecuteSingle(true);
749 ············Assert.That(l != null, "Land not found");
750 ············Assert.That(1 ==··l.Flughäfen.Count, "Count wrong");
751 ············Flughafen f2 = CreateFlughafen("FRA");
752 ············pm.MakePersistent(f2);
753 ············l.AddFlughafen(f2);
754 ············pm.Save();
755 ············pm.UnloadCache();
756 ············l = (Land) q.ExecuteSingle(true);
757 ············Assert.That(2 ==··l.Flughäfen.Count, "Count wrong");
758 ········}
759
760 ········public void TestAddFlughafen2()
761 ········{
762 ············pm.MakePersistent(l);
763 ············pm.MakePersistent(f);
764 ············pm.Save();
765 ············l.AddFlughafen(f);
766 ············pm.Save();
767 ············pm.UnloadCache();
768 ············l = (Land) pm.FindObject(l.NDOObjectId);
769 ············Assert.That(1 ==··l.Flughäfen.Count, "Count wrong");
770 ········}
771
772 ········[Test]
773 ········public void TestRelatedObject()
774 ········{
775 ············pm.MakePersistent(l);
776 ············pm.MakePersistent(f);
777 ············l.AddFlughafen(f);
778 ············pm.Save();
779 ············pm.MakeHollow(f);
780 ············f.Kürzel = "XXX";
781 ············pm.Save();··// Bug would overwrite foreign key in database.
782 ············Assert.That("XXX" ==··f.Kürzel, "Kürzel should be changed");
783 ············ObjectId id = l.NDOObjectId;
784 ············pm.UnloadCache();
785 ············l = (Land) pm.FindObject(id);
786 ············Assert.That(1 ==··l.Flughäfen.Count, "Number of children");
787 ········}
788
789 ········private Land CreateLand(string name)
790 ········{
791 ············Land l = new Land();
792 ············l.Name = name;
793 ············return l;
794 ········}
795
796 ········private Flughafen CreateFlughafen(string name)
797 ········{
798 ············Flughafen f = new Flughafen();
799 ············f.Kürzel = name;
800 ············return f;
801 ········}
802 ····}
803 }
804