public void GamestateApplyMultiplePlayerPacketsTest() { short actorNumber = 1; GamestateCommitTestHelper <PlayerEntry> testHelper = new GamestateCommitTestHelper <PlayerEntry>(actorNumber); GamestateTable <PlayerEntry> players = testHelper.TestTable(GamestateTracker.Table.Players); GamestateRandomTestingUnit generator = new GamestateRandomTestingUnit(8); for (short i = 0; i < 100; i++) { PlayerEntry playerEntry = players.Create(i); generator.RandomisePlayerEntry(playerEntry); playerEntry.Commit(); GamestatePacket packet = testHelper.commitedPackets[0]; testHelper.Apply(packet); playerEntry = players.Get(i); GamestateAssertionUnit.AssertPacketApplied(playerEntry, packet); generator.RandomisePlayerEntry(playerEntry); playerEntry.Commit(); packet = testHelper.commitedPackets[1]; testHelper.Apply(packet); playerEntry = players.Get(i); GamestateAssertionUnit.AssertPacketApplied(playerEntry, packet); playerEntry.Release(); testHelper.commitedPackets.Clear(); } }
public void GamestateApplyTeamPacketErrorCallbackTest() { short actorNumber = 1; GamestateCommitTestHelper <TeamEntry> testHelper = new GamestateCommitTestHelper <TeamEntry>(actorNumber); GamestateTable <TeamEntry> teams = testHelper.TestTable(GamestateTracker.Table.Teams); GamestateRandomTestingUnit generator = new GamestateRandomTestingUnit(777); for (short i = 0; i < 100; i++) { TeamEntry teamEntry = teams.Create(i); generator.RandomiseTeamEntry(teamEntry); GamestatePacket packet = GamestatePacketManager.GetPacket(); bool errorCallbackCalled = false; teamEntry.Commit((TeamEntry entry, bool succeeded) => { Assert.That(succeeded, Is.EqualTo(true)); GamestateAssertionUnit.AssertPacketApplied(entry, packet); entry.Release(); errorCallbackCalled = true; }); packet = testHelper.commitedPackets[0]; testHelper.Apply(packet); Assert.That(errorCallbackCalled, Is.EqualTo(true)); testHelper.commitedPackets.Clear(); } }
public void GamestateApplyPlayerPacketListenerDeletionTest() { short actorNumber = 1; GamestateCommitTestHelper <PlayerEntry> testHelper = new GamestateCommitTestHelper <PlayerEntry>(actorNumber); GamestateTable <PlayerEntry> players = testHelper.TestTable(GamestateTracker.Table.Players); GamestateRandomTestingUnit generator = new GamestateRandomTestingUnit(12); for (short i = 0; i < 100; i++) { PlayerEntry playerEntry = players.Create(i); generator.RandomisePlayerEntry(playerEntry); GamestatePacket packet = GamestatePacketManager.GetPacket(); bool listenerACalled = false; bool listenerBCalled = false; bool listenerCCalled = false; bool listenerDCalled = false; int a = playerEntry.AddListener((PlayerEntry entry) => { entry.Release(); listenerACalled = true; }); int b = playerEntry.AddListener((PlayerEntry entry) => { entry.Release(); listenerBCalled = true; }); int c = playerEntry.AddListener((PlayerEntry entry) => { entry.Release(); listenerCCalled = true; }); playerEntry.RemoveListener(b); int d = playerEntry.AddListener((PlayerEntry entry) => { entry.Release(); listenerDCalled = true; }); playerEntry.RemoveListener(c); playerEntry.Commit(); packet = testHelper.commitedPackets[0]; testHelper.Apply(packet); Assert.That(listenerACalled, Is.EqualTo(true)); Assert.That(listenerBCalled, Is.EqualTo(false)); Assert.That(listenerCCalled, Is.EqualTo(false)); Assert.That(listenerDCalled, Is.EqualTo(true)); testHelper.commitedPackets.Clear(); } }
public void GamestateCreateTeamTest() { short id = -100; GamestateCommitTestHelper <TeamEntry> testHelper = new GamestateCommitTestHelper <TeamEntry>(1); GamestateTable <TeamEntry> teams = testHelper.TestTable(GamestateTracker.Table.Teams); TeamEntry teamEntry = teams.Create(id); Assert.That(teamEntry, Is.Not.Null); Assert.That(teamEntry.id, Is.EqualTo(id)); teamEntry.Commit(); testHelper.Apply(testHelper.commitedPackets[0]); Assert.That(teams.Get(id), Is.Not.Null); }
public void GamestateCreatePlayerTest() { short id = 7; GamestateCommitTestHelper <PlayerEntry> testHelper = new GamestateCommitTestHelper <PlayerEntry>(1); GamestateTable <PlayerEntry> players = testHelper.TestTable(GamestateTracker.Table.Players); PlayerEntry playerEntry = players.Create(id); Assert.That(playerEntry, Is.Not.Null); Assert.That(playerEntry.id, Is.EqualTo(id)); playerEntry.Commit(); testHelper.Apply(testHelper.commitedPackets[0]); Assert.That(players.Get(id), Is.Not.Null); }
public void GamestateApplyPlayerPacketMultipleErrorCallbacksTest() { short actorNumber = 1; GamestateCommitTestHelper <PlayerEntry> testHelper = new GamestateCommitTestHelper <PlayerEntry>(actorNumber); GamestateTable <PlayerEntry> players = testHelper.TestTable(GamestateTracker.Table.Players); GamestateRandomTestingUnit generator = new GamestateRandomTestingUnit(23); for (short i = 0; i < 100; i++) { PlayerEntry playerEntry = players.Create(i); generator.RandomisePlayerEntry(playerEntry); GamestatePacket packet = GamestatePacketManager.GetPacket(); bool errorCallbackACalled = false; bool errorCallbackBCalled = false; playerEntry.Commit((PlayerEntry entry, bool succeeded) => { Assert.That(succeeded, Is.EqualTo(true)); GamestateAssertionUnit.AssertPacketApplied(entry, packet); entry.Release(); errorCallbackACalled = true; }); playerEntry = players.Get(i); playerEntry.Commit((PlayerEntry entry, bool succeeded) => { Assert.That(succeeded, Is.EqualTo(false)); GamestateAssertionUnit.AssertPacketApplied(entry, packet); entry.Release(); errorCallbackBCalled = true; }); packet = testHelper.commitedPackets[0]; testHelper.Apply(packet); Assert.That(errorCallbackACalled, Is.EqualTo(true)); Assert.That(errorCallbackBCalled, Is.EqualTo(true)); testHelper.commitedPackets.Clear(); } }
public void GamestateApplyTeamPacketTest() { short actorNumber = 17; GamestateCommitTestHelper <TeamEntry> testHelper = new GamestateCommitTestHelper <TeamEntry>(actorNumber); GamestateTable <TeamEntry> teams = testHelper.TestTable(GamestateTracker.Table.Teams); GamestateRandomTestingUnit generator = new GamestateRandomTestingUnit(82); for (short i = 0; i < 100; i++) { TeamEntry teamEntry = teams.Create(i); generator.RandomiseTeamEntry(teamEntry); teamEntry.Commit(); GamestatePacket packet = testHelper.commitedPackets[0]; testHelper.Apply(packet); teamEntry = teams.Get(i); GamestateAssertionUnit.AssertPacketApplied(teamEntry, packet); teamEntry.Release(); testHelper.commitedPackets.Clear(); } }