コード例 #1
0
    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();
        }
    }