Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        public void TearDown()
        {
            // Unregister Photon serializer/deserializer callbacks for the types

            PhotonRegisterSerializers registerSerializers = new PhotonRegisterSerializers();

            registerSerializers.DeregisterSerializer(typeof(NullMembers));
            registerSerializers.DeregisterSerializer(typeof(ConcreteChildById));
            registerSerializers.DeregisterSerializer(typeof(AbstractBaseById));
            registerSerializers.DeregisterSerializer(typeof(ConcreteChildByValue));
            registerSerializers.DeregisterSerializer(typeof(AbstractBaseByValue));

            // Deregister types & destroy type registries

            NetworkableId <Type> .Remove(typeof(NullMembers));

            NetworkableId <Type> .Remove(typeof(AbstractBaseById));

            NetworkableId <Type> .Remove(typeof(ConcreteChildById));

            NetworkableId <AbstractBaseById> .Destroy();

            NetworkableId <ConcreteChildById> .Destroy();

            NetworkableIdRegistry.DestroyRootRegistry(typeof(AbstractBaseById));

            NetworkableId <Type> .Remove(typeof(AbstractBaseByValue));

            NetworkableId <Type> .Remove(typeof(ConcreteChildByValue));

            NetworkableId <Type> .Destroy();

            NetworkableIdRegistry.DestroyRootRegistry(typeof(Type));
        }
Ejemplo n.º 3
0
    public static NetworkableIdRegistry CreateRootRegistry(Type type)
    {
        Assert.IsFalse(AllRootRegistries.ContainsKey(type), "Attempted to create root NetworkableIdRegistry for root type " + type.FullName + " twice");
        NetworkableIdRegistry rootRegistry = new NetworkableIdRegistry(type);

        AllRootRegistries[type] = rootRegistry;
        return(rootRegistry);
    }
Ejemplo n.º 4
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));
     }
 }
Ejemplo n.º 5
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)));
        }
Ejemplo n.º 6
0
        public void AddWithId()
        {
            NetworkableIdRegistry registry = new NetworkableIdRegistry(typeof(DummyClass1));

            DummyClass1 obj1 = new DummyClass1();
            DummyClass1 obj2 = new DummyClass1();

            int id1 = 10;
            int id2 = 20;

            // Add item to registry
            Assert.DoesNotThrow(() => registry.AddWithId(obj1, id1));
            Assert.That(registry.ToId(obj1), Is.EqualTo(id1));

            // Re-adding the same object with a new ID is not allowed
            Assert.Throws <ArgumentException>(() => registry.AddWithId(obj1, id2));

            // Adding a different object with the same ID is not allowed
            Assert.Throws <ArgumentException>(() => registry.AddWithId(obj2, id1));
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Prepare NetworkableId<T> for use.
 /// </summary>
 public static void Destroy()
 {
     rootRegistry = null;
 }