Пример #1
0
        public void TestGameLostWithTwoPlayingPlayers()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, false);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            game.Join(client2, false);
            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client3, true);
            game.StartGame(client1);
            callback1.Reset();
            callback2.Reset();
            callback3.Reset();

            game.GameLost(client2);
            FlushActionQueue();

            Assert.AreEqual(GameStates.WaitStartGame, game.State);
            Assert.AreEqual(ClientStates.WaitInGame, client1.State);
            Assert.AreEqual(ClientStates.GameLost, client2.State);
            Assert.AreEqual(ClientStates.WaitInGame, client3.State);
            Assert.AreEqual(1, callback1.GetCallCount("OnPlayerLost"));
            Assert.AreEqual(0, callback2.GetCallCount("OnPlayerLost"));
            Assert.AreEqual(1, callback3.GetCallCount("OnPlayerLost"));
            Assert.AreEqual(1, callback1.GetCallCount("OnGameFinished"));
            Assert.AreEqual(1, callback2.GetCallCount("OnGameFinished"));
            Assert.AreEqual(1, callback3.GetCallCount("OnGameFinished"));
            Assert.AreEqual(1, callback1.GetCallCount("OnWinListModified"));
            Assert.AreEqual(1, callback2.GetCallCount("OnWinListModified"));
            Assert.AreEqual(1, callback3.GetCallCount("OnWinListModified"));
            Assert.AreEqual(1, callback1.GetCallCount("OnPlayerWon"));
            Assert.AreEqual(1, callback2.GetCallCount("OnPlayerWon"));
            Assert.AreEqual(1, callback3.GetCallCount("OnPlayerWon"));
            //Assert.AreEqual(client1.Id, callback1.GetCallParameters("OnPlayerWon", 0)[0]);
        }
Пример #2
0
        public void TestLeavePlayingPlayerWhileGameStartedMultiplePlayingPlayerLeft()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource()); 
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, false);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            game.Join(client2, false);
            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client3, false);
            game.StartGame(client1);
            callback1.Reset();
            callback2.Reset();
            callback3.Reset();

            game.Leave(client2);

            Assert.AreEqual(GameStates.GameStarted, game.State);
            Assert.AreEqual(ClientStates.Playing, client1.State);
            Assert.AreEqual(ClientStates.Playing, client3.State);
            Assert.AreEqual(0, callback1.GetCallCount("OnGameFinished"));
            Assert.AreEqual(0, callback2.GetCallCount("OnGameFinished"));
            Assert.AreEqual(0, callback3.GetCallCount("OnGameFinished"));
            Assert.AreEqual(0, callback1.GetCallCount("OnWinListModified"));
            Assert.AreEqual(0, callback2.GetCallCount("OnWinListModified"));
            Assert.AreEqual(0, callback3.GetCallCount("OnWinListModified"));
        }
Пример #3
0
        public void TestGameLostWithOnePlayingPlayer()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, false);
            game.StartGame(client1);
            callback1.Reset();

            game.GameLost(client1);
            FlushActionQueue();

            Assert.AreEqual(GameStates.WaitStartGame, game.State);
            Assert.AreEqual(ClientStates.GameLost, client1.State);
            Assert.AreEqual(0, callback1.GetCallCount("OnPlayerLost"));
            Assert.AreEqual(1, callback1.GetCallCount("OnGameFinished"));
            Assert.AreEqual(0, callback1.GetCallCount("OnWinListModified"));
        }
Пример #4
0
        public void TestVoteKickCallbackCalled()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, false);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            game.Join(client2, false);
            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client3, false);
            CountCallTetriNETCallback callback4 = new CountCallTetriNETCallback();
            IClient client4 = CreateClient("client4", callback4);
            game.Join(client4, true);

            bool succeed = game.VoteKick(client1, client2, "reason");

            Assert.IsTrue(succeed);
            Assert.AreEqual(0, callback1.GetCallCount("OnVoteKickAsked")); // vote initiator automatically answers yes
            Assert.AreEqual(0, callback2.GetCallCount("OnVoteKickAsked")); // target is not warned
            Assert.AreEqual(1, callback3.GetCallCount("OnVoteKickAsked")); // other players are asked about vote
            Assert.AreEqual(0, callback4.GetCallCount("OnVoteKickAsked")); // spectators are not asked about vote
        }
