Пример #1
0
        public void PlayersGetsNotificationWhenGameSessionIsReadyToLaunch()
        {
            Jabberwocky.SoC.Service.GameSessionManager gameSessionManager = null;
            try
            {
                // Arrange
                var testPlayer1Data = new Jabberwocky.SoC.Service.PlayerData(TestPlayer1UserName);
                var testPlayer2Data = new Jabberwocky.SoC.Service.PlayerData(TestPlayer2UserName);
                var testPlayer3Data = new Jabberwocky.SoC.Service.PlayerData(TestPlayer3UserName);
                var testPlayer4Data = new Jabberwocky.SoC.Service.PlayerData(TestPlayer4UserName);

                var mockPlayerCardRepository = this.CreateMockPlayerCardRepository(
                    testPlayer1Data,
                    testPlayer2Data,
                    testPlayer3Data,
                    testPlayer4Data);

                gameSessionManager = GameSessionManagerTestExtensions.CreateGameSessionManagerForTest(4)
                                     .AddPlayerCardRepository(mockPlayerCardRepository)
                                     .WaitUntilGameSessionManagerHasStarted();

                var testPlayer1 = new TestClient(TestPlayer1UserName, gameSessionManager);
                var testPlayer2 = new TestClient(TestPlayer2UserName, gameSessionManager);
                var testPlayer3 = new TestClient(TestPlayer3UserName, gameSessionManager);
                var testPlayer4 = new TestClient(TestPlayer4UserName, gameSessionManager);

                // Act & Assert
                var testScript = new TestScript(testPlayer1, testPlayer2, testPlayer3, testPlayer4);
                testScript.RunUntil(TestScript.RunPoints.RunUntilClientsReceiveGameSessionReadyToLaunchMessage);
            }
            finally
            {
                gameSessionManager?.WaitUntilGameSessionManagerHasStopped();
            }
        }
Пример #2
0
        public void PlayerReceivesConfirmationOnceJoinedToGameSession()
        {
            // Arrange
            Jabberwocky.SoC.Service.GameSessionManager gameSessionManager = null;
            try
            {
                gameSessionManager = GameSessionManagerTestExtensions.CreateGameSessionManagerForTest(4)
                                     .WaitUntilGameSessionManagerHasStarted();

                var testPlayer1 = new TestClient(TestPlayer1UserName, gameSessionManager);
                var testScript  = new TestScript(testPlayer1);

                // Act
                testScript.AllClientsJoinGame();
                testScript.WaitUntilClientsReceiveMessageOfType(typeof(ConfirmGameJoinedMessage), testPlayer1);

                // Assert
                var receivedMessage = testPlayer1.GetLastMessage();
                receivedMessage.ShouldBeOfType <ConfirmGameJoinedMessage>();
                ((ConfirmGameJoinedMessage)receivedMessage).GameState.ShouldBe(Jabberwocky.SoC.Service.GameSessionManager.GameStates.Lobby);
            }
            finally
            {
                gameSessionManager?.WaitUntilGameSessionManagerHasStopped();
            }
        }
Пример #3
0
        public void SubsequentGameInitializationConfirminationMessagesAreIgnored()
        {
            Jabberwocky.SoC.Service.GameSessionManager gameSessionManager = null;
            try
            {
                // Arrange
                var mockLogger        = Substitute.For <ILogger>();
                var mockLoggerFactory = Substitute.For <ILoggerFactory>();
                mockLoggerFactory.Create(Arg.Any <String>()).Returns(mockLogger);

                gameSessionManager = GameSessionManagerTestExtensions.CreateGameSessionManagerForTest(4)
                                     .AddLoggerFactory(mockLoggerFactory)
                                     .WaitUntilGameSessionManagerHasStarted();

                var testPlayer1 = new TestClient(TestPlayer1UserName, gameSessionManager);
                var testPlayer2 = new TestClient(TestPlayer2UserName, gameSessionManager);
                var testPlayer3 = new TestClient(TestPlayer3UserName, gameSessionManager);
                var testPlayer4 = new TestClient(TestPlayer4UserName, gameSessionManager);

                // Act
                var testScript = new TestScript(testPlayer1, testPlayer2, testPlayer3, testPlayer4);
                testScript.RunUntil(TestScript.RunPoints.RunUntilEnd);
                testScript.SendGameInitializationConfirmationFromClients(testPlayer1, testPlayer2, testPlayer3, testPlayer4);

                testScript.WaitUntilAllClientsReceiveMessageOfType(typeof(GameOverMessage));
                mockLogger.DidNotReceive().Exception(Arg.Any <String>());
            }
            finally
            {
                gameSessionManager?.WaitUntilGameSessionManagerHasStopped();
            }
        }
