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> /// Add an item to the registry. Once added, the registry can perform item<->ID translation for that item. /// Adding the same item twice is not supported. /// </summary> public static int Add(T item) { Assert.IsNotNull(rootRegistry, "NetworkableId<" + typeof(T).Name + "> registry has not yet been initialized"); return(rootRegistry.Add(item)); }