2002-06-20 Nick Drochak <ndrochak@gol.com>
[mono.git] / mcs / class / corlib / Test / System.Runtime.Serialization / ObjectIDGeneratorTests.cs
1 //
2 // System.Runtime.Serialization.ObjectIDGeneratorTests.cs
3 //
4 // Author: Duncan Mak  (duncan@ximian.com)
5 //
6 // (C) Ximian, Inc.
7 //
8
9 using System;
10 using System.Diagnostics;
11 using System.Runtime.Serialization;
12
13 using NUnit.Framework;
14
15 namespace MonoTests.System.Runtime.Serialization
16 {
17         public class ObjectIDGeneratorTests : TestCase
18         {
19                 ObjectIDGenerator generator;
20
21                 string obj1 = "obj1";
22                 int obj2 = 42;          
23                 long id;
24
25                 public static ITest Suite {
26                         get { return new TestSuite (typeof (ObjectIDGeneratorTests)); }
27                 }
28                 
29                 public ObjectIDGeneratorTests (string name)
30                         : base (name)
31                 {
32                 }
33
34                 protected override void SetUp ()
35                 {
36                         generator = new ObjectIDGenerator ();
37                 }
38
39                 //
40                 // Tests adding an ID for a new object
41                 //
42                 public void TestGetId1 ()
43                 {
44                         bool testBool1;
45                         id = generator.GetId (obj1, out testBool1);
46
47                         AssertEquals ("A1", 1L, id); // should start at 1
48                         AssertEquals ("A2", true, testBool1);   // firstTime should be true
49                 }
50
51                 //
52                 // Tests getting the ID for an existing object
53                 //
54                 public void TestGetId2 ()
55                 {
56                         bool testBool1;
57                         bool testBool2;
58                         id = generator.GetId (obj1, out testBool1);
59                         long testId1 = generator.GetId (obj1, out testBool2);
60
61                         AssertEquals ("B1", testId1, id); // same object, same ID
62                         AssertEquals ("B2", false, testBool2); // no longer firstTime
63                 }
64
65                 //
66                 // Tests getting the ID for an existing object
67                 //
68                 public void TestHasId1 ()
69                 {
70                         bool testBool1;
71                         bool testBool3;
72                         id = generator.GetId (obj1, out testBool1);
73                         long testId2 = generator.HasId (obj1, out testBool3);
74
75                         AssertEquals ("C1", false, testBool3); // this has been inserted before
76                         AssertEquals ("C2", id, testId2); // we should get the same ID
77                 }
78
79                 //
80                 // Tests getting the ID for a non-existent object
81                 //
82                 public void TestHasId2 ()
83                 {
84                         bool testBool4;
85                         long testId3 = generator.HasId (obj2, out testBool4);
86
87                         AssertEquals ("D1", 0L, testId3);
88                         AssertEquals ("D2", true, testBool4);
89                 }
90         }
91 }