Пример #5
0
        public void TestStopCallbackCalled()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, true);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            game.Join(client2, true);
            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client3, false);

            game.Stop();

            Assert.AreEqual(game.State, GameStates.Created);
            Assert.AreEqual(1, callback1.GetCallCount("OnGameLeft"));
            Assert.AreEqual(1, callback2.GetCallCount("OnGameLeft"));
            Assert.AreEqual(1, callback3.GetCallCount("OnGameLeft"));
        }
Пример #6
0
        public void TestJoinSpectatorOtherClientsInformed()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            game.Join(client1, true);
            game.Join(client2, false);

            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client3, true);

            Assert.AreEqual(2, callback1.GetCallCount("OnClientGameJoined"));
            Assert.AreEqual(1, callback2.GetCallCount("OnClientGameJoined"));
            Assert.AreEqual(0, callback3.GetCallCount("OnClientGameJoined"));
            Assert.AreEqual(1, callback1.GetCallCount("OnGameMasterModified"));
            Assert.AreEqual(0, callback2.GetCallCount("OnGameMasterModified"));
            Assert.AreEqual(0, callback3.GetCallCount("OnGameMasterModified"));
        }
Пример #7
0
        public void TestLeaveClientCallbackCalled()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client = CreateClient("client1", callback1);
            game.Join(client, true);

            game.Leave(client);

            Assert.AreEqual(1, callback1.GetCallCount("OnGameLeft"));
        }
Пример #8
0
        public void TestResumeGameFailedIfGameNotPaused()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, false);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            game.Join(client2, false);
            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client3, true);

            bool succeed = game.ResumeGame(client1);

            Assert.IsFalse(succeed);
            Assert.AreEqual(GameStates.WaitStartGame, game.State);
            Assert.AreEqual(0, callback1.GetCallCount("OnGamePaused"));
            Assert.AreEqual(0, callback1.GetCallCount("OnGamePaused"));
            Assert.AreEqual(0, callback1.GetCallCount("OnGamePaused"));
        }
Пример #9
0
        public void TestResumeGameStatusUpdatedAndCallbacksCalled()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, false);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            game.Join(client2, false);
            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client3, true);
            game.StartGame(client1);
            game.PauseGame(client1);

            bool succeed = game.ResumeGame(client1);

            Assert.IsTrue(succeed);
            Assert.AreEqual(GameStates.GameStarted, game.State);
            Assert.AreEqual(1, callback1.GetCallCount("OnGameResumed"));
            Assert.AreEqual(1, callback2.GetCallCount("OnGameResumed"));
            Assert.AreEqual(1, callback3.GetCallCount("OnGameResumed"));
        }
Пример #10
0
        public void TestEarnAchievementCallbacksCalled()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, false);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            game.Join(client2, false);
            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client3, true);
            game.StartGame(client1);

            game.EarnAchievement(client1, 5, "achievement");
            FlushActionQueue();

            Assert.AreEqual(0, callback1.GetCallCount("OnAchievementEarned"));
            Assert.AreEqual(1, callback2.GetCallCount("OnAchievementEarned"));
            Assert.AreEqual(1, callback3.GetCallCount("OnAchievementEarned"));
        }
Пример #11
0
        public void TestStopGameStatusUpdatedAndCallbackCalledIfGameStarted()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, false);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            game.Join(client2, true);
            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client3, false);
            game.StartGame(client1);

            bool succeed = game.StopGame(client1);

            Assert.IsTrue(succeed);
            Assert.AreEqual(GameStates.WaitStartGame, game.State);
            Assert.AreEqual(1, callback1.GetCallCount("OnGameFinished"));
            Assert.AreEqual(1, callback2.GetCallCount("OnGameFinished"));
            Assert.AreEqual(1, callback3.GetCallCount("OnGameFinished"));
            Assert.AreEqual(ClientStates.WaitInGame, client1.State);
            Assert.AreEqual(ClientStates.WaitInGame, client2.State);
            Assert.AreEqual(ClientStates.WaitInGame, client3.State);
        }