Пример #4
0
        public void WhenNamedClientDropsOutOfGameSessionBeforeLaunchOtherClientsAreNotified()
        {
            Jabberwocky.SoC.Service.GameSessionManager gameSessionManager = null;
            try
            {
                var expectedMessageForTestPlayer1 = new PlayerHasLeftGameMessage();
                var expectedMessageForTestPlayer2 = new OtherPlayerHasLeftGameMessage(TestPlayer1UserName);

                var testPlayer1Data = new Jabberwocky.SoC.Service.PlayerData(TestPlayer1UserName);

                var mockPlayerCardRepository = this.CreateMockPlayerCardRepository(testPlayer1Data);

                gameSessionManager = GameSessionManagerTestExtensions.CreateGameSessionManagerForTest(4)
                                     .AddPlayerCardRepository(mockPlayerCardRepository)
                                     .WaitUntilGameSessionManagerHasStarted();

                var testPlayer1 = new TestClient(TestPlayer1UserName, gameSessionManager);
                var testPlayer2 = new TestClient(TestPlayer2UserName, gameSessionManager);

                var testScript = new TestScript(testPlayer1, testPlayer2);
                testScript.AllClientsJoinGame();
                testScript.WaitUntilClientsReceiveMessageOfType(typeof(PlayerDataReceivedMessage), testPlayer1, testPlayer2);

                // Act
                testPlayer1.LeaveGame();

                // Assert
                testScript.WaitUntilClientsReceiveMessage(expectedMessageForTestPlayer1, testPlayer1);
                testScript.WaitUntilClientsReceiveMessage(expectedMessageForTestPlayer2, testPlayer2);
            }
            finally
            {
                gameSessionManager?.WaitUntilGameSessionManagerHasStopped();
            }
        }
Пример #5
0
        public void SameClientCannotBeAddedAsLastMemberOfGameSession()
        {
            Jabberwocky.SoC.Service.GameSessionManager gameSessionManager = null;
            try
            {
                Guid expectedSessionToken = Guid.NewGuid();
                Guid otherSessionToken    = Guid.NewGuid();

                var mockGameSessionTokenFactory = NSubstitute.Substitute.For <IGameSessionTokenFactory>();
                mockGameSessionTokenFactory.CreateGameSessionToken().Returns(expectedSessionToken, otherSessionToken);

                gameSessionManager = GameSessionManagerTestExtensions.CreateGameSessionManagerForTest(4)
                                     .AddGameSessionTokenFactory(mockGameSessionTokenFactory)
                                     .WaitUntilGameSessionManagerHasStarted();

                var testPlayer1 = new TestClient(TestPlayer1UserName, gameSessionManager);
                var testPlayer2 = new TestClient(TestPlayer2UserName, gameSessionManager);
                var testPlayer3 = new TestClient(TestPlayer3UserName, gameSessionManager);

                // Act - Attempt to add the same client as the last member to the game session.
                var testScript = new TestScript(testPlayer1, testPlayer2, testPlayer3, testPlayer1);
                testScript.AllClientsJoinGame();
                testScript.WaitUntilClientsReceiveMessageOfType(typeof(PlayerDataReceivedMessage), testPlayer1, testPlayer2, testPlayer3);

                // Assert
                testPlayer1.GameToken.ShouldBe(expectedSessionToken);
                testPlayer2.GameToken.ShouldBe(expectedSessionToken);
                testPlayer3.GameToken.ShouldBe(expectedSessionToken);
            }
            finally
            {
                gameSessionManager?.WaitUntilGameSessionManagerHasStopped();
            }
        }
