2 // System.Runtime.Serialization.ObjectIDGeneratorTests.cs
4 // Author: Duncan Mak (duncan@ximian.com)
10 using System.Diagnostics;
11 using System.Runtime.Serialization;
13 using NUnit.Framework;
15 namespace MonoTests.System.Runtime.Serialization
17 public class ObjectIDGeneratorTests : TestCase
19 ObjectIDGenerator generator;
25 protected override void SetUp ()
27 generator = new ObjectIDGenerator ();
31 // Tests adding an ID for a new object
33 public void TestGetId1 ()
36 id = generator.GetId (obj1, out testBool1);
38 AssertEquals ("A1", 1L, id); // should start at 1
39 AssertEquals ("A2", true, testBool1); // firstTime should be true
43 // Tests getting the ID for an existing object
45 public void TestGetId2 ()
49 id = generator.GetId (obj1, out testBool1);
50 long testId1 = generator.GetId (obj1, out testBool2);
52 AssertEquals ("B1", testId1, id); // same object, same ID
53 AssertEquals ("B2", false, testBool2); // no longer firstTime
57 // Tests getting the ID for an existing object
59 public void TestHasId1 ()
63 id = generator.GetId (obj1, out testBool1);
64 long testId2 = generator.HasId (obj1, out testBool3);
66 AssertEquals ("C1", false, testBool3); // this has been inserted before
67 AssertEquals ("C2", id, testId2); // we should get the same ID
71 // Tests getting the ID for a non-existent object
73 public void TestHasId2 ()
76 long testId3 = generator.HasId (obj2, out testBool4);
78 AssertEquals ("D1", 0L, testId3);
79 AssertEquals ("D2", true, testBool4);