Example #1
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 #2
0
        public void ShouldSendUpdatesAccordingToDoI()
        {
            var entity1 = new Entity();
            var entity2 = new Entity();

            doiMock.Setup(doi => doi.IsInterestedInEntity(entity1)).Returns(true);
            doiMock.Setup(doi => doi.IsInterestedInEntity(entity2)).Returns(false);

            var worldSync = new WorldSync();

            worldSync.HandleLocalAddedEntity(this, new EntityEventArgs(entity1));
            worldSync.HandleLocalAddedEntity(this, new EntityEventArgs(entity2));

            handlers.Verify(h => h.AddEntity(entity1.Guid.ToString(), World.Instance.ID.ToString(), It.Is <EntitySyncInfo>(
                                                 esi => esi.Components.Count == 0)), Times.Once());
            handlers.Verify(h => h.AddEntity(entity2.Guid.ToString(), World.Instance.ID.ToString(), It.Is <EntitySyncInfo>(
                                                 esi => esi.Components.Count == 0)), Times.Never());
        }
Example #3
0
        /// <summary>
        /// Initializes the object of this class. We have chosen to use this method instead of a constructor as various
        /// other methods called from Initilize require a ServerSync.Instance to be set, which requires a construct to
        /// have finished constructing the object already.
        /// </summary>
        public void Initialize()
        {
            localServer          = new LocalServerImpl();
            remoteServers        = new Dictionary <Connection, IRemoteServer>();
            AttemptedConnections = new HashSet <Connection>();

            domainSync    = new DomainSync();
            worldSync     = new WorldSync();
            componentSync = new ComponentSync();

            localServer.Service.OnNewClient += HandleNewServerConnected;

            if (ServerDiscovery == null)
            {
                ServerDiscovery = new ConfigDiscovery();
            }

            ConnectToRemoteServers();

            PluginManager.Instance.AddPluginLoadedHandler("Terminal", RegisterTerminalCommands);
        }
Example #4
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 ShouldSendUpdatesAccordingToDoI()
        {
            var entity1 = new Entity();
            var entity2 = new Entity();
            doiMock.Setup(doi => doi.IsInterestedInEntity(entity1)).Returns(true);
            doiMock.Setup(doi => doi.IsInterestedInEntity(entity2)).Returns(false);

            var worldSync = new WorldSync();
            worldSync.HandleLocalAddedEntity(this, new EntityEventArgs(entity1));
            worldSync.HandleLocalAddedEntity(this, new EntityEventArgs(entity2));

            handlers.Verify(h => h.AddEntity(entity1.Guid, It.Is<EntitySyncInfo>(
                esi => esi.Components.Count == 0)), Times.Once());
            handlers.Verify(h => h.AddEntity(entity2.Guid, It.Is<EntitySyncInfo>(
                esi => esi.Components.Count == 0)), Times.Never());
        }
        public void ShouldSendEntityAdditions()
        {
            var entity = new Entity();
            entity["test"]["a"].Suggest(33);

            var worldSync = new WorldSync();
            worldSync.HandleLocalAddedEntity(this, new EntityEventArgs(entity));

            handlers.Verify(h => h.AddEntity(entity.Guid, It.Is<EntitySyncInfo>(esi =>
                esi.Components.Count == 1 &&
                esi.Components["test"]["a"].LastValue.Equals(33))), Times.Once());
        }
        public void ShouldSendEntityRemovals()
        {
            var entity = new Entity();
            var worldSync = new WorldSync();
            worldSync.HandleLocalRemovedEntity(this, new EntityEventArgs(entity));

            handlers.Verify(h => h.RemoveEntity(entity.Guid), Times.Once());
        }
        public void ShouldRemoveEntityOnUpdate()
        {
            var entity = new Entity();
            World.Instance.Add(entity);

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

            World.Instance.FindEntity(entity.Guid);
        }
        public void ShouldSendAttributeChanges()
        {
            var entity = new Entity();
            entity["test"]["a"].Suggest(33);
            World.Instance.Add(entity);

            var worldSync = new WorldSync();
            worldSync.HandleLocalChangedAttribute(this, new ChangedAttributeEventArgs(entity["test"], "a", 33, 55));

            handlers.Verify(h => h.ChangeAttributes(entity.Guid, It.Is<EntitySyncInfo>(esi =>
                esi.Components.Count == 1 &&
                esi.Components["test"]["a"].LastValue.Equals(55))), 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 ShouldRegisterWorldSyncAPI()
 {
     var worldSync = new WorldSync();
     localServiceMock.VerifySet(ls => ls["serverSync.addEntity"] = It.IsAny<Delegate>());
     localServiceMock.VerifySet(ls => ls["serverSync.removeEntity"] = It.IsAny<Delegate>());
     localServiceMock.VerifySet(ls => ls["serverSync.changeAttributes"] = It.IsAny<Delegate>());
 }
        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 ShouldCreateInitialSyncInfoForExistingEntities()
 {
     var entity = new Entity();
     World.Instance.Add(entity);
     var worldSync = new WorldSync();
     worldSync.syncInfo.ContainsKey(entity.Guid);
 }
        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);
        }
        public void ShouldAddEntityOnUpdate()
        {
            var guid = Guid.NewGuid();
            var owner = Guid.NewGuid();
            var worldSync = new WorldSync();
            worldSync.HandleRemoteAddedEntity(remoteConnectionMock.Object, guid, owner, new EntitySyncInfo());

            // Will throw exception if no such entity.
            World.Instance.FindEntity(guid);
        }
        /// <summary>
        /// Initializes the object of this class. We have chosen to use this method instead of a constructor as various
        /// other methods called from Initilize require a ServerSync.Instance to be set, which requires a construct to
        /// have finished constructing the object already.
        /// </summary>
        public void Initialize()
        {
            localServer = new LocalServerImpl();
            remoteServers = new Dictionary<Connection, IRemoteServer>();

            domainSync = new DomainSync();
            worldSync = new WorldSync();
            componentSync = new ComponentSync();

            localServer.Service.OnNewClient += HandleNewServerConnected;

            ConnectToRemoteServers();

            PluginManager.Instance.AddPluginLoadedHandler("Terminal", RegisterTerminalCommands);
        }