Пример #12
0
        public void TestFinishContinuousSpecialActionCallbacksCalled()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, false);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            game.Join(client2, false);
            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client3, true);
            game.StartGame(client1);

            game.FinishContinuousSpecial(client1, Specials.Darkness);
            FlushActionQueue();

            Assert.AreEqual(0, callback1.GetCallCount("OnContinuousSpecialFinished"));
            Assert.AreEqual(1, callback2.GetCallCount("OnContinuousSpecialFinished"));
            Assert.AreEqual(1, callback3.GetCallCount("OnContinuousSpecialFinished"));
        }
Пример #13
0
        public void TestClearLinesActionCallbacksCalled()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, false);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            game.Join(client2, false);
            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client3, true);
            game.StartGame(client1);

            game.ModifyGrid(client1, null);
            FlushActionQueue();

            Assert.AreEqual(0, callback1.GetCallCount("OnGridModified"));
            Assert.AreEqual(1, callback2.GetCallCount("OnGridModified"));
            Assert.AreEqual(1, callback3.GetCallCount("OnGridModified"));
        }
Пример #14
0
        public void TestUseSpecialSwitchFieldsActionCallbacksCalled()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, false);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            game.Join(client2, false);
            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client3, false);
            game.StartGame(client1);

            game.UseSpecial(client1, client2, Specials.SwitchFields);
            FlushActionQueue();

            Assert.AreEqual(1, callback1.GetCallCount("OnSpecialUsed"));
            Assert.AreEqual(1, callback2.GetCallCount("OnSpecialUsed"));
            Assert.AreEqual(1, callback3.GetCallCount("OnSpecialUsed"));
            Assert.AreEqual(1, callback1.GetCallCount("OnGridModified"));
            Assert.AreEqual(1, callback2.GetCallCount("OnGridModified"));
            Assert.AreEqual(0, callback3.GetCallCount("OnGridModified"));
        }
Пример #15
0
        public void TestGameLostWithMultiplePlayingPlayer()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, false);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            game.Join(client2, false);
            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client3, false);
            game.StartGame(client1);
            callback1.Reset();
            callback2.Reset();
            callback3.Reset();

            game.GameLost(client2);
            FlushActionQueue();

            Assert.AreEqual(GameStates.GameStarted, game.State);
            Assert.AreEqual(ClientStates.Playing, client1.State);
            Assert.AreEqual(ClientStates.GameLost, client2.State);
            Assert.AreEqual(ClientStates.Playing, client3.State);
            Assert.AreEqual(1, callback1.GetCallCount("OnPlayerLost"));
            Assert.AreEqual(0, callback2.GetCallCount("OnPlayerLost"));
            Assert.AreEqual(1, callback3.GetCallCount("OnPlayerLost"));
        }
Пример #16
0
        public void TestChangeOptionsClientsInformed()
        {
            GameOptions originalOptions = new GameOptions();
            originalOptions.Initialize(GameRules.Custom);
            IGame game = CreateGame("game1", 5, 10, GameRules.Custom, originalOptions);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, false);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            game.Join(client2, true);
            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client3, false);

            GameOptions newOptions = new GameOptions();
            newOptions.Initialize(GameRules.Custom);
            game.ChangeOptions(client1, newOptions);

            Assert.AreEqual(1, callback1.GetCallCount("OnGameOptionsChanged"));
            Assert.AreEqual(1, callback2.GetCallCount("OnGameOptionsChanged"));
            Assert.AreEqual(1, callback3.GetCallCount("OnGameOptionsChanged"));
        }
Пример #17
0
        public void TestJoinSpectatorCallbackCalled()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback = new CountCallTetriNETCallback();
            IClient client = CreateClient("client1", callback);

            game.Join(client, true);

            Assert.AreEqual(1, callback.GetCallCount("OnGameJoined"));
        }
Пример #18
0
        public void TestResetWinListClientsInformed()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, false);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            game.Join(client2, false);
            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client3, false);

            game.ResetWinList(client1);

            Assert.AreEqual(1, callback1.GetCallCount("OnWinListModified"));
            Assert.AreEqual(1, callback2.GetCallCount("OnWinListModified"));
            Assert.AreEqual(1, callback3.GetCallCount("OnWinListModified"));
        }
