Example #1
0
        public void ShouldChangeAttributesOnUpdate()
        {
            var entity = new Entity();

            World.Instance.Add(entity);

            var changedAttributes = new EntitySyncInfo();

            changedAttributes["test"]["a"] = new AttributeSyncInfo(Guid.NewGuid().ToString(), 99);

            var worldSync = new WorldSync();

            worldSync.HandleRemoteChangedAttributes(remoteConnectionMock.Object, entity.Guid.ToString(), changedAttributes);

            Assert.AreEqual(entity["test"]["a"].Value, 99);
        }
Example #2
0
        public void ShouldNotSendUpdatesWhenTheyResultFromRemoteUpdate()
        {
            var changedAttributes = new EntitySyncInfo();

            changedAttributes["test"]["a"] = new AttributeSyncInfo(Guid.NewGuid().ToString(), 99);

            var entity    = new Entity();
            var worldSync = new WorldSync();

            worldSync.HandleRemoteAddedEntity(remoteConnectionMock.Object, entity.Guid.ToString(), entity.Owner.ToString(), new EntitySyncInfo());
            worldSync.HandleRemoteChangedAttributes(remoteConnectionMock.Object, entity.Guid.ToString(), new EntitySyncInfo());
            worldSync.HandleRemoteRemovedEntity(remoteConnectionMock.Object, entity.Guid.ToString());

            handlers.Verify(h => h.AddEntity(entity.Guid.ToString(), It.IsAny <EntitySyncInfo>()), Times.Never());
            handlers.Verify(h => h.ChangeAttributes(entity.Guid.ToString(), It.IsAny <EntitySyncInfo>()), Times.Never());
            handlers.Verify(h => h.RemoveEntity(entity.Guid.ToString()), Times.Never());
        }