Пример #6
0
        public void AllClientsReceivePlayerCardsForAllClientsInGameSession()
        {
            Jabberwocky.SoC.Service.GameSessionManager gameSessionManager = null;
            try
            {
                // Arrange
                var testPlayer1Data = new Jabberwocky.SoC.Service.PlayerData(TestPlayer1UserName);
                var testPlayer2Data = new Jabberwocky.SoC.Service.PlayerData(TestPlayer2UserName);
                var testPlayer3Data = new Jabberwocky.SoC.Service.PlayerData(TestPlayer3UserName);
                var testPlayer4Data = new Jabberwocky.SoC.Service.PlayerData(TestPlayer4UserName);

                var mockPlayerCardRepository = this.CreateMockPlayerCardRepository(
                    testPlayer1Data,
                    testPlayer2Data,
                    testPlayer3Data,
                    testPlayer4Data);

                gameSessionManager = GameSessionManagerTestExtensions.CreateGameSessionManagerForTest(4)
                                     .AddPlayerCardRepository(mockPlayerCardRepository)
                                     .WaitUntilGameSessionManagerHasStarted();

                var testPlayer1 = new TestClient(TestPlayer1UserName, gameSessionManager);
                var testPlayer2 = new TestClient(TestPlayer2UserName, gameSessionManager);
                var testPlayer3 = new TestClient(TestPlayer3UserName, gameSessionManager);
                var testPlayer4 = new TestClient(TestPlayer4UserName, gameSessionManager);

                // Act
                var testScript = new TestScript(testPlayer1, testPlayer2, testPlayer3, testPlayer4);
                testScript.RunUntil(TestScript.RunPoints.RunUntilClientsReceiveGameSessionReadyToLaunchMessage);

                // Assert
                testPlayer1.ContainMessagesInOrder(1,
                                                   new PlayerDataReceivedMessage(testPlayer2Data),
                                                   new PlayerDataReceivedMessage(testPlayer3Data),
                                                   new PlayerDataReceivedMessage(testPlayer4Data));

                testPlayer2.ContainMessagesInOrder(1,
                                                   new PlayerDataReceivedMessage(testPlayer1Data),
                                                   new PlayerDataReceivedMessage(testPlayer3Data),
                                                   new PlayerDataReceivedMessage(testPlayer4Data));

                testPlayer3.ContainMessagesInOrder(1,
                                                   new PlayerDataReceivedMessage(testPlayer1Data),
                                                   new PlayerDataReceivedMessage(testPlayer2Data),
                                                   new PlayerDataReceivedMessage(testPlayer4Data));

                testPlayer4.ContainMessagesInOrder(1,
                                                   new PlayerDataReceivedMessage(testPlayer1Data),
                                                   new PlayerDataReceivedMessage(testPlayer2Data),
                                                   new PlayerDataReceivedMessage(testPlayer3Data));
            }
            finally
            {
                gameSessionManager?.WaitUntilGameSessionManagerHasStopped();
            }
        }
Пример #7
0
        public void GameManagerReceivesCorrectMessagesWhenPlacingFirstTown(UInt32[] townLocations)
        {
            Jabberwocky.SoC.Service.GameSessionManager gameSessionManager = null;
            try
            {
                var board           = new GameBoardManager(BoardSizes.Standard);
                var mockGameManager = Substitute.For <IGameSession>();
                mockGameManager.GetFirstSetupPassOrder().Returns(new UInt32[] { 0u, 1u, 2u, 3u });
                mockGameManager.Board.Returns(board);

                var mockGameManagerFactory = Substitute.For <IGameSessionManager>();
                mockGameManagerFactory.Create().Returns(mockGameManager);

                var mockLogger        = Substitute.For <ILogger>();
                var mockLoggerFactory = Substitute.For <ILoggerFactory>();
                mockLoggerFactory.Create(Arg.Any <String>()).Returns(mockLogger);

                gameSessionManager = GameSessionManagerTestExtensions.CreateGameSessionManagerForTest(4)
                                     .AddGameManagerFactory(mockGameManagerFactory)
                                     .AddLoggerFactory(mockLoggerFactory)
                                     .WaitUntilGameSessionManagerHasStarted();

                var testPlayer1 = new TestClient(TestPlayer1UserName, gameSessionManager);
                var testPlayer2 = new TestClient(TestPlayer2UserName, gameSessionManager);
                var testPlayer3 = new TestClient(TestPlayer3UserName, gameSessionManager);
                var testPlayer4 = new TestClient(TestPlayer4UserName, gameSessionManager);

                var testScript = new TestScript(testPlayer1, testPlayer2, testPlayer3, testPlayer4);
                testScript.RunUntil(TestScript.RunPoints.RunUntilEnd);
                testScript.WaitUntilClientsReceiveMessageOfType(typeof(PlaceTownMessage), testPlayer1);
                testScript.SendTownPlacementFromClient(testPlayer1, townLocations[0]);

                testScript.WaitUntilClientsReceiveMessageOfType(typeof(PlaceTownMessage), testPlayer2);
                mockGameManager.Received().PlaceTown(townLocations[0]);
                testScript.SendTownPlacementFromClient(testPlayer2, townLocations[1]);

                testScript.WaitUntilClientsReceiveMessageOfType(typeof(PlaceTownMessage), testPlayer3);
                mockGameManager.Received().PlaceTown(townLocations[1]);
                testScript.SendTownPlacementFromClient(testPlayer3, townLocations[2]);

                testScript.WaitUntilClientsReceiveMessageOfType(typeof(PlaceTownMessage), testPlayer4);
                mockGameManager.Received().PlaceTown(townLocations[2]);
                testScript.SendTownPlacementFromClient(testPlayer4, townLocations[3]);

                testScript.WaitUntilClientsReceiveMessageOfType(typeof(GameOverMessage), testPlayer1, testPlayer2, testPlayer3, testPlayer4);
                mockGameManager.Received().PlaceTown(townLocations[3]);
                mockLogger.DidNotReceive().Exception(Arg.Any <String>());
            }
            finally
            {
                gameSessionManager?.WaitUntilGameSessionManagerHasStopped();
            }
        }