Пример #19
0
        public void TestLeavePlayerChangeGameMaster()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client1, false);
            game.Join(client2, false);
            game.Join(client3, true);

            bool succeed = game.Leave(client1);

            Assert.IsTrue(succeed);
            Assert.AreEqual(2, game.ClientCount);
            Assert.AreEqual(1, game.PlayerCount);
            Assert.AreEqual(1, game.SpectatorCount);
            Assert.AreEqual(client2, game.Clients.First());
            Assert.IsFalse(client1.IsGameMaster);
            Assert.IsTrue(client2.IsGameMaster);
            Assert.AreEqual(0, callback1.GetCallCount("OnGameMasterModified"));
            Assert.AreEqual(1, callback2.GetCallCount("OnGameMasterModified"));
            Assert.AreEqual(1, callback3.GetCallCount("OnGameMasterModified"));
        }
Пример #20
0
        public void TestResetWinListFailedIfNotWaitingGameStart()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, false);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            game.Join(client2, false);
            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client3, false);
            game.StartGame(client1);

            bool succeed = game.ResetWinList(client1);

            Assert.AreEqual(0, callback1.GetCallCount("OnWinListModified"));
            Assert.IsFalse(succeed);
        }
Пример #21
0
        public void TestLeaveClientOtherClientsInformed()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, true);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            game.Join(client2, true);
            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client3, false);

            game.Leave(client1);

            Assert.AreEqual(1, callback2.GetCallCount("OnClientGameLeft"));
            Assert.AreEqual(1, callback3.GetCallCount("OnClientGameLeft"));
        }
Пример #22
0
        public void TestJoinSpectatorWhileGameStarted()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource()); 
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, false);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            game.Join(client2, false);
            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client3, true);
            game.StartGame(client1);
            callback1.Reset();
            callback2.Reset();
            callback3.Reset();

            CountCallTetriNETCallback callback4 = new CountCallTetriNETCallback();
            IClient client4 = CreateClient("client4", callback4);
            game.Join(client4, true);

            Assert.AreEqual(ClientStates.WaitInGame, client4.State);
            Assert.AreEqual(ClientRoles.Spectator, client4.Roles);
            Assert.AreEqual(1, callback1.GetCallCount("OnClientGameJoined"));
            Assert.AreEqual(1, callback2.GetCallCount("OnClientGameJoined"));
            Assert.AreEqual(1, callback3.GetCallCount("OnClientGameJoined"));
            Assert.AreEqual(1, callback4.GetCallCount("OnGameJoined"));
        }
Пример #23
0
        public void TestVoteKickTimeout()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, false);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            game.Join(client2, false);
            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client3, false);

            game.VoteKick(client1, client2, "reason");
            Thread.Sleep(10500);

            Assert.IsNull(client1.LastVoteKickAnswer);
            Assert.IsNull(client2.LastVoteKickAnswer);
            Assert.IsNull(client3.LastVoteKickAnswer);
            Assert.AreEqual(0, callback1.GetCallCount("OnClientGameLeft"));
            Assert.AreEqual(0, callback2.GetCallCount("OnGameLeft"));
            Assert.AreEqual(0, callback3.GetCallCount("OnClientGameLeft"));
        }
Пример #24
0
        public void TestVoteKickAnswerLastToAnswerKicked()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, false);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            game.Join(client2, false);
            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client3, false);
            CountCallTetriNETCallback callback4 = new CountCallTetriNETCallback();
            IClient client4 = CreateClient("client4", callback4);
            game.Join(client4, false);
            game.VoteKick(client1, client2, "reason");
            game.VoteKickAnswer(client4, true);

            bool succeed = game.VoteKickAnswer(client3, true);

            Assert.IsTrue(succeed);
            Assert.IsNull(client1.LastVoteKickAnswer);
            Assert.IsNull(client2.LastVoteKickAnswer);
            Assert.IsNull(client3.LastVoteKickAnswer);
            Assert.IsNull(client4.LastVoteKickAnswer);
            Assert.AreEqual(1, callback1.GetCallCount("OnClientGameLeft"));
            Assert.AreEqual(1, callback2.GetCallCount("OnGameLeft"));
            Assert.AreEqual(1, callback3.GetCallCount("OnClientGameLeft"));
            Assert.AreEqual(1, callback4.GetCallCount("OnClientGameLeft"));
        }