Datei: IntegrationTests/IntegrationTests/Rel1to1BidirectionalWTable.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.Collections; |
| 25 | using System.IO; |
| 26 | using NUnit.Framework; |
| 27 | using Reisekosten.Personal; |
| 28 | using Reisekosten; |
| 29 | using NDO; |
| 30 | |
| 31 | namespace NdoUnitTests |
| 32 | { |
| 33 | ····/// <summary> |
| 34 | ····/// All tests for 1:1-Relations. Bidirectional Composition and Aggregation with mapping table. |
| 35 | ····/// </summary> |
| 36 | |
| 37 | |
| 38 | ····[TestFixture] |
| 39 | ····public class Rel1to1BidirectionalWTable : NDOTest |
| 40 | ····{ |
| 41 | ········public Rel1to1BidirectionalWTable() |
| 42 | ········{ |
| 43 | ········} |
| 44 | |
| 45 | ········private PersistenceManager pm; |
| 46 | ········private Zertifikat z; |
| 47 | ········private Signatur sgn; |
| 48 | |
| 49 | ········[SetUp] |
| 50 | ········public void Setup() |
| 51 | ········{ |
| 52 | ············pm = PmFactory.NewPersistenceManager(); |
| 53 | ············z = CreateZertifikat( 0815 ); |
| 54 | ············sgn = new Signatur(); |
| 55 | ············sgn.Key = "Signiert"; |
| 56 | ········} |
| 57 | |
| 58 | ········[TearDown] |
| 59 | ········public void TearDown() |
| 60 | ········{ |
| 61 | ············pm.Abort(); |
| 62 | ············IList zertifikatListe = pm.GetClassExtent( typeof( Zertifikat ), true ); |
| 63 | ············pm.Delete( zertifikatListe ); |
| 64 | ············IList sListe = pm.GetClassExtent( typeof( Signatur ), true ); |
| 65 | ············pm.Delete( sListe ); |
| 66 | ············pm.Save(); |
| 67 | ············pm.Close(); |
| 68 | ············pm = null; |
| 69 | ········} |
| 70 | |
| 71 | |
| 72 | |
| 73 | ········#region Composition Tests |
| 74 | |
| 75 | ········[Test] |
| 76 | ········public void CompTestCreateObjectsSave() |
| 77 | ········{ |
| 78 | ············z.SGN = sgn; |
| 79 | ············pm.MakePersistent( z ); |
| 80 | ············pm.Save(); |
| 81 | ············Assert.That( !z.NDOObjectId.Equals( z.SGN.NDOObjectId ), "Ids should be different" ); |
| 82 | ············z = (Zertifikat)pm.FindObject( z.NDOObjectId ); |
| 83 | ············sgn = (Signatur)pm.FindObject( z.SGN.NDOObjectId ); |
| 84 | ············Assert.That(z != null, "1. Zertifikat not found" ); |
| 85 | ············Assert.That(sgn != null, "1. SGN not found" ); |
| 86 | ············ObjectId moid = z.NDOObjectId; |
| 87 | ············ObjectId soid = sgn.NDOObjectId; |
| 88 | ············z = null; |
| 89 | ············sgn = null; |
| 90 | |
| 91 | ············pm.UnloadCache(); |
| 92 | ············z = (Zertifikat)pm.FindObject( moid ); |
| 93 | ············Signatur s2 = z.SGN; |
| 94 | ············sgn = (Signatur)pm.FindObject( soid ); |
| 95 | ············Assert.That(z != null, "2. Zertifikat not found" ); |
| 96 | ············Assert.That(sgn != null, "2. SGN not found" ); |
| 97 | ············Assert.That(Object.ReferenceEquals(sgn, s2), "SGN should match" ); |
| 98 | ············Assert.That(Object.ReferenceEquals(z, sgn.Owner), "Zertifikat should match" ); |
| 99 | ········} |
| 100 | |
| 101 | ········[Test] |
| 102 | ········public void SimpleObjectSave() |
| 103 | ········{ |
| 104 | ············pm.MakePersistent( sgn ); |
| 105 | ············pm.Save(); |
| 106 | ········} |
| 107 | |
| 108 | ········[Test] |
| 109 | ········public void CompChildAddFail() |
| 110 | ········{ |
| 111 | ············bool thrown = false; |
| 112 | ············pm.MakePersistent( sgn ); |
| 113 | ············try |
| 114 | ············{ |
| 115 | ················sgn.Owner = z; |
| 116 | ············} |
| 117 | ············catch (NDOException) |
| 118 | ············{ |
| 119 | ················thrown = true; |
| 120 | ············} |
| 121 | ············Assert.That(true ==··thrown ); |
| 122 | ········} |
| 123 | |
| 124 | ········[Test] |
| 125 | ········public void CompChildAddFail2() |
| 126 | ········{ |
| 127 | ············bool thrown = false; |
| 128 | ············pm.MakePersistent( sgn ); |
| 129 | ············pm.Save(); |
| 130 | ············try |
| 131 | ············{ |
| 132 | ················sgn.Owner = z; |
| 133 | ············} |
| 134 | ············catch (NDOException) |
| 135 | ············{ |
| 136 | ················thrown = true; |
| 137 | ············} |
| 138 | ············Assert.That(true ==··thrown ); |
| 139 | ········} |
| 140 | |
| 141 | ········[Test] |
| 142 | ········public void CompChildAdd3() |
| 143 | ········{ |
| 144 | ············pm.MakePersistent( z ); |
| 145 | ············pm.Save(); |
| 146 | ············z.SGN = sgn; |
| 147 | ············var thrown = false; |
| 148 | ············try |
| 149 | ············{ |
| 150 | ················sgn.Owner = z;··// Cannot manipulate composition relation through child |
| 151 | ············} |
| 152 | ············catch (NDOException) |
| 153 | ············{ |
| 154 | ················thrown = true; |
| 155 | ············} |
| 156 | ············Assert.That(true ==··thrown ); |
| 157 | ········} |
| 158 | |
| 159 | ········[Test] |
| 160 | ········public void CompChildAdd4() |
| 161 | ········{ |
| 162 | ············pm.MakePersistent( z ); |
| 163 | ············pm.Save(); |
| 164 | ············z.SGN = sgn; |
| 165 | ············var thrown = false; |
| 166 | ············try |
| 167 | ············{ |
| 168 | ················sgn.Owner = null;··// Cannot manipulate composition relation through child |
| 169 | ············} |
| 170 | ············catch (NDOException) |
| 171 | ············{ |
| 172 | ················thrown = true; |
| 173 | ············} |
| 174 | ············Assert.That(true ==··thrown ); |
| 175 | ········} |
| 176 | |
| 177 | ········[Test] |
| 178 | ········public void CompTestAddObjectSave() |
| 179 | ········{ |
| 180 | ············pm.MakePersistent( z ); |
| 181 | ············pm.Save(); |
| 182 | ············z.SGN = sgn; |
| 183 | ············Assert.That(NDOObjectState.Created ==··sgn.NDOObjectState, "1. Wrong state" ); |
| 184 | ············Assert.That(Object.ReferenceEquals(z, sgn.Owner), "1. Backlink wrong" ); |
| 185 | ············pm.Save(); |
| 186 | ············z = (Zertifikat)pm.FindObject( z.NDOObjectId ); |
| 187 | ············sgn = (Signatur)pm.FindObject( sgn.NDOObjectId ); |
| 188 | ············Assert.That(z != null, "1. Zertifikat not found" ); |
| 189 | ············Assert.That(sgn != null, "1. SGN not found" ); |
| 190 | ············Assert.That(NDOObjectState.Persistent ==··sgn.NDOObjectState, "2. Wrong state" ); |
| 191 | ············Assert.That(Object.ReferenceEquals(z, sgn.Owner), "2. Backlink wrong" ); |
| 192 | ········} |
| 193 | |
| 194 | ········[Test] |
| 195 | ········public void CompTestAddObjectAbort() |
| 196 | ········{ |
| 197 | ············pm.MakePersistent( z ); |
| 198 | ············pm.Save(); |
| 199 | ············z.SGN = sgn; |
| 200 | ············Assert.That(NDOObjectState.Created ==··sgn.NDOObjectState, "1. Wrong state" ); |
| 201 | ············Assert.That(z.SGN != null, "1. SGN not found" ); |
| 202 | ············pm.Abort(); |
| 203 | ············Assert.That(NDOObjectState.Transient ==··sgn.NDOObjectState, "2. Wrong state" ); |
| 204 | ············Assert.That(z.SGN == null, "1. SGN should be null" ); |
| 205 | ············Assert.That(sgn.Owner == null, "1. Zertifikat should be null" ); |
| 206 | ········} |
| 207 | |
| 208 | |
| 209 | ········[Test] |
| 210 | ········public void CompTestReplaceChildSave() |
| 211 | ········{ |
| 212 | ············pm.MakePersistent( z ); |
| 213 | ············z.SGN = sgn; |
| 214 | ············pm.Save(); |
| 215 | ············Assert.That(z.SGN != null, "1. SGN not found" ); |
| 216 | ············Signatur svn2 = new Signatur(); |
| 217 | ············svn2.Key = "VeriSign"; |
| 218 | ············z.SGN = svn2; |
| 219 | ············Assert.That(NDOObjectState.Deleted ==··sgn.NDOObjectState, "1. Wrong state" ); |
| 220 | ············Assert.That(NDOObjectState.Created ==··svn2.NDOObjectState, "2. Wrong state" ); |
| 221 | ············Assert.That(sgn.Owner == null, "3. No relation to Zertifikat" ); |
| 222 | ············Assert.That(Object.ReferenceEquals(svn2.Owner, z), "4. Zertifikat should be same" ); |
| 223 | ············Assert.That(Object.ReferenceEquals(z.SGN, svn2), "5. SGN should be same" ); |
| 224 | ············pm.Save(); |
| 225 | ············Assert.That(NDOObjectState.Transient ==··sgn.NDOObjectState, "6. Wrong state" ); |
| 226 | ············Assert.That(NDOObjectState.Persistent ==··svn2.NDOObjectState, "7. Wrong state" ); |
| 227 | ············Assert.That(sgn.Owner == null, "8. No relation to Zertifikat" ); |
| 228 | ············Assert.That(Object.ReferenceEquals(svn2.Owner, z), "9. Zertifikat should be same" ); |
| 229 | ············Assert.That(Object.ReferenceEquals(z.SGN, svn2), "10. SGN should be same" ); |
| 230 | ········} |
| 231 | |
| 232 | ········[Test] |
| 233 | ········public void CompTestReplaceChildAbort() |
| 234 | ········{ |
| 235 | ············pm.MakePersistent( z ); |
| 236 | ············z.SGN = sgn; |
| 237 | ············pm.Save(); |
| 238 | ············Assert.That(z.SGN != null, "1. SGN not found" ); |
| 239 | ············Signatur svn2 = new Signatur(); |
| 240 | ············svn2.Key = "VeriSign"; |
| 241 | ············z.SGN = svn2; |
| 242 | ············pm.Abort(); |
| 243 | ············Assert.That(NDOObjectState.Transient ==··svn2.NDOObjectState, "1. Wrong state" ); |
| 244 | ············Assert.That(NDOObjectState.Persistent ==··sgn.NDOObjectState, "2. Wrong state" ); |
| 245 | ············Assert.That(svn2.Owner == null, "3. No relation to Zertifikat" ); |
| 246 | ············Assert.That(Object.ReferenceEquals(sgn.Owner, z), "4. Zertifikat should be same" ); |
| 247 | ············Assert.That(Object.ReferenceEquals(z.SGN, sgn), "5. SGN should be same" ); |
| 248 | ········} |
| 249 | |
| 250 | ········[Test] |
| 251 | ········public void CompTestReplaceParentSave() |
| 252 | ········{ |
| 253 | ············pm.MakePersistent( z ); |
| 254 | ············z.SGN = sgn; |
| 255 | ············pm.Save(); |
| 256 | ············Assert.That(z.SGN != null, "1. SGN not found" ); |
| 257 | ············Zertifikat m2 = CreateZertifikat( 3345 ); |
| 258 | ············var thrown = false; |
| 259 | ············try |
| 260 | ············{ |
| 261 | ················sgn.Owner = m2; |
| 262 | ············} |
| 263 | ············catch (NDOException) |
| 264 | ············{ |
| 265 | ················thrown = true; |
| 266 | ············} |
| 267 | ············Assert.That(true ==··thrown ); |
| 268 | ········} |
| 269 | |
| 270 | |
| 271 | ········[Test] |
| 272 | ········public void CompTestRemoveObjectSave() |
| 273 | ········{ |
| 274 | ············pm.MakePersistent( z ); |
| 275 | ············z.SGN = sgn; |
| 276 | ············pm.Save(); |
| 277 | ············Assert.That(z.SGN != null, "1. SGN not found" ); |
| 278 | ············z.SGN = null; |
| 279 | ············Assert.That(NDOObjectState.Deleted ==··sgn.NDOObjectState, "1. Wrong state" ); |
| 280 | ············Assert.That(z.SGN == null, "1. SGN should be null" ); |
| 281 | ············Assert.That(sgn.Owner == null, "1. Zertifikat should be null" ); |
| 282 | ············pm.Save(); |
| 283 | ············Assert.That(z.SGN == null, "2. SGN should be null" ); |
| 284 | ············Assert.That(NDOObjectState.Transient ==··sgn.NDOObjectState, "2. Wrong state" ); |
| 285 | ············ObjectId moid = z.NDOObjectId; |
| 286 | ············pm.UnloadCache(); |
| 287 | ············z = (Zertifikat)pm.FindObject( moid ); |
| 288 | ············Assert.That(z != null, "3. Zertifikat not found" ); |
| 289 | ············Assert.That(z.SGN == null, "3. SGN should be null" ); |
| 290 | ········} |
| 291 | |
| 292 | ········[Test] |
| 293 | ········public void CompTestRemoveObjectAbort() |
| 294 | ········{ |
| 295 | ············pm.MakePersistent( z ); |
| 296 | ············z.SGN = sgn; |
| 297 | ············pm.Save(); |
| 298 | ············Assert.That(z.SGN != null, "1. SGN not found" ); |
| 299 | ············z.SGN = null; |
| 300 | ············Assert.That(NDOObjectState.Deleted ==··sgn.NDOObjectState, "1. Wrong state" ); |
| 301 | ············Assert.That(z.SGN == null, "2. SGN should be null" ); |
| 302 | ············pm.Abort(); |
| 303 | ············Assert.That(z.SGN != null, "2. SGN not found" ); |
| 304 | ············Assert.That(NDOObjectState.Persistent ==··sgn.NDOObjectState, "2. Wrong state" ); |
| 305 | ············Assert.That(Object.ReferenceEquals(z, sgn.Owner), "2. Backlink wrong" ); |
| 306 | ········} |
| 307 | |
| 308 | ········[Test] |
| 309 | ········public void CompTestRemoveParent() |
| 310 | ········{ |
| 311 | ············pm.MakePersistent( z ); |
| 312 | ············z.SGN = sgn; |
| 313 | ············pm.Save(); |
| 314 | ············Assert.That(sgn.Owner != null, "1. Zertifikat not found" ); |
| 315 | ············ObjectId aoid = sgn.NDOObjectId; |
| 316 | ············var thrown = false; |
| 317 | ············try |
| 318 | ············{ |
| 319 | ················sgn.Owner = null;·· // Cannot manipulate composition relation through child |
| 320 | ············} |
| 321 | ············catch (NDOException) |
| 322 | ············{ |
| 323 | ················thrown = true; |
| 324 | ············} |
| 325 | ············Assert.That(true ==··thrown ); |
| 326 | ········} |
| 327 | |
| 328 | ········[Test] |
| 329 | ········public void CompTestRemoveParentBeforeSave() |
| 330 | ········{ |
| 331 | ············pm.MakePersistent( z ); |
| 332 | ············z.SGN = sgn; |
| 333 | ············var thrown = false; |
| 334 | ············try |
| 335 | ············{ |
| 336 | ················sgn.Owner = null;·· // Cannot manipulate composition relation through child |
| 337 | ············} |
| 338 | ············catch (NDOException) |
| 339 | ············{ |
| 340 | ················thrown = true; |
| 341 | ············} |
| 342 | ············Assert.That(true ==··thrown ); |
| 343 | ········} |
| 344 | |
| 345 | |
| 346 | ········[Test] |
| 347 | ········public void CompTestDeleteSave() |
| 348 | ········{ |
| 349 | ············pm.MakePersistent( z ); |
| 350 | ············pm.Save(); |
| 351 | ············z.SGN = sgn; |
| 352 | ············pm.Save(); |
| 353 | ············pm.Delete( z ); |
| 354 | ············Assert.That(NDOObjectState.Deleted ==··z.NDOObjectState, "1. Wrong state" ); |
| 355 | ············Assert.That(NDOObjectState.Deleted ==··sgn.NDOObjectState, "2. Wrong state" ); |
| 356 | ············pm.Save(); |
| 357 | ············Assert.That(NDOObjectState.Transient ==··z.NDOObjectState, "1. Wrong state" ); |
| 358 | ············Assert.That(NDOObjectState.Transient ==··sgn.NDOObjectState, "2. Wrong state" ); |
| 359 | ············// Objects should retain relations in memory |
| 360 | ············Assert.That(z.SGN != null, "3. SGN shouldn't be null" ); |
| 361 | ············Assert.That(sgn.Owner == null, "3. Zertifikat should be null" ); |
| 362 | ········} |
| 363 | |
| 364 | ········[Test] |
| 365 | ········public void CompTestDeleteChildSave() |
| 366 | ········{ |
| 367 | ············pm.MakePersistent( z ); |
| 368 | ············pm.Save(); |
| 369 | ············z.SGN = sgn; |
| 370 | ············pm.Save(); |
| 371 | ············var thrown = false; |
| 372 | ············try |
| 373 | ············{ |
| 374 | ················pm.Delete( sgn ); |
| 375 | ············} |
| 376 | ············catch (NDOException) |
| 377 | ············{ |
| 378 | ················thrown = true; |
| 379 | ············} |
| 380 | ············Assert.That(true ==··thrown ); |
| 381 | ········} |
| 382 | |
| 383 | |
| 384 | ········[Test] |
| 385 | ········public void CompTestDeleteAbort() |
| 386 | ········{ |
| 387 | ············pm.MakePersistent( z ); |
| 388 | ············pm.Save(); |
| 389 | ············z.SGN = sgn; |
| 390 | ············pm.Save(); |
| 391 | ············pm.Delete( z ); |
| 392 | ············Assert.That(NDOObjectState.Deleted ==··z.NDOObjectState, "1. Wrong state" ); |
| 393 | ············Assert.That(NDOObjectState.Deleted ==··sgn.NDOObjectState, "2. Wrong state" ); |
| 394 | ············pm.Abort(); |
| 395 | ············Assert.That(NDOObjectState.Persistent ==··z.NDOObjectState, "1. Wrong state" ); |
| 396 | ············Assert.That(NDOObjectState.Persistent ==··sgn.NDOObjectState, "2. Wrong state" ); |
| 397 | ············Assert.That(z.SGN != null, "2. SGN not found" ); |
| 398 | ············Assert.That(Object.ReferenceEquals(z, sgn.Owner), "2. Backlink wrong" ); |
| 399 | ········} |
| 400 | |
| 401 | ········[Test] |
| 402 | ········public void CompTestCreateDelete() |
| 403 | ········{ |
| 404 | ············pm.MakePersistent( z ); |
| 405 | ············z.SGN = sgn; |
| 406 | ············pm.Delete( z ); |
| 407 | ············Assert.That(NDOObjectState.Transient ==··z.NDOObjectState, "1. Wrong state" ); |
| 408 | ············Assert.That(NDOObjectState.Transient ==··sgn.NDOObjectState, "2. Wrong state" ); |
| 409 | ············// Objects should retain relations in memory |
| 410 | ············Assert.That(z.SGN != null, "3. SGN shouldn't be null" ); |
| 411 | ············Assert.That(sgn.Owner == null, "3. Zertifikat should be null" ); |
| 412 | ········} |
| 413 | |
| 414 | ········[Test] |
| 415 | ········public void CompTestAddRemoveSave() |
| 416 | ········{ |
| 417 | ············pm.MakePersistent( z ); |
| 418 | ············pm.Save(); |
| 419 | ············z.SGN = sgn; |
| 420 | ············z.SGN = null; |
| 421 | ············Assert.That(NDOObjectState.Transient ==··sgn.NDOObjectState, "1. Wrong state" ); |
| 422 | ············Assert.That(z.SGN == null, "1. SGN should be null" ); |
| 423 | ············Assert.That(sgn.Owner == null, "1. Zertifikat should be null" ); |
| 424 | ············pm.Save(); |
| 425 | ············Assert.That(NDOObjectState.Transient ==··sgn.NDOObjectState, "2. Wrong state" ); |
| 426 | ············Assert.That(z.SGN == null, "2. SGN should be null" ); |
| 427 | ············Assert.That(sgn.Owner == null, "3. Zertifikat should be null" ); |
| 428 | ········} |
| 429 | |
| 430 | ········[Test] |
| 431 | ········public void CompTestAddRemoveAbort() |
| 432 | ········{ |
| 433 | ············pm.MakePersistent( z ); |
| 434 | ············pm.Save(); |
| 435 | ············z.SGN = sgn; |
| 436 | ············z.SGN = null; |
| 437 | ············Assert.That(NDOObjectState.Transient ==··sgn.NDOObjectState, "1. Wrong state" ); |
| 438 | ············pm.Abort(); |
| 439 | ············Assert.That(NDOObjectState.Transient ==··sgn.NDOObjectState, "2. Wrong state" ); |
| 440 | ············Assert.That(z.SGN == null, "2. SGN should be null" ); |
| 441 | ············Assert.That(sgn.Owner == null, "3. Zertifikat should be null" ); |
| 442 | ········} |
| 443 | |
| 444 | |
| 445 | |
| 446 | ········[Test] |
| 447 | ········public void CompTestHollow() |
| 448 | ········{ |
| 449 | ············z.SGN = sgn; |
| 450 | ············pm.MakePersistent( z ); |
| 451 | ············pm.Save(); |
| 452 | ············pm.MakeHollow( z ); // setzt z.sgn auf null |
| 453 | |
| 454 | ············Assert.That(NDOObjectState.Hollow ==··z.NDOObjectState, "1: Zertifikat should be hollow" ); |
| 455 | ············Assert.That(NDOObjectState.Persistent ==··sgn.NDOObjectState, "1: SGN should be persistent" ); |
| 456 | |
| 457 | ············sgn = z.SGN; // ruft LoadData för z auf. z.svm liegt auf dem Cache und ist Persistent |
| 458 | ············Assert.That(NDOObjectState.Persistent ==··z.NDOObjectState, "1: Zertifikat should be persistent" ); |
| 459 | ············Assert.That(NDOObjectState.Persistent ==··sgn.NDOObjectState, "2: SGN should be persistent" ); |
| 460 | ············ObjectId id = z.NDOObjectId; |
| 461 | ············pm.Close(); |
| 462 | ············pm = PmFactory.NewPersistenceManager(); |
| 463 | ············z = (Zertifikat)pm.FindObject( id ); |
| 464 | ············Assert.That(z != null, "Zertifikat not found" ); |
| 465 | ············Assert.That(NDOObjectState.Hollow ==··z.NDOObjectState, "2: Zertifikat should be hollow" ); |
| 466 | ············sgn = z.SGN; |
| 467 | ············Assert.That(NDOObjectState.Persistent ==··z.NDOObjectState, "2: Zertifikat should be persistent" ); |
| 468 | ············Assert.That(sgn != null, "SGN not found" ); |
| 469 | ············Assert.That(NDOObjectState.Hollow ==··sgn.NDOObjectState, "1: SGN should be hollow" ); |
| 470 | ············Assert.That(Object.ReferenceEquals(z, sgn.Owner), "2. Backlink wrong" ); |
| 471 | ········} |
| 472 | |
| 473 | |
| 474 | ········[Test] |
| 475 | ········public void CompTestMakeAllHollow() |
| 476 | ········{ |
| 477 | ············z.SGN = sgn; |
| 478 | ············pm.MakePersistent( z ); |
| 479 | ············pm.Save(); |
| 480 | ············pm.MakeAllHollow(); |
| 481 | ············Assert.That(NDOObjectState.Hollow ==··z.NDOObjectState, "1: Zertifikat should be hollow" ); |
| 482 | ············Assert.That(NDOObjectState.Hollow ==··sgn.NDOObjectState, "1: SGN should be hollow" ); |
| 483 | ············Assert.That(Object.ReferenceEquals(z, sgn.Owner), "2. Backlink wrong" ); |
| 484 | ········} |
| 485 | |
| 486 | ········[Test] |
| 487 | ········public void CompTestMakeAllHollowUnsaved() |
| 488 | ········{ |
| 489 | ············z.SGN = sgn; |
| 490 | ············pm.MakePersistent( z ); |
| 491 | ············pm.MakeAllHollow();··// before save, objects cannot be made hollow. => in locked objects |
| 492 | ············Assert.That(NDOObjectState.Created ==··z.NDOObjectState, "1: Zertifikat should be created" ); |
| 493 | ············Assert.That(NDOObjectState.Created ==··sgn.NDOObjectState, "1: SGN should be created" ); |
| 494 | ········} |
| 495 | |
| 496 | |
| 497 | ········[Test] |
| 498 | ········public void CompTestExtentRelatedObjects() |
| 499 | ········{ |
| 500 | ············z.SGN = sgn; |
| 501 | ············pm.MakePersistent( z ); |
| 502 | ············pm.Save(); |
| 503 | ············IList liste = pm.GetClassExtent( typeof( Zertifikat ) ); |
| 504 | ············z = (Zertifikat)liste[0]; |
| 505 | ············Assert.That(NDOObjectState.Persistent ==··z.NDOObjectState, "1: Zertifikat should be persistent" ); |
| 506 | ············Assert.That(z.SGN != null, "2. Relation is missing" ); |
| 507 | ············Assert.That(NDOObjectState.Persistent ==··z.SGN.NDOObjectState, "2.: SGN should be hollow" ); |
| 508 | ············Assert.That(Object.ReferenceEquals(z, sgn.Owner), "2. Backlink wrong" ); |
| 509 | |
| 510 | ············pm.UnloadCache(); |
| 511 | ············liste = pm.GetClassExtent( typeof( Zertifikat ) ); |
| 512 | ············z = (Zertifikat)liste[0]; |
| 513 | ············Assert.That(NDOObjectState.Hollow ==··z.NDOObjectState, "5: Zertifikat should be hollow" ); |
| 514 | ············Assert.That(z.SGN != null, "6. Relation is missing" ); |
| 515 | ············Assert.That(NDOObjectState.Hollow ==··z.SGN.NDOObjectState, "8.: Key should be hollow" ); |
| 516 | ············Assert.That( z != sgn.Owner, "8a. Should be different objects" ); |
| 517 | ············Assert.That(Object.ReferenceEquals(z, z.SGN.Owner), "8b. Zertifikat should match" ); |
| 518 | |
| 519 | ············pm.UnloadCache(); |
| 520 | ············liste = pm.GetClassExtent( typeof( Zertifikat ), false ); |
| 521 | ············z = (Zertifikat)liste[0]; |
| 522 | ············Assert.That(NDOObjectState.Persistent ==··z.NDOObjectState, "9: Zertifikat should be persistent" ); |
| 523 | ············Assert.That(z.SGN != null, "10. Relation is missing" ); |
| 524 | ············Assert.That(NDOObjectState.Hollow ==··z.SGN.NDOObjectState, "12.: Key should be hollow" ); |
| 525 | ············Assert.That( z != sgn.Owner, "12a. Should be different objects" ); |
| 526 | ············Assert.That(Object.ReferenceEquals(z, z.SGN.Owner), "12b. Zertifikat should match" ); |
| 527 | ········} |
| 528 | |
| 529 | ········#endregion |
| 530 | |
| 531 | |
| 532 | |
| 533 | ········private Zertifikat CreateZertifikat( int k ) |
| 534 | ········{ |
| 535 | ············Zertifikat z = new Zertifikat(); |
| 536 | ············z.Key = k; |
| 537 | ············return z; |
| 538 | ········} |
| 539 | ····} |
| 540 | } |
| 541 |
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.Collections; |
| 25 | using System.IO; |
| 26 | using NUnit.Framework; |
| 27 | using Reisekosten.Personal; |
| 28 | using Reisekosten; |
| 29 | using NDO; |
| 30 | |
| 31 | namespace NdoUnitTests |
| 32 | { |
| 33 | ····/// <summary> |
| 34 | ····/// All tests for 1:1-Relations. Bidirectional Composition and Aggregation with mapping table. |
| 35 | ····/// </summary> |
| 36 | |
| 37 | |
| 38 | ····[TestFixture] |
| 39 | ····public class Rel1to1BidirectionalWTable : NDOTest |
| 40 | ····{ |
| 41 | ········public Rel1to1BidirectionalWTable() |
| 42 | ········{ |
| 43 | ········} |
| 44 | |
| 45 | ········private PersistenceManager pm; |
| 46 | ········private Zertifikat z; |
| 47 | ········private Signatur sgn; |
| 48 | |
| 49 | ········[SetUp] |
| 50 | ········public void Setup() |
| 51 | ········{ |
| 52 | ············pm = PmFactory.NewPersistenceManager(); |
| 53 | ············z = CreateZertifikat( 0815 ); |
| 54 | ············sgn = new Signatur(); |
| 55 | ············sgn.Key = "Signiert"; |
| 56 | ········} |
| 57 | |
| 58 | ········[TearDown] |
| 59 | ········public void TearDown() |
| 60 | ········{ |
| 61 | ············pm.Abort(); |
| 62 | ············IList zertifikatListe = pm.GetClassExtent( typeof( Zertifikat ), true ); |
| 63 | ············pm.Delete( zertifikatListe ); |
| 64 | ············IList sListe = pm.GetClassExtent( typeof( Signatur ), true ); |
| 65 | ············pm.Delete( sListe ); |
| 66 | ············pm.Save(); |
| 67 | ········} |
| 68 | |
| 69 | ········public void OneTimeTearDown() |
| 70 | ········{ |
| 71 | ············pm.Close(); |
| 72 | ············pm = null; |
| 73 | ········} |
| 74 | |
| 75 | |
| 76 | ········#region Composition Tests |
| 77 | |
| 78 | ········[Test] |
| 79 | ········public void CompTestCreateObjectsSave() |
| 80 | ········{ |
| 81 | ············z.SGN = sgn; |
| 82 | ············pm.MakePersistent( z ); |
| 83 | ············pm.Save(); |
| 84 | ············Assert.That( !z.NDOObjectId.Equals( z.SGN.NDOObjectId ), "Ids should be different" ); |
| 85 | ············z = (Zertifikat)pm.FindObject( z.NDOObjectId ); |
| 86 | ············sgn = (Signatur)pm.FindObject( z.SGN.NDOObjectId ); |
| 87 | ············Assert.That(z != null, "1. Zertifikat not found" ); |
| 88 | ············Assert.That(sgn != null, "1. SGN not found" ); |
| 89 | ············ObjectId moid = z.NDOObjectId; |
| 90 | ············ObjectId soid = sgn.NDOObjectId; |
| 91 | ············z = null; |
| 92 | ············sgn = null; |
| 93 | |
| 94 | ············pm.UnloadCache(); |
| 95 | ············z = (Zertifikat)pm.FindObject( moid ); |
| 96 | ············Signatur s2 = z.SGN; |
| 97 | ············sgn = (Signatur)pm.FindObject( soid ); |
| 98 | ············Assert.That(z != null, "2. Zertifikat not found" ); |
| 99 | ············Assert.That(sgn != null, "2. SGN not found" ); |
| 100 | ············Assert.That(Object.ReferenceEquals(sgn, s2), "SGN should match" ); |
| 101 | ············Assert.That(Object.ReferenceEquals(z, sgn.Owner), "Zertifikat should match" ); |
| 102 | ········} |
| 103 | |
| 104 | ········[Test] |
| 105 | ········public void SimpleObjectSave() |
| 106 | ········{ |
| 107 | ············pm.MakePersistent( sgn ); |
| 108 | ············pm.Save(); |
| 109 | ········} |
| 110 | |
| 111 | ········[Test] |
| 112 | ········public void CompChildAddFail() |
| 113 | ········{ |
| 114 | ············bool thrown = false; |
| 115 | ············pm.MakePersistent( sgn ); |
| 116 | ············try |
| 117 | ············{ |
| 118 | ················sgn.Owner = z; |
| 119 | ············} |
| 120 | ············catch (NDOException) |
| 121 | ············{ |
| 122 | ················thrown = true; |
| 123 | ············} |
| 124 | ············Assert.That(true ==··thrown ); |
| 125 | ········} |
| 126 | |
| 127 | ········[Test] |
| 128 | ········public void CompChildAddFail2() |
| 129 | ········{ |
| 130 | ············bool thrown = false; |
| 131 | ············pm.MakePersistent( sgn ); |
| 132 | ············pm.Save(); |
| 133 | ············try |
| 134 | ············{ |
| 135 | ················sgn.Owner = z; |
| 136 | ············} |
| 137 | ············catch (NDOException) |
| 138 | ············{ |
| 139 | ················thrown = true; |
| 140 | ············} |
| 141 | ············Assert.That(true ==··thrown ); |
| 142 | ········} |
| 143 | |
| 144 | ········[Test] |
| 145 | ········public void CompChildAdd3() |
| 146 | ········{ |
| 147 | ············pm.MakePersistent( z ); |
| 148 | ············pm.Save(); |
| 149 | ············z.SGN = sgn; |
| 150 | ············var thrown = false; |
| 151 | ············try |
| 152 | ············{ |
| 153 | ················sgn.Owner = z;··// Cannot manipulate composition relation through child |
| 154 | ············} |
| 155 | ············catch (NDOException) |
| 156 | ············{ |
| 157 | ················thrown = true; |
| 158 | ············} |
| 159 | ············Assert.That(true ==··thrown ); |
| 160 | ········} |
| 161 | |
| 162 | ········[Test] |
| 163 | ········public void CompChildAdd4() |
| 164 | ········{ |
| 165 | ············pm.MakePersistent( z ); |
| 166 | ············pm.Save(); |
| 167 | ············z.SGN = sgn; |
| 168 | ············var thrown = false; |
| 169 | ············try |
| 170 | ············{ |
| 171 | ················sgn.Owner = null;··// Cannot manipulate composition relation through child |
| 172 | ············} |
| 173 | ············catch (NDOException) |
| 174 | ············{ |
| 175 | ················thrown = true; |
| 176 | ············} |
| 177 | ············Assert.That(true ==··thrown ); |
| 178 | ········} |
| 179 | |
| 180 | ········[Test] |
| 181 | ········public void CompTestAddObjectSave() |
| 182 | ········{ |
| 183 | ············pm.MakePersistent( z ); |
| 184 | ············pm.Save(); |
| 185 | ············z.SGN = sgn; |
| 186 | ············Assert.That(NDOObjectState.Created ==··sgn.NDOObjectState, "1. Wrong state" ); |
| 187 | ············Assert.That(Object.ReferenceEquals(z, sgn.Owner), "1. Backlink wrong" ); |
| 188 | ············pm.Save(); |
| 189 | ············z = (Zertifikat)pm.FindObject( z.NDOObjectId ); |
| 190 | ············sgn = (Signatur)pm.FindObject( sgn.NDOObjectId ); |
| 191 | ············Assert.That(z != null, "1. Zertifikat not found" ); |
| 192 | ············Assert.That(sgn != null, "1. SGN not found" ); |
| 193 | ············Assert.That(NDOObjectState.Persistent ==··sgn.NDOObjectState, "2. Wrong state" ); |
| 194 | ············Assert.That(Object.ReferenceEquals(z, sgn.Owner), "2. Backlink wrong" ); |
| 195 | ········} |
| 196 | |
| 197 | ········[Test] |
| 198 | ········public void CompTestAddObjectAbort() |
| 199 | ········{ |
| 200 | ············pm.MakePersistent( z ); |
| 201 | ············pm.Save(); |
| 202 | ············z.SGN = sgn; |
| 203 | ············Assert.That(NDOObjectState.Created ==··sgn.NDOObjectState, "1. Wrong state" ); |
| 204 | ············Assert.That(z.SGN != null, "1. SGN not found" ); |
| 205 | ············pm.Abort(); |
| 206 | ············Assert.That(NDOObjectState.Transient ==··sgn.NDOObjectState, "2. Wrong state" ); |
| 207 | ············Assert.That(z.SGN == null, "1. SGN should be null" ); |
| 208 | ············Assert.That(sgn.Owner == null, "1. Zertifikat should be null" ); |
| 209 | ········} |
| 210 | |
| 211 | |
| 212 | ········[Test] |
| 213 | ········public void CompTestReplaceChildSave() |
| 214 | ········{ |
| 215 | ············pm.MakePersistent( z ); |
| 216 | ············z.SGN = sgn; |
| 217 | ············pm.Save(); |
| 218 | ············Assert.That(z.SGN != null, "1. SGN not found" ); |
| 219 | ············Signatur svn2 = new Signatur(); |
| 220 | ············svn2.Key = "VeriSign"; |
| 221 | ············z.SGN = svn2; |
| 222 | ············Assert.That(NDOObjectState.Deleted ==··sgn.NDOObjectState, "1. Wrong state" ); |
| 223 | ············Assert.That(NDOObjectState.Created ==··svn2.NDOObjectState, "2. Wrong state" ); |
| 224 | ············Assert.That(sgn.Owner == null, "3. No relation to Zertifikat" ); |
| 225 | ············Assert.That(Object.ReferenceEquals(svn2.Owner, z), "4. Zertifikat should be same" ); |
| 226 | ············Assert.That(Object.ReferenceEquals(z.SGN, svn2), "5. SGN should be same" ); |
| 227 | ············pm.Save(); |
| 228 | ············Assert.That(NDOObjectState.Transient ==··sgn.NDOObjectState, "6. Wrong state" ); |
| 229 | ············Assert.That(NDOObjectState.Persistent ==··svn2.NDOObjectState, "7. Wrong state" ); |
| 230 | ············Assert.That(sgn.Owner == null, "8. No relation to Zertifikat" ); |
| 231 | ············Assert.That(Object.ReferenceEquals(svn2.Owner, z), "9. Zertifikat should be same" ); |
| 232 | ············Assert.That(Object.ReferenceEquals(z.SGN, svn2), "10. SGN should be same" ); |
| 233 | ········} |
| 234 | |
| 235 | ········[Test] |
| 236 | ········public void CompTestReplaceChildAbort() |
| 237 | ········{ |
| 238 | ············pm.MakePersistent( z ); |
| 239 | ············z.SGN = sgn; |
| 240 | ············pm.Save(); |
| 241 | ············Assert.That(z.SGN != null, "1. SGN not found" ); |
| 242 | ············Signatur svn2 = new Signatur(); |
| 243 | ············svn2.Key = "VeriSign"; |
| 244 | ············z.SGN = svn2; |
| 245 | ············pm.Abort(); |
| 246 | ············Assert.That(NDOObjectState.Transient ==··svn2.NDOObjectState, "1. Wrong state" ); |
| 247 | ············Assert.That(NDOObjectState.Persistent ==··sgn.NDOObjectState, "2. Wrong state" ); |
| 248 | ············Assert.That(svn2.Owner == null, "3. No relation to Zertifikat" ); |
| 249 | ············Assert.That(Object.ReferenceEquals(sgn.Owner, z), "4. Zertifikat should be same" ); |
| 250 | ············Assert.That(Object.ReferenceEquals(z.SGN, sgn), "5. SGN should be same" ); |
| 251 | ········} |
| 252 | |
| 253 | ········[Test] |
| 254 | ········public void CompTestReplaceParentSave() |
| 255 | ········{ |
| 256 | ············pm.MakePersistent( z ); |
| 257 | ············z.SGN = sgn; |
| 258 | ············pm.Save(); |
| 259 | ············Assert.That(z.SGN != null, "1. SGN not found" ); |
| 260 | ············Zertifikat m2 = CreateZertifikat( 3345 ); |
| 261 | ············var thrown = false; |
| 262 | ············try |
| 263 | ············{ |
| 264 | ················sgn.Owner = m2; |
| 265 | ············} |
| 266 | ············catch (NDOException) |
| 267 | ············{ |
| 268 | ················thrown = true; |
| 269 | ············} |
| 270 | ············Assert.That(true ==··thrown ); |
| 271 | ········} |
| 272 | |
| 273 | |
| 274 | ········[Test] |
| 275 | ········public void CompTestRemoveObjectSave() |
| 276 | ········{ |
| 277 | ············pm.MakePersistent( z ); |
| 278 | ············z.SGN = sgn; |
| 279 | ············pm.Save(); |
| 280 | ············Assert.That(z.SGN != null, "1. SGN not found" ); |
| 281 | ············z.SGN = null; |
| 282 | ············Assert.That(NDOObjectState.Deleted ==··sgn.NDOObjectState, "1. Wrong state" ); |
| 283 | ············Assert.That(z.SGN == null, "1. SGN should be null" ); |
| 284 | ············Assert.That(sgn.Owner == null, "1. Zertifikat should be null" ); |
| 285 | ············pm.Save(); |
| 286 | ············Assert.That(z.SGN == null, "2. SGN should be null" ); |
| 287 | ············Assert.That(NDOObjectState.Transient ==··sgn.NDOObjectState, "2. Wrong state" ); |
| 288 | ············ObjectId moid = z.NDOObjectId; |
| 289 | ············pm.UnloadCache(); |
| 290 | ············z = (Zertifikat)pm.FindObject( moid ); |
| 291 | ············Assert.That(z != null, "3. Zertifikat not found" ); |
| 292 | ············Assert.That(z.SGN == null, "3. SGN should be null" ); |
| 293 | ········} |
| 294 | |
| 295 | ········[Test] |
| 296 | ········public void CompTestRemoveObjectAbort() |
| 297 | ········{ |
| 298 | ············pm.MakePersistent( z ); |
| 299 | ············z.SGN = sgn; |
| 300 | ············pm.Save(); |
| 301 | ············Assert.That(z.SGN != null, "1. SGN not found" ); |
| 302 | ············z.SGN = null; |
| 303 | ············Assert.That(NDOObjectState.Deleted ==··sgn.NDOObjectState, "1. Wrong state" ); |
| 304 | ············Assert.That(z.SGN == null, "2. SGN should be null" ); |
| 305 | ············pm.Abort(); |
| 306 | ············Assert.That(z.SGN != null, "2. SGN not found" ); |
| 307 | ············Assert.That(NDOObjectState.Persistent ==··sgn.NDOObjectState, "2. Wrong state" ); |
| 308 | ············Assert.That(Object.ReferenceEquals(z, sgn.Owner), "2. Backlink wrong" ); |
| 309 | ········} |
| 310 | |
| 311 | ········[Test] |
| 312 | ········public void CompTestRemoveParent() |
| 313 | ········{ |
| 314 | ············pm.MakePersistent( z ); |
| 315 | ············z.SGN = sgn; |
| 316 | ············pm.Save(); |
| 317 | ············Assert.That(sgn.Owner != null, "1. Zertifikat not found" ); |
| 318 | ············ObjectId aoid = sgn.NDOObjectId; |
| 319 | ············var thrown = false; |
| 320 | ············try |
| 321 | ············{ |
| 322 | ················sgn.Owner = null;·· // Cannot manipulate composition relation through child |
| 323 | ············} |
| 324 | ············catch (NDOException) |
| 325 | ············{ |
| 326 | ················thrown = true; |
| 327 | ············} |
| 328 | ············Assert.That(true ==··thrown ); |
| 329 | ········} |
| 330 | |
| 331 | ········[Test] |
| 332 | ········public void CompTestRemoveParentBeforeSave() |
| 333 | ········{ |
| 334 | ············pm.MakePersistent( z ); |
| 335 | ············z.SGN = sgn; |
| 336 | ············var thrown = false; |
| 337 | ············try |
| 338 | ············{ |
| 339 | ················sgn.Owner = null;·· // Cannot manipulate composition relation through child |
| 340 | ············} |
| 341 | ············catch (NDOException) |
| 342 | ············{ |
| 343 | ················thrown = true; |
| 344 | ············} |
| 345 | ············Assert.That(true ==··thrown ); |
| 346 | ········} |
| 347 | |
| 348 | |
| 349 | ········[Test] |
| 350 | ········public void CompTestDeleteSave() |
| 351 | ········{ |
| 352 | ············pm.MakePersistent( z ); |
| 353 | ············pm.Save(); |
| 354 | ············z.SGN = sgn; |
| 355 | ············pm.Save(); |
| 356 | ············pm.Delete( z ); |
| 357 | ············Assert.That(NDOObjectState.Deleted ==··z.NDOObjectState, "1. Wrong state" ); |
| 358 | ············Assert.That(NDOObjectState.Deleted ==··sgn.NDOObjectState, "2. Wrong state" ); |
| 359 | ············pm.Save(); |
| 360 | ············Assert.That(NDOObjectState.Transient ==··z.NDOObjectState, "1. Wrong state" ); |
| 361 | ············Assert.That(NDOObjectState.Transient ==··sgn.NDOObjectState, "2. Wrong state" ); |
| 362 | ············// Objects should retain relations in memory |
| 363 | ············Assert.That(z.SGN != null, "3. SGN shouldn't be null" ); |
| 364 | ············Assert.That(sgn.Owner == null, "3. Zertifikat should be null" ); |
| 365 | ········} |
| 366 | |
| 367 | ········[Test] |
| 368 | ········public void CompTestDeleteChildSave() |
| 369 | ········{ |
| 370 | ············pm.MakePersistent( z ); |
| 371 | ············pm.Save(); |
| 372 | ············z.SGN = sgn; |
| 373 | ············pm.Save(); |
| 374 | ············var thrown = false; |
| 375 | ············try |
| 376 | ············{ |
| 377 | ················pm.Delete( sgn ); |
| 378 | ············} |
| 379 | ············catch (NDOException) |
| 380 | ············{ |
| 381 | ················thrown = true; |
| 382 | ············} |
| 383 | ············Assert.That(true ==··thrown ); |
| 384 | ········} |
| 385 | |
| 386 | |
| 387 | ········[Test] |
| 388 | ········public void CompTestDeleteAbort() |
| 389 | ········{ |
| 390 | ············pm.MakePersistent( z ); |
| 391 | ············pm.Save(); |
| 392 | ············z.SGN = sgn; |
| 393 | ············pm.Save(); |
| 394 | ············pm.Delete( z ); |
| 395 | ············Assert.That(NDOObjectState.Deleted ==··z.NDOObjectState, "1. Wrong state" ); |
| 396 | ············Assert.That(NDOObjectState.Deleted ==··sgn.NDOObjectState, "2. Wrong state" ); |
| 397 | ············pm.Abort(); |
| 398 | ············Assert.That(NDOObjectState.Persistent ==··z.NDOObjectState, "1. Wrong state" ); |
| 399 | ············Assert.That(NDOObjectState.Persistent ==··sgn.NDOObjectState, "2. Wrong state" ); |
| 400 | ············Assert.That(z.SGN != null, "2. SGN not found" ); |
| 401 | ············Assert.That(Object.ReferenceEquals(z, sgn.Owner), "2. Backlink wrong" ); |
| 402 | ········} |
| 403 | |
| 404 | ········[Test] |
| 405 | ········public void CompTestCreateDelete() |
| 406 | ········{ |
| 407 | ············pm.MakePersistent( z ); |
| 408 | ············z.SGN = sgn; |
| 409 | ············pm.Delete( z ); |
| 410 | ············Assert.That(NDOObjectState.Transient ==··z.NDOObjectState, "1. Wrong state" ); |
| 411 | ············Assert.That(NDOObjectState.Transient ==··sgn.NDOObjectState, "2. Wrong state" ); |
| 412 | ············// Objects should retain relations in memory |
| 413 | ············Assert.That(z.SGN != null, "3. SGN shouldn't be null" ); |
| 414 | ············Assert.That(sgn.Owner == null, "3. Zertifikat should be null" ); |
| 415 | ········} |
| 416 | |
| 417 | ········[Test] |
| 418 | ········public void CompTestAddRemoveSave() |
| 419 | ········{ |
| 420 | ············pm.MakePersistent( z ); |
| 421 | ············pm.Save(); |
| 422 | ············z.SGN = sgn; |
| 423 | ············z.SGN = null; |
| 424 | ············Assert.That(NDOObjectState.Transient ==··sgn.NDOObjectState, "1. Wrong state" ); |
| 425 | ············Assert.That(z.SGN == null, "1. SGN should be null" ); |
| 426 | ············Assert.That(sgn.Owner == null, "1. Zertifikat should be null" ); |
| 427 | ············pm.Save(); |
| 428 | ············Assert.That(NDOObjectState.Transient ==··sgn.NDOObjectState, "2. Wrong state" ); |
| 429 | ············Assert.That(z.SGN == null, "2. SGN should be null" ); |
| 430 | ············Assert.That(sgn.Owner == null, "3. Zertifikat should be null" ); |
| 431 | ········} |
| 432 | |
| 433 | ········[Test] |
| 434 | ········public void CompTestAddRemoveAbort() |
| 435 | ········{ |
| 436 | ············pm.MakePersistent( z ); |
| 437 | ············pm.Save(); |
| 438 | ············z.SGN = sgn; |
| 439 | ············z.SGN = null; |
| 440 | ············Assert.That(NDOObjectState.Transient ==··sgn.NDOObjectState, "1. Wrong state" ); |
| 441 | ············pm.Abort(); |
| 442 | ············Assert.That(NDOObjectState.Transient ==··sgn.NDOObjectState, "2. Wrong state" ); |
| 443 | ············Assert.That(z.SGN == null, "2. SGN should be null" ); |
| 444 | ············Assert.That(sgn.Owner == null, "3. Zertifikat should be null" ); |
| 445 | ········} |
| 446 | |
| 447 | |
| 448 | |
| 449 | ········[Test] |
| 450 | ········public void CompTestHollow() |
| 451 | ········{ |
| 452 | ············z.SGN = sgn; |
| 453 | ············pm.MakePersistent( z ); |
| 454 | ············pm.Save(); |
| 455 | ············pm.MakeHollow( z ); // setzt z.sgn auf null |
| 456 | |
| 457 | ············Assert.That(NDOObjectState.Hollow ==··z.NDOObjectState, "1: Zertifikat should be hollow" ); |
| 458 | ············Assert.That(NDOObjectState.Persistent ==··sgn.NDOObjectState, "1: SGN should be persistent" ); |
| 459 | |
| 460 | ············sgn = z.SGN; // ruft LoadData för z auf. z.svm liegt auf dem Cache und ist Persistent |
| 461 | ············Assert.That(NDOObjectState.Persistent ==··z.NDOObjectState, "1: Zertifikat should be persistent" ); |
| 462 | ············Assert.That(NDOObjectState.Persistent ==··sgn.NDOObjectState, "2: SGN should be persistent" ); |
| 463 | ············ObjectId id = z.NDOObjectId; |
| 464 | ············pm.Close(); |
| 465 | ············pm = PmFactory.NewPersistenceManager(); |
| 466 | ············z = (Zertifikat)pm.FindObject( id ); |
| 467 | ············Assert.That(z != null, "Zertifikat not found" ); |
| 468 | ············Assert.That(NDOObjectState.Hollow ==··z.NDOObjectState, "2: Zertifikat should be hollow" ); |
| 469 | ············sgn = z.SGN; |
| 470 | ············Assert.That(NDOObjectState.Persistent ==··z.NDOObjectState, "2: Zertifikat should be persistent" ); |
| 471 | ············Assert.That(sgn != null, "SGN not found" ); |
| 472 | ············Assert.That(NDOObjectState.Hollow ==··sgn.NDOObjectState, "1: SGN should be hollow" ); |
| 473 | ············Assert.That(Object.ReferenceEquals(z, sgn.Owner), "2. Backlink wrong" ); |
| 474 | ········} |
| 475 | |
| 476 | |
| 477 | ········[Test] |
| 478 | ········public void CompTestMakeAllHollow() |
| 479 | ········{ |
| 480 | ············z.SGN = sgn; |
| 481 | ············pm.MakePersistent( z ); |
| 482 | ············pm.Save(); |
| 483 | ············pm.MakeAllHollow(); |
| 484 | ············Assert.That(NDOObjectState.Hollow ==··z.NDOObjectState, "1: Zertifikat should be hollow" ); |
| 485 | ············Assert.That(NDOObjectState.Hollow ==··sgn.NDOObjectState, "1: SGN should be hollow" ); |
| 486 | ············Assert.That(Object.ReferenceEquals(z, sgn.Owner), "2. Backlink wrong" ); |
| 487 | ········} |
| 488 | |
| 489 | ········[Test] |
| 490 | ········public void CompTestMakeAllHollowUnsaved() |
| 491 | ········{ |
| 492 | ············z.SGN = sgn; |
| 493 | ············pm.MakePersistent( z ); |
| 494 | ············pm.MakeAllHollow();··// before save, objects cannot be made hollow. => in locked objects |
| 495 | ············Assert.That(NDOObjectState.Created ==··z.NDOObjectState, "1: Zertifikat should be created" ); |
| 496 | ············Assert.That(NDOObjectState.Created ==··sgn.NDOObjectState, "1: SGN should be created" ); |
| 497 | ········} |
| 498 | |
| 499 | |
| 500 | ········[Test] |
| 501 | ········public void CompTestExtentRelatedObjects() |
| 502 | ········{ |
| 503 | ············z.SGN = sgn; |
| 504 | ············pm.MakePersistent( z ); |
| 505 | ············pm.Save(); |
| 506 | ············IList liste = pm.GetClassExtent( typeof( Zertifikat ) ); |
| 507 | ············z = (Zertifikat)liste[0]; |
| 508 | ············Assert.That(NDOObjectState.Persistent ==··z.NDOObjectState, "1: Zertifikat should be persistent" ); |
| 509 | ············Assert.That(z.SGN != null, "2. Relation is missing" ); |
| 510 | ············Assert.That(NDOObjectState.Persistent ==··z.SGN.NDOObjectState, "2.: SGN should be hollow" ); |
| 511 | ············Assert.That(Object.ReferenceEquals(z, sgn.Owner), "2. Backlink wrong" ); |
| 512 | |
| 513 | ············pm.UnloadCache(); |
| 514 | ············liste = pm.GetClassExtent( typeof( Zertifikat ) ); |
| 515 | ············z = (Zertifikat)liste[0]; |
| 516 | ············Assert.That(NDOObjectState.Hollow ==··z.NDOObjectState, "5: Zertifikat should be hollow" ); |
| 517 | ············Assert.That(z.SGN != null, "6. Relation is missing" ); |
| 518 | ············Assert.That(NDOObjectState.Hollow ==··z.SGN.NDOObjectState, "8.: Key should be hollow" ); |
| 519 | ············Assert.That( z != sgn.Owner, "8a. Should be different objects" ); |
| 520 | ············Assert.That(Object.ReferenceEquals(z, z.SGN.Owner), "8b. Zertifikat should match" ); |
| 521 | |
| 522 | ············pm.UnloadCache(); |
| 523 | ············liste = pm.GetClassExtent( typeof( Zertifikat ), false ); |
| 524 | ············z = (Zertifikat)liste[0]; |
| 525 | ············Assert.That(NDOObjectState.Persistent ==··z.NDOObjectState, "9: Zertifikat should be persistent" ); |
| 526 | ············Assert.That(z.SGN != null, "10. Relation is missing" ); |
| 527 | ············Assert.That(NDOObjectState.Hollow ==··z.SGN.NDOObjectState, "12.: Key should be hollow" ); |
| 528 | ············Assert.That( z != sgn.Owner, "12a. Should be different objects" ); |
| 529 | ············Assert.That(Object.ReferenceEquals(z, z.SGN.Owner), "12b. Zertifikat should match" ); |
| 530 | ········} |
| 531 | |
| 532 | ········#endregion |
| 533 | |
| 534 | |
| 535 | |
| 536 | ········private Zertifikat CreateZertifikat( int k ) |
| 537 | ········{ |
| 538 | ············Zertifikat z = new Zertifikat(); |
| 539 | ············z.Key = k; |
| 540 | ············return z; |
| 541 | ········} |
| 542 | ····} |
| 543 | } |
| 544 |