Пример #8
0
        public void ClientsReceivePlaceTownMessageInCorrectOrder(UInt32[] firstSetupPassOrder)
        {
            Jabberwocky.SoC.Service.GameSessionManager gameSessionManager = null;
            try
            {
                var board           = new GameBoardManager(BoardSizes.Standard);
                var mockGameManager = Substitute.For <IGameSession>();
                mockGameManager.GetFirstSetupPassOrder().Returns(firstSetupPassOrder);
                mockGameManager.Board.Returns(board);

                var mockGameManagerFactory = Substitute.For <IGameSessionManager>();
                mockGameManagerFactory.Create().Returns(mockGameManager);

                gameSessionManager = GameSessionManagerTestExtensions.CreateGameSessionManagerForTest(4)
                                     .AddGameManagerFactory(mockGameManagerFactory)
                                     .WaitUntilGameSessionManagerHasStarted();

                var testPlayers = new[]
                {
                    new TestClient(TestPlayer1UserName, gameSessionManager),
                    new TestClient(TestPlayer2UserName, gameSessionManager),
                    new TestClient(TestPlayer3UserName, gameSessionManager),
                    new TestClient(TestPlayer4UserName, gameSessionManager)
                };

                var testPlayer1 = testPlayers[0];
                var testPlayer2 = testPlayers[1];
                var testPlayer3 = testPlayers[2];
                var testPlayer4 = testPlayers[3];

                var firstTestPlayer  = testPlayers[firstSetupPassOrder[0]];
                var secondTestPlayer = testPlayers[firstSetupPassOrder[1]];
                var thirdTestPlayer  = testPlayers[firstSetupPassOrder[2]];
                var fourthTestPlayer = testPlayers[firstSetupPassOrder[3]];

                var testScript = new TestScript(testPlayer1, testPlayer2, testPlayer3, testPlayer4);
                testScript.RunUntil(TestScript.RunPoints.RunUntilEnd);
                testScript.WaitUntilClientsReceiveMessageOfType(typeof(PlaceTownMessage), firstTestPlayer);
                testScript.SendTownPlacementFromClient(firstTestPlayer, 0u);
                testScript.WaitUntilClientsReceiveMessageOfType(typeof(PlaceTownMessage), secondTestPlayer);
                testScript.SendTownPlacementFromClient(secondTestPlayer, 10u);
                testScript.WaitUntilClientsReceiveMessageOfType(typeof(PlaceTownMessage), thirdTestPlayer);
                testScript.SendTownPlacementFromClient(thirdTestPlayer, 20u);
                testScript.WaitUntilClientsReceiveMessageOfType(typeof(PlaceTownMessage), fourthTestPlayer);
            }
            finally
            {
                gameSessionManager.WaitUntilGameSessionManagerHasStopped();
            }
        }
