public void TestReserveNew() { IdentifierManager manager = new IdentifierManager(10L, 12L); Assert.AreEqual(10L, manager.ReserveNew()); Assert.AreEqual(11L, manager.ReserveNew()); Assert.AreEqual(12L, manager.ReserveNew()); try { manager.ReserveNew(); Assert.Fail("InvalidOperationException expected"); } catch (InvalidOperationException) { // expected } }
public void TestBasic() { IdentifierManager manager = new IdentifierManager(0L, 100L); Assert.AreEqual(101L, manager.GetRemainingIdentifiers()); Assert.AreEqual(0L, manager.ReserveNew()); Assert.AreEqual(100L, manager.GetRemainingIdentifiers()); Assert.AreEqual(1L, manager.Reserve(0L)); Assert.AreEqual(99L, manager.GetRemainingIdentifiers()); }
public void TestLongLimits() { long min = IdentifierManager.MIN_ID; long max = IdentifierManager.MAX_ID; IdentifierManager manager = new IdentifierManager(min, max); Assert.IsTrue(max - min + 1 > 0, "Limits lead to a long variable overflow"); Assert.IsTrue(manager.GetRemainingIdentifiers() > 0, "Limits lead to a long variable overflow"); Assert.AreEqual(min, manager.ReserveNew()); Assert.AreEqual(max, manager.Reserve(max)); Assert.AreEqual(max - min - 1, manager.GetRemainingIdentifiers()); manager.Release(max); manager.Release(min); }