private void ServerEntity_RemoveTimerAll() { // Arrange var s = TestZoneBuilder.Build(); IServerEntity o = null; s.ServerZone.RunAction(z => { o = z.Spawn(typeof(IBullet), 0); }); // Act & Assert var called1 = false; var called2 = false; o.SetTimerOnce(1, TimeSpan.FromSeconds(1), (e, t) => { called1 = true; }); o.SetTimerOnce(2, TimeSpan.FromSeconds(1), (e, t) => { called2 = true; }); o.RemoveTimerAll(); s.UpdateTime(TimeSpan.FromSeconds(1)); Assert.False(called1); Assert.False(called2); }
public void ChangeOwnership() { // Arrange var s = TestZoneBuilder.Build(); IServerEntity so = null; s.ServerZone.RunAction(z => so = z.Spawn(typeof(ISpaceShip), 1)); // Act s.ServerZone.RunAction(z => z.SetEntityOwnership(so.Id, 2)); // Assert var s2 = s.ServerZone.GetEntity(so.Id); Assert.NotNull(s2); Assert.Equal(2, s2.OwnerId); var c2 = s.ClientZones[0].GetEntity(so.Id); Assert.NotNull(c2); Assert.Equal(2, c2.OwnerId); }
public void LiveWhenOwnerGoAwayEntity_GetHandOver_WhenAllOwnerRemoved_Entity() { // Arrange var s = TestZoneBuilder.Build(); IServerEntity so = null; s.ServerZone.RunAction(z => so = z.Spawn(typeof(ISpaceShip), 1, EntityFlags.LiveWhenOwnerGoAway)); // Act s.RemoveClient(1); s.RemoveClient(2); s.AddClient(); // Assert var s2 = s.ServerZone.GetEntity(so.Id); Assert.NotNull(s2); Assert.Equal(3, s2.OwnerId); var c2 = s.ClientZones[0].GetEntity(so.Id); Assert.NotNull(c2); Assert.Equal(3, c2.OwnerId); }
private void ServerEntity_SetTimerRepeatedly() { // Arrange var s = TestZoneBuilder.Build(); IServerEntity o = null; s.ServerZone.RunAction(z => { o = z.Spawn(typeof(IBullet), 0); }); // Act & Assert var callCount = 0; o.SetTimerRepeatedly(1, TimeSpan.FromSeconds(1), (e, t) => { Assert.Equal(e, o); Assert.Equal(1, t); callCount += 1; }); s.UpdateTime(TimeSpan.FromSeconds(1)); Assert.Equal(1, callCount); s.UpdateTime(TimeSpan.FromSeconds(1)); Assert.Equal(2, callCount); }
public void Spawn_SingletonEntity_When_AlreadyExists_Fail() { // Arrange var s = TestZoneBuilder.Build(); s.ServerZone.RunAction(z => z.Spawn(typeof(IEarth), 1)); // Act & Assert Assert.Throws <InvalidOperationException>(() => { s.ServerZone.RunAction(z => z.Spawn(typeof(IEarth), 1)); }); }
public void Spawn_SingletonEntity_When_NoExists_Succeed() { // Arrange var s = TestZoneBuilder.Build(); // Act IServerEntity so = null; s.ServerZone.RunAction(z => so = z.Spawn(typeof(IEarth), 1)); // Assert Assert.NotNull(so); Assert.IsType <ServerEarth>(so); }
public void OwnedEntity_AutoDespawn_WhenOwnerRemoved_Entity() { // Arrange var s = TestZoneBuilder.Build(); IServerEntity so = null; s.ServerZone.RunAction(z => so = z.Spawn(typeof(ISpaceShip), 1)); // Act s.RemoveClient(1); // Assert Assert.Null(s.ServerZone.GetEntity(so.Id)); }
public void Client_CallToServer_Called() { // Arrange var s = TestZoneBuilder.Build(); IServerEntity so = null; s.ServerZone.RunAction(z => so = z.Spawn(typeof(ISpaceShip), 1)); // Act s.ClientZones[0].RunAction(z => ((ClientSpaceShip)z.GetEntity(so.Id)).Shoot(1, 2)); // Assert Assert.Equal(Tuple.Create(so.Id, "OnShoot(1, 2)"), s.ServerZone.Log(-1)); }
public void NonOwner_CanCall_Entity_WhenEntityMethodHasAnyoneCanCallAttribute() { // Arrange var s = TestZoneBuilder.Build(); IServerEntity so = null; s.ServerZone.RunAction(z => so = z.Spawn(typeof(IBullet), 1)); // Act s.ClientZones[1].RunAction(z => ((ClientBullet)z.GetEntity(so.Id)).Tag("Silver")); // Assert Assert.Equal(Tuple.Create(so.Id, "OnTag(Silver)"), s.ServerZone.Log(-1)); }
public void NonOwner_CanControl_Entity_WhenEntityHasAnyoneCanControlFlag() { // Arrange var s = TestZoneBuilder.Build(); IServerEntity so = null; s.ServerZone.RunAction(z => so = z.Spawn(typeof(ISpaceShip), 1, EntityFlags.AnyoneCanControl)); // Act s.ClientZones[1].RunAction(z => ((ClientSpaceShip)z.GetEntity(so.Id)).Shoot(1, 2)); // Assert Assert.Equal(Tuple.Create(so.Id, "OnShoot(1, 2)"), s.ServerZone.Log(-1)); }
public void NonOwner_CannotControl_Entity() { // Arrange var s = TestZoneBuilder.Build(); IServerEntity so = null; s.ServerZone.RunAction(z => so = z.Spawn(typeof(ISpaceShip), 1)); // Act s.ClientZones[1].RunAction(z => ((ClientSpaceShip)z.GetEntity(so.Id)).Shoot(1, 2)); // Assert Assert.Equal(Tuple.Create(so.Id, "InvalidOwnershipInvoke"), s.ServerZone.Log(-1)); }
public void Spawn_ServerOnlyEntity_WhenAddNewClient_ClientCannotSee() { // Arrange var s = TestZoneBuilder.Build(); // Act IServerEntity so = null; s.ServerZone.RunAction(z => so = z.Spawn(typeof(IMonitor), 0)); var zone = s.AddClient(); // Assert var co = zone.Value.GetEntity(so.Id); Assert.Null(co); }
public void AddClient_AddedClientZone_Synced() { // Arrange var s = TestZoneBuilder.Build(); IServerEntity so = null; s.ServerZone.RunAction(z => so = z.Spawn(typeof(ISpaceShip), 1, EntityFlags.Normal)); // Act var zone = s.AddClient(); // Assert var co = zone.Value.GetEntity(so.Id); Assert.NotNull(co); Assert.IsType <ClientSpaceShip>(co); }
public void Client_CallPassThrough_Called() { // Arrange var s = TestZoneBuilder.Build(); IServerEntity so = null; s.ServerZone.RunAction(z => so = z.Spawn(typeof(ISpaceShip), 1, EntityFlags.Normal)); // Act s.ClientZones[0].RunAction(z => ((ClientSpaceShip)z.GetEntity(so.Id)).Say("Hello")); // Assert foreach (var clientZone in s.ClientZones) { Assert.Equal(Tuple.Create(so.Id, "OnSay(Hello)"), clientZone.Log(-1)); } }
public void Server_CallToClient_Called() { // Arrange var s = TestZoneBuilder.Build(); IServerEntity so = null; s.ServerZone.RunAction(z => so = z.Spawn(typeof(ISpaceShip), 1, EntityFlags.Normal)); // Act s.ServerZone.RunAction(z => ((ServerSpaceShip)so).Hit(1, 2)); // Assert foreach (var clientZone in s.ClientZones) { Assert.Equal(Tuple.Create(so.Id, "OnHit(1, 2)"), clientZone.Log(-1)); } }
public void Change_TrackableData_Synced() { // Arrange var s = TestZoneBuilder.Build(); IServerEntity so = null; s.ServerZone.RunAction(z => so = z.Spawn(typeof(ISpaceShip), 1, EntityFlags.Normal)); // Act s.ClientZones[0].RunAction(z => ((ClientSpaceShip)z.GetEntity(so.Id)).Shoot(1, 2)); // Assert foreach (var clientZone in s.ClientZones) { var clientEntity = (ClientSpaceShip)clientZone.GetEntity(so.Id); Assert.Equal(1, clientEntity.Data.Score); } }
public void Spawn_Snapshot_Synced() { // Arrange var s = TestZoneBuilder.Build(); IServerEntity so = null; // Act s.ServerZone.RunAction(z => so = z.Spawn(typeof(ISpaceShip), 1, EntityFlags.Normal, "Enterprise")); // Assert foreach (var clientZone in s.ClientZones) { Assert.Equal(Tuple.Create(so.Id, "OnSnapshot(Enterprise)"), clientZone.Log(-2)); Assert.Equal(Tuple.Create(so.Id, "Spawn"), clientZone.Log(-1)); } }
public void Spawn_ServerOnlyEntity_WhenSpawn_ClientCannotSee() { // Arrange var s = TestZoneBuilder.Build(); // Act IServerEntity so = null; s.ServerZone.RunAction(z => so = z.Spawn(typeof(IMonitor), 0)); Assert.NotNull(so); Assert.IsType <ServerMonitor>(so); // Assert foreach (var clientZone in s.ClientZones) { IClientEntity co = clientZone.GetEntity(so.Id); Assert.Null(co); } }
private void ServerEntity_SetTimerOnce() { // Arrange var s = TestZoneBuilder.Build(); IServerEntity o = null; s.ServerZone.RunAction(z => { o = z.Spawn(typeof(IBullet), 0); }); // Act & Assert var called = false; o.SetTimerOnce(1, TimeSpan.FromSeconds(1), (e, t) => { Assert.Equal(e, o); Assert.Equal(1, t); called = true; }); s.UpdateTime(TimeSpan.FromSeconds(1)); Assert.True(called); }
public void Spawn_SyncedToClient() { // Arrange var s = TestZoneBuilder.Build(); // Act IServerEntity so = null; s.ServerZone.RunAction(z => so = z.Spawn(typeof(IBullet), 1)); Assert.NotNull(so); Assert.IsType <ServerBullet>(so); // Assert foreach (var clientZone in s.ClientZones) { IClientEntity co = clientZone.GetEntity(so.Id); Assert.NotNull(co); Assert.IsType <ClientBullet>(co); } }