Пример #9
0
        public void AllClientsReceiveBoardDataWhenGameSessionIsLaunched()
        {
            Jabberwocky.SoC.Service.GameSessionManager gameSessionManager = null;
            try
            {
                // Arrange
                var testPlayer1Data = new Jabberwocky.SoC.Service.PlayerData(TestPlayer1UserName);
                var testPlayer2Data = new Jabberwocky.SoC.Service.PlayerData(TestPlayer2UserName);
                var testPlayer3Data = new Jabberwocky.SoC.Service.PlayerData(TestPlayer3UserName);
                var testPlayer4Data = new Jabberwocky.SoC.Service.PlayerData(TestPlayer4UserName);

                var mockPlayerCardRepository = this.CreateMockPlayerCardRepository(
                    testPlayer1Data,
                    testPlayer2Data,
                    testPlayer3Data,
                    testPlayer4Data);

                gameSessionManager = GameSessionManagerTestExtensions.CreateGameSessionManagerForTest(4)
                                     .AddPlayerCardRepository(mockPlayerCardRepository)
                                     .WaitUntilGameSessionManagerHasStarted();

                var testPlayer1 = new TestClient(TestPlayer1UserName, gameSessionManager);
                var testPlayer2 = new TestClient(TestPlayer2UserName, gameSessionManager);
                var testPlayer3 = new TestClient(TestPlayer3UserName, gameSessionManager);
                var testPlayer4 = new TestClient(TestPlayer4UserName, gameSessionManager);

                var gameInitializationData = GameInitializationDataBuilder.Build(new GameBoardManager(BoardSizes.Standard));
                var expectedMessage        = new InitializeGameMessage(gameInitializationData);

                // Act
                var testScript = new TestScript(testPlayer1, testPlayer2, testPlayer3, testPlayer4);
                testScript.RunUntil(TestScript.RunPoints.RunUntilClientsReceiveGameInitializationMessage);

                // Assert
                testPlayer1.GetLastMessage().IsSameAs(expectedMessage);
                testPlayer2.GetLastMessage().IsSameAs(expectedMessage);
                testPlayer3.GetLastMessage().IsSameAs(expectedMessage);
                testPlayer4.GetLastMessage().IsSameAs(expectedMessage);
            }
            finally
            {
                gameSessionManager?.WaitUntilGameSessionManagerHasStopped();
            }
        }
Пример #10
0
        public void ClientsReceivePersonalMessageFromClientOnceGameSessionIsLaunched()
        {
            Jabberwocky.SoC.Service.GameSessionManager gameSessionManager = null;
            try
            {
                // Arrange
                var testPlayer1Data = new Jabberwocky.SoC.Service.PlayerData(TestPlayer1UserName);
                var testPlayer2Data = new Jabberwocky.SoC.Service.PlayerData(TestPlayer2UserName);
                var testPlayer3Data = new Jabberwocky.SoC.Service.PlayerData(TestPlayer3UserName);
                var testPlayer4Data = new Jabberwocky.SoC.Service.PlayerData(TestPlayer4UserName);

                var mockPlayerCardRepository = this.CreateMockPlayerCardRepository(
                    testPlayer1Data,
                    testPlayer2Data,
                    testPlayer3Data,
                    testPlayer4Data);

                gameSessionManager = GameSessionManagerTestExtensions.CreateGameSessionManagerForTest(4)
                                     .AddPlayerCardRepository(mockPlayerCardRepository)
                                     .WaitUntilGameSessionManagerHasStarted();

                var testPlayer1 = new TestClient(TestPlayer1UserName, gameSessionManager);
                var testPlayer2 = new TestClient(TestPlayer2UserName, gameSessionManager);
                var testPlayer3 = new TestClient(TestPlayer3UserName, gameSessionManager);
                var testPlayer4 = new TestClient(TestPlayer4UserName, gameSessionManager);

                var testScript = new TestScript(testPlayer1, testPlayer2, testPlayer3, testPlayer4);
                testScript.RunUntil(TestScript.RunPoints.RunUntilClientsReceiveGameInitializationMessage);

                var messageText     = "Hello There";
                var expectedMessage = new PersonalMessage(TestPlayer1UserName, messageText);

                // Act
                testPlayer1.SendPersonalMessage(messageText);

                // Assert
                testScript.WaitUntilClientsReceiveMessage(expectedMessage, testPlayer2, testPlayer3, testPlayer4);
            }
            finally
            {
                gameSessionManager?.WaitUntilGameSessionManagerHasStopped();
            }
        }