Example #3
0
        public void ShouldForwardUpdatesToServersOtherThanTheSource()
        {
            var otherConnectionMock = new Mock <Connection>();
            var handlers2           = new Mock <IHandlers>();

            otherConnectionMock.Setup(rc => rc.GenerateClientFunction("serverSync", "addEntity"))
            .Returns((ClientFunction)handlers2.Object.AddEntity);
            otherConnectionMock.Setup(rc => rc.GenerateClientFunction("serverSync", "removeEntity"))
            .Returns((ClientFunction)handlers2.Object.RemoveEntity);
            otherConnectionMock.Setup(rc => rc.GenerateClientFunction("serverSync", "changeAttributes"))
            .Returns((ClientFunction)handlers2.Object.ChangeAttributes);

            var guid = Guid.NewGuid();
            RemoteServerImpl remoteServer2 = new RemoteServerImpl(otherConnectionMock.Object, doiMock.Object,
                                                                  dorMock.Object, guid);

            serverSyncMock.Setup(ss => ss.RemoteServers).Returns(
                new List <IRemoteServer> {
                remoteServer, remoteServer2
            });

            var changedAttributes = new EntitySyncInfo();

            changedAttributes["test"]["a"] = new AttributeSyncInfo(Guid.NewGuid().ToString(), 99);

            var entity    = new Entity();
            var worldSync = new WorldSync();

            worldSync.HandleRemoteAddedEntity(remoteConnectionMock.Object, entity.Guid.ToString(), entity.Owner.ToString(), new EntitySyncInfo());
            worldSync.HandleRemoteChangedAttributes(remoteConnectionMock.Object, entity.Guid.ToString(), changedAttributes);
            worldSync.HandleRemoteRemovedEntity(remoteConnectionMock.Object, entity.Guid.ToString());

            handlers.Verify(h => h.AddEntity(entity.Guid.ToString(), It.IsAny <EntitySyncInfo>()), Times.Never());
            handlers.Verify(h => h.ChangeAttributes(entity.Guid.ToString(), It.IsAny <EntitySyncInfo>()), Times.Never());
            handlers.Verify(h => h.RemoveEntity(entity.Guid.ToString()), Times.Never());

            handlers2.Verify(h => h.AddEntity(entity.Guid.ToString(), entity.Owner.ToString(), It.IsAny <EntitySyncInfo>()), Times.Once());
            handlers2.Verify(h => h.ChangeAttributes(entity.Guid.ToString(), It.IsAny <EntitySyncInfo>()), Times.Once());
            handlers2.Verify(h => h.RemoveEntity(entity.Guid.ToString()), Times.Once());
        }
        public void ShouldNotSendUpdatesWhenTheyResultFromRemoteUpdate()
        {
            var changedAttributes = new EntitySyncInfo();
            changedAttributes["test"]["a"] = new AttributeSyncInfo(Guid.NewGuid(), 99);

            var entity = new Entity();
            var worldSync = new WorldSync();
            worldSync.HandleRemoteAddedEntity(remoteConnectionMock.Object, entity.Guid, entity.Owner, new EntitySyncInfo());
            worldSync.HandleRemoteChangedAttributes(remoteConnectionMock.Object, entity.Guid, new EntitySyncInfo());
            worldSync.HandleRemoteRemovedEntity(remoteConnectionMock.Object, entity.Guid);

            handlers.Verify(h => h.AddEntity(entity.Guid, It.IsAny<EntitySyncInfo>()), Times.Never());
            handlers.Verify(h => h.ChangeAttributes(entity.Guid, It.IsAny<EntitySyncInfo>()), Times.Never());
            handlers.Verify(h => h.RemoveEntity(entity.Guid), Times.Never());
        }
        public void ShouldForwardUpdatesToServersOtherThanTheSource()
        {
            var otherConnectionMock = new Mock<Connection>();
            var handlers2 = new Mock<IHandlers>();
            otherConnectionMock.Setup(rc => rc.GenerateClientFunction("serverSync","addEntity"))
                .Returns((ClientFunction)handlers2.Object.AddEntity);
            otherConnectionMock.Setup(rc => rc.GenerateClientFunction("serverSync","removeEntity"))
                .Returns((ClientFunction)handlers2.Object.RemoveEntity);
            otherConnectionMock.Setup(rc => rc.GenerateClientFunction("serverSync", "changeAttributes"))
                .Returns((ClientFunction)handlers2.Object.ChangeAttributes);

            var guid = Guid.NewGuid();
            RemoteServerImpl remoteServer2 = new RemoteServerImpl(otherConnectionMock.Object, doiMock.Object,
                dorMock.Object, guid);
            serverSyncMock.Setup(ss => ss.RemoteServers).Returns(
                new List<IRemoteServer> { remoteServer, remoteServer2 });

            var changedAttributes = new EntitySyncInfo();
            changedAttributes["test"]["a"] = new AttributeSyncInfo(Guid.NewGuid(), 99);

            var entity = new Entity();
            var worldSync = new WorldSync();
            worldSync.HandleRemoteAddedEntity(remoteConnectionMock.Object, entity.Guid, entity.Owner, new EntitySyncInfo());
            worldSync.HandleRemoteChangedAttributes(remoteConnectionMock.Object, entity.Guid, changedAttributes);
            worldSync.HandleRemoteRemovedEntity(remoteConnectionMock.Object, entity.Guid);

            handlers.Verify(h => h.AddEntity(entity.Guid, It.IsAny<EntitySyncInfo>()), Times.Never());
            handlers.Verify(h => h.ChangeAttributes(entity.Guid, It.IsAny<EntitySyncInfo>()), Times.Never());
            handlers.Verify(h => h.RemoveEntity(entity.Guid), Times.Never());

            handlers2.Verify(h => h.AddEntity(entity.Guid, It.IsAny<EntitySyncInfo>()), Times.Once());
            handlers2.Verify(h => h.ChangeAttributes(entity.Guid, It.IsAny<EntitySyncInfo>()), Times.Once());
            handlers2.Verify(h => h.RemoveEntity(entity.Guid), Times.Once());
        }
        public void ShouldChangeAttributesOnUpdate()
        {
            var entity = new Entity();
            World.Instance.Add(entity);

            var changedAttributes = new EntitySyncInfo();
            changedAttributes["test"]["a"] = new AttributeSyncInfo(Guid.NewGuid(), 99);

            var worldSync = new WorldSync();
            worldSync.HandleRemoteChangedAttributes(remoteConnectionMock.Object, entity.Guid, changedAttributes);

            Assert.AreEqual(entity["test"]["a"].Value, 99);
        }