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