Пример #11
0
        public void AllClientsReceiveSameGameTokenWhenJoinedToSameGame()
        {
            Jabberwocky.SoC.Service.GameSessionManager gameSessionManager = null;
            try
            {
                // Arrange
                var testPlayer1Data = new Jabberwocky.SoC.Service.PlayerData(TestPlayer1UserName);
                var testPlayer2Data = new Jabberwocky.SoC.Service.PlayerData(TestPlayer2UserName);
                var testPlayer3Data = new Jabberwocky.SoC.Service.PlayerData(TestPlayer3UserName);
                var testPlayer4Data = new Jabberwocky.SoC.Service.PlayerData(TestPlayer4UserName);

                var mockPlayerCardRepository = this.CreateMockPlayerCardRepository(
                    testPlayer1Data,
                    testPlayer2Data,
                    testPlayer3Data,
                    testPlayer4Data);

                gameSessionManager = GameSessionManagerTestExtensions.CreateGameSessionManagerForTest(4)
                                     .AddPlayerCardRepository(mockPlayerCardRepository)
                                     .WaitUntilGameSessionManagerHasStarted();

                var testPlayer1 = new TestClient(TestPlayer1UserName, gameSessionManager);
                var testPlayer2 = new TestClient(TestPlayer2UserName, gameSessionManager);
                var testPlayer3 = new TestClient(TestPlayer3UserName, gameSessionManager);
                var testPlayer4 = new TestClient(TestPlayer4UserName, gameSessionManager);

                // Act
                var testScript = new TestScript(testPlayer1, testPlayer2, testPlayer3, testPlayer4);
                testScript.RunUntil(TestScript.RunPoints.RunUntilClientsReceiveGameSessionReadyToLaunchMessage);

                // Assert
                testPlayer1.GameToken.ShouldNotBe(Guid.Empty);
                (testPlayer1.GameToken == testPlayer2.GameToken &&
                 testPlayer2.GameToken == testPlayer3.GameToken &&
                 testPlayer3.GameToken == testPlayer4.GameToken).ShouldBeTrue();
            }
            finally
            {
                gameSessionManager?.WaitUntilGameSessionManagerHasStopped();
            }
        }
Пример #12
0
        public void WhenNamedClientDropsOutOfGameSessionAfterLaunchOtherClientsAreNotified()
        {
            Jabberwocky.SoC.Service.GameSessionManager gameSessionManager = null;
            try
            {
                var expectedMessageForTestPlayer1      = new PlayerHasLeftGameMessage();
                var expectedMessageForOtherTestPlayers = new OtherPlayerHasLeftGameMessage(TestPlayer1UserName);

                var testPlayer1Data = new Jabberwocky.SoC.Service.PlayerData(TestPlayer1UserName);
                var testPlayer2Data = new Jabberwocky.SoC.Service.PlayerData(TestPlayer2UserName);
                var testPlayer3Data = new Jabberwocky.SoC.Service.PlayerData(TestPlayer3UserName);
                var testPlayer4Data = new Jabberwocky.SoC.Service.PlayerData(TestPlayer4UserName);

                var mockPlayerCardRepository = this.CreateMockPlayerCardRepository(testPlayer1Data, testPlayer2Data, testPlayer3Data, testPlayer4Data);

                gameSessionManager = GameSessionManagerTestExtensions.CreateGameSessionManagerForTest(4)
                                     .AddPlayerCardRepository(mockPlayerCardRepository)
                                     .WaitUntilGameSessionManagerHasStarted();

                var testPlayer1 = new TestClient(TestPlayer1UserName, gameSessionManager);
                var testPlayer2 = new TestClient(TestPlayer2UserName, gameSessionManager);
                var testPlayer3 = new TestClient(TestPlayer3UserName, gameSessionManager);
                var testPlayer4 = new TestClient(TestPlayer4UserName, gameSessionManager);

                var testScript = new TestScript(testPlayer1, testPlayer2, testPlayer3, testPlayer4);
                testScript.RunUntil(TestScript.RunPoints.RunUntilClientsReceiveGameInitializationMessage);

                // Act
                testPlayer1.LeaveGame();

                // Assert
                testScript.WaitUntilClientsReceiveMessage(expectedMessageForTestPlayer1, testPlayer1);
                testScript.WaitUntilClientsReceiveMessage(expectedMessageForOtherTestPlayers, testPlayer2, testPlayer3, testPlayer4);
            }
            finally
            {
                gameSessionManager?.WaitUntilGameSessionManagerHasStopped();
            }
        }
