ObjectIDGeneratorTests.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 : TestCase
  15. {
  16. ObjectIDGenerator generator;
  17. string obj1 = "obj1";
  18. int obj2 = 42;
  19. long id;
  20. protected override void SetUp ()
  21. {
  22. generator = new ObjectIDGenerator ();
  23. }
  24. //
  25. // Tests adding an ID for a new object
  26. //
  27. public void TestGetId1 ()
  28. {
  29. bool testBool1;
  30. id = generator.GetId (obj1, out testBool1);
  31. AssertEquals ("A1", 1L, id); // should start at 1
  32. AssertEquals ("A2", true, testBool1); // firstTime should be true
  33. }
  34. //
  35. // Tests getting the ID for an existing object
  36. //
  37. public void TestGetId2 ()
  38. {
  39. bool testBool1;
  40. bool testBool2;
  41. id = generator.GetId (obj1, out testBool1);
  42. long testId1 = generator.GetId (obj1, out testBool2);
  43. AssertEquals ("B1", testId1, id); // same object, same ID
  44. AssertEquals ("B2", false, testBool2); // no longer firstTime
  45. }
  46. //
  47. // Tests getting the ID for an existing object
  48. //
  49. public void TestHasId1 ()
  50. {
  51. bool testBool1;
  52. bool testBool3;
  53. id = generator.GetId (obj1, out testBool1);
  54. long testId2 = generator.HasId (obj1, out testBool3);
  55. AssertEquals ("C1", false, testBool3); // this has been inserted before
  56. AssertEquals ("C2", id, testId2); // we should get the same ID
  57. }
  58. //
  59. // Tests getting the ID for a non-existent object
  60. //
  61. public void TestHasId2 ()
  62. {
  63. bool testBool4;
  64. long testId3 = generator.HasId (obj2, out testBool4);
  65. AssertEquals ("D1", 0L, testId3);
  66. AssertEquals ("D2", true, testBool4);
  67. }
  68. }
  69. }