**** Merged from MCS ****
[mono-project.git] / mcs / class / corlib / Test / System.Runtime.Serialization / ObjectIDGeneratorTests.cs
blobd15ffd3cafbf98880d18cd8f0eb3e83aa9047a4a
1 //
2 // System.Runtime.Serialization.ObjectIDGeneratorTests.cs
3 //
4 // Author: Duncan Mak (duncan@ximian.com)
5 //
6 // (C) Ximian, Inc.
7 //
9 using System;
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;
21 string obj1 = "obj1";
22 int obj2 = 42;
23 long id;
25 protected override void SetUp ()
27 generator = new ObjectIDGenerator ();
31 // Tests adding an ID for a new object
33 public void TestGetId1 ()
35 bool testBool1;
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 ()
47 bool testBool1;
48 bool testBool2;
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 ()
61 bool testBool1;
62 bool testBool3;
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 ()
75 bool testBool4;
76 long testId3 = generator.HasId (obj2, out testBool4);
78 AssertEquals ("D1", 0L, testId3);
79 AssertEquals ("D2", true, testBool4);