Пример #13
0
        public void ClientReceivesPersonalMessageFromAnotherClientBeforeGameSessionIsLaunched()
        {
            Jabberwocky.SoC.Service.GameSessionManager gameSessionManager = null;
            try
            {
                // Arrange
                var testPlayer1Data = new Jabberwocky.SoC.Service.PlayerData(TestPlayer1UserName);
                var testPlayer2Data = new Jabberwocky.SoC.Service.PlayerData(TestPlayer2UserName);

                var mockPlayerCardRepository = this.CreateMockPlayerCardRepository(
                    testPlayer1Data,
                    testPlayer2Data);

                gameSessionManager = GameSessionManagerTestExtensions.CreateGameSessionManagerForTest(4)
                                     .AddPlayerCardRepository(mockPlayerCardRepository)
                                     .WaitUntilGameSessionManagerHasStarted();

                var testPlayer1 = new TestClient(TestPlayer1UserName, gameSessionManager);
                var testPlayer2 = new TestClient(TestPlayer2UserName, gameSessionManager);

                var testScript = new TestScript(testPlayer1, testPlayer2);
                testScript.AllClientsJoinGame();
                testScript.WaitUntilClientsReceiveMessageOfType(typeof(PlayerDataReceivedMessage), testPlayer1, testPlayer2);

                var messageText     = "Hello There";
                var expectedMessage = new PersonalMessage(TestPlayer1UserName, messageText);

                // Act
                testPlayer1.SendPersonalMessage(messageText);

                // Assert
                testScript.WaitUntilClientsReceiveMessage(expectedMessage, testPlayer2);
            }
            finally
            {
                gameSessionManager?.WaitUntilGameSessionManagerHasStopped();
            }
        }
Пример #14
0
        public void SameClientCannotBeAddedToAnotherGameSession()
        {
            Jabberwocky.SoC.Service.GameSessionManager gameSessionManager = null;
            try
            {
                Guid firstSessionToken  = Guid.NewGuid();
                Guid secondSessionToken = Guid.NewGuid();

                var mockGameSessionTokenFactory = NSubstitute.Substitute.For <IGameSessionTokenFactory>();
                mockGameSessionTokenFactory.CreateGameSessionToken().Returns(firstSessionToken, secondSessionToken);

                gameSessionManager = GameSessionManagerTestExtensions.CreateGameSessionManagerForTest(4)
                                     .AddGameSessionTokenFactory(mockGameSessionTokenFactory)
                                     .WaitUntilGameSessionManagerHasStarted();

                var testPlayer1 = new TestClient(TestPlayer1UserName, gameSessionManager);
                var testPlayer2 = new TestClient(TestPlayer2UserName, gameSessionManager);
                var testPlayer3 = new TestClient(TestPlayer3UserName, gameSessionManager);
                var testPlayer4 = new TestClient(TestPlayer4UserName, gameSessionManager);

                // Act - Attempt to add the same client into two game sessions.
                var testScript = new TestScript(testPlayer1, testPlayer2, testPlayer3, testPlayer4, testPlayer1);
                testScript.RunUntil(TestScript.RunPoints.RunUntilClientsReceiveGameSessionReadyToLaunchMessage);
                //this.WaitUntilClientsReceiveMessageOfType(typeof(GameSessionReadyToLaunchMessage), testPlayer1, testPlayer2, testPlayer3, testPlayer4);

                // Assert
                testPlayer1.GameToken.ShouldBe(firstSessionToken);
                testPlayer2.GameToken.ShouldBe(firstSessionToken);
                testPlayer3.GameToken.ShouldBe(firstSessionToken);
                testPlayer4.GameToken.ShouldBe(firstSessionToken);
            }
            finally
            {
                gameSessionManager?.WaitUntilGameSessionManagerHasStopped();
            }
        }