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(); } }
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(); } }
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(); } }
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(); } }
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(); } }
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(); } }
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(); } }