ObjectIDGeneratorTests.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //
  2. // System.Runtime.Serialization.ObjectIDGeneratorTests.cs
  3. //
  4. // Author: Duncan Mak ([email protected])
  5. //
  6. // (C) Ximian, Inc.
  7. //
  8. using System;
  9. using System.Diagnostics;
  10. using System.Runtime.Serialization;
  11. using NUnit.Framework;
  12. namespace MonoTests.System.Runtime.Serialization
  13. {
  14. public class ObjectIDGeneratorTests
  15. {
  16. ObjectIDGenerator generator;
  17. string obj1 = "obj1";
  18. int obj2 = 42;
  19. long id;
  20. [SetUp]
  21. protected void SetUp ()
  22. {
  23. generator = new ObjectIDGenerator ();
  24. }
  25. //
  26. // Tests adding an ID for a new object
  27. //
  28. public void TestGetId1 ()
  29. {
  30. bool testBool1;
  31. id = generator.GetId (obj1, out testBool1);
  32. Assert.AreEqual (1L, id); // should start at 1, "A1");
  33. Assert.AreEqual (true, testBool1); // firstTime should be true, "A2");
  34. }
  35. //
  36. // Tests getting the ID for an existing object
  37. //
  38. public void TestGetId2 ()
  39. {
  40. bool testBool1;
  41. bool testBool2;
  42. id = generator.GetId (obj1, out testBool1);
  43. long testId1 = generator.GetId (obj1, out testBool2);
  44. Assert.AreEqual (testId1, id); // same object, same ID, "B1");
  45. Assert.AreEqual (false, testBool2); // no longer firstTime, "B2");
  46. }
  47. //
  48. // Tests getting the ID for an existing object
  49. //
  50. public void TestHasId1 ()
  51. {
  52. bool testBool1;
  53. bool testBool3;
  54. id = generator.GetId (obj1, out testBool1);
  55. long testId2 = generator.HasId (obj1, out testBool3);
  56. Assert.AreEqual (false, testBool3); // this has been inserted before, "C1");
  57. Assert.AreEqual (id, testId2); // we should get the same ID, "C2");
  58. }
  59. //
  60. // Tests getting the ID for a non-existent object
  61. //
  62. public void TestHasId2 ()
  63. {
  64. bool testBool4;
  65. long testId3 = generator.HasId (obj2, out testBool4);
  66. Assert.AreEqual (0L, testId3, "D1");
  67. Assert.AreEqual (true, testBool4, "D2");
  68. }
  69. }
  70. }