Example #1
0
 /// <summary>
 /// Prepare NetworkableId<T> for use.
 /// If root == null, create a new registry.
 /// Otherwise, attach to the root type's registry. The root type's NetworkableId<T> must already have been initialized.
 /// </summary>
 public static void Create(Type root)
 {
     if (root != null)
     {
         rootRegistry = NetworkableIdRegistry.GetRootRegistry(root);
         Assert.IsNotNull(rootRegistry, "No NetworkableIdRegistry available for root type " + root.FullName);
     }
     else
     {
         rootRegistry = NetworkableIdRegistry.CreateRootRegistry(typeof(T));
     }
 }
Example #2
0
        public void RootRegistries()
        {
            // There should be no root registries available at start of test
            Assert.That(NetworkableIdRegistry.AllRootRegistries.Count, Is.EqualTo(0));

            // Create one root registry
            NetworkableIdRegistry.CreateRootRegistry(typeof(DummyClass1));

            // After creating a root registry for a given type, that type should be available
            Assert.That(NetworkableIdRegistry.AllRootRegistries.Count, Is.EqualTo(1));
            Assert.That(NetworkableIdRegistry.GetRootRegistry(typeof(DummyClass1)), Is.Not.Null);

            // Other classes should not yet provide a root registry
            Assert.Throws <KeyNotFoundException>(() => NetworkableIdRegistry.GetRootRegistry(typeof(DummyClass2)));

            // Remove root registry
            Assert.DoesNotThrow(() => NetworkableIdRegistry.DestroyRootRegistry(typeof(DummyClass1)));
        }