public void ZoneHandling()
        {
            ServerStateMachine     serverStateMachine = new TestServerStateMachine();
            ServerObjectRepository objRepo            = new ServerObjectRepository(serverStateMachine);

            // Create a distributed object to play with
            DistributedObjectId   doId = new DistributedObjectId(100);
            DistributedTestObject obj  = new DistributedTestObject(doId);

            ZoneId zoneId1 = new ZoneId(100);
            ZoneId zoneId2 = new ZoneId(200);

            objRepo.AddObject(obj);

            // No zone set yet
            Assert.IsTrue(objRepo.GetZone(obj) == null);
            Assert.IsTrue(objRepo.GetZone(doId) == null);
            Assert.IsTrue(objRepo.GetObjectsInZone(zoneId1).Count == 0);

            // Set the first zone
            objRepo.SetObjectZone(obj, zoneId1);
            Assert.IsTrue(objRepo.GetZone(obj) == zoneId1);
            Assert.IsTrue(objRepo.GetZone(doId) == zoneId1);
            Assert.IsTrue(objRepo.GetObjectsInZone(zoneId1).Count == 1);

            // Now change to the second zone
            objRepo.SetObjectZone(obj, zoneId2);
            Assert.IsTrue(objRepo.GetZone(obj) == zoneId2);
            Assert.IsTrue(objRepo.GetZone(doId) == zoneId2);
            // Should no longer be in the first zone
            Assert.IsTrue(objRepo.GetObjectsInZone(zoneId1).Count == 0);
            // Should be in the second zone
            Assert.IsTrue(objRepo.GetObjectsInZone(zoneId2).Count == 1);

            // Try setting the same zone again
            objRepo.SetObjectZone(obj, zoneId2);
            Assert.IsTrue(objRepo.GetZone(obj) == zoneId2);
            Assert.IsTrue(objRepo.GetZone(doId) == zoneId2);
            // Should be in the second zone, only once
            Assert.IsTrue(objRepo.GetObjectsInZone(zoneId2).Count == 1);

            // Remove obj
            objRepo.RemoveObject(obj);
            Assert.IsFalse(objRepo.ContainsObject(obj));
            // Should not be in either zone
            Assert.IsTrue(objRepo.GetObjectsInZone(zoneId1).Count == 0);
            Assert.IsTrue(objRepo.GetObjectsInZone(zoneId2).Count == 0);
        }
Exemplo n.º 2
0
        public void ObjectZoneChangingWithNobodyListening()
        {
            // Setup the server engine and its required dependencies
            ServerStateMachine     serverStateMachine = new TestServerStateMachine();
            SessionManager         sessionManager     = new SessionManager();
            ServerObjectRepository objectRepo         = new ServerObjectRepository(serverStateMachine);
            ServerEngine           serverEngine       = new ServerEngine(sessionManager, objectRepo, MockSendMessageToReflector);

            // Create a distributed object to play with
            DistributedObjectId   doId = new DistributedObjectId(100);
            DistributedTestObject obj  = new DistributedTestObject(doId);

            ZoneId zoneId1 = new ZoneId(100);
            ZoneId zoneId2 = new ZoneId(200);

            // Start by putting the object in the first zone
            serverEngine.ProcessZoneChange(obj, zoneId1);
            Assert.IsTrue(objectRepo.GetZone(obj) == zoneId1);

            // Test changing to the zone the object is already in
            serverEngine.ProcessZoneChange(obj, zoneId1);
            Assert.IsTrue(objectRepo.GetZone(obj) == zoneId1);

            // Now change to a new zone
            serverEngine.ProcessZoneChange(obj, zoneId2);
            Assert.IsTrue(objectRepo.GetZone(obj) == zoneId2);

            // Now remove the object from the zone
            Assert.IsTrue(serverEngine.RemoveObjectFromZone(obj) == zoneId2);
            Assert.IsTrue(objectRepo.GetZone(obj) == null);

            // Try a duplicate removal - should be safe to do
            Assert.IsTrue(serverEngine.RemoveObjectFromZone(obj) == null);
            Assert.IsTrue(objectRepo.GetZone(obj) == null);

            // Now put the object back in the first zone
            serverEngine.ProcessZoneChange(obj, zoneId1);
            Assert.IsTrue(objectRepo.GetZone(obj) == zoneId1);
        }