public void AddRemoveRegistryContents() { NetworkableIdRegistry registry = new NetworkableIdRegistry(typeof(DummyClass1)); DummyClass1 obj1 = new DummyClass1(); DummyClass1 obj2 = new DummyClass1(); // Add a pair of items to registry Assert.DoesNotThrow(() => registry.Add(obj1)); Assert.DoesNotThrow(() => registry.Add(obj2)); // Once added, the item is assigned an ID, and translations to/from ID match int id1 = registry.ToId(obj1); Assert.That(registry.FromId(id1), Is.EqualTo(obj1)); // Adding the same object twice is not allowed Assert.Throws <ArgumentException>(() => registry.Add(obj1)); // Remove item from registry registry.Remove(obj1); // Once removed, the item is no longer available for lookup Assert.Throws <ArgumentException>(() => registry.ToId(obj1)); // Multiple removal of the same object is not allowed Assert.Throws <ArgumentException>(() => registry.Remove(obj1)); }
/// <summary> /// Remove an item from the registry. /// Removing an item which is not in the registry is not supported. /// </summary> public static void Remove(T item) { Assert.IsNotNull(rootRegistry, "NetworkableId<" + typeof(T).Name + "> registry has not yet been initialized"); rootRegistry.Remove(item); }