public void Setup() { config = GameMasterConfiguration.GetDefault(); gameMaster = new GameMaster.GameMaster(config); mockedNetworkComponent = new Mock <INetworkComponent>(); mockedNetworkComponent.Setup(m => m.Connect(It.IsAny <ClientType>())).Returns(true); mockedNetworkComponent.Setup(m => m.GetIncomingMessages()).Returns(GetMockedMessages()); }
private void GetConfigurationsForTest(int testId, out AgentConfiguration agentConfig, out GameMasterConfiguration gmConfig, out CommunicationServerConfiguration csConfig) { const int baseAgentPort = 50000; const int baseGmPort = 60000; var agentPortForTest = baseAgentPort + testId; var gmPortForTest = baseGmPort - testId; csConfig = CommunicationServerConfiguration.GetDefault(); agentConfig = AgentConfiguration.GetDefault(); agentConfig.CsPort = agentPortForTest; csConfig.AgentPort = agentPortForTest; gmConfig = GameMasterConfiguration.GetDefault(); gmConfig.CsPort = gmPortForTest; csConfig.GameMasterPort = gmPortForTest; }
public void Setup() { gameMaster = new GameMaster.GameMaster(GameMasterConfiguration.GetDefault()); BoardLogicComponent = gameMaster.BoardLogic; size = new Point(gameMaster.Configuration.BoardX, gameMaster.Configuration.BoardY); }
public void ConnectingAgentsState_ShouldConnectAgent() { // Setup var config = GameMasterConfiguration.GetDefault(); config.TeamSize = 3; var gameMaster = new GameMaster.GameMaster(config); agentsInTeam = gameMaster.Configuration.TeamSize; gmTaskState = new IntegrationTestsHelper.GameMasterTaskState(gameMaster, 30); var csConfig = CommunicationServerConfiguration.GetDefault(); var csTask = new Task(IntegrationTestsHelper.RunCommunicationServer, csConfig); csTask.Start(); Thread.Sleep(100); var gmTask = new Task(IntegrationTestsHelper.RunGameMaster, gmTaskState); gmTask.Start(); gmTaskState.GameMaster.ConnectToCommunicationServer(); var agentTaskStates = IntegrationTestsHelper.CreateAgents(agentsInTeam) .Select(agent => new IntegrationTestsHelper.AgentTaskState(agent, agentSleepMs)).ToList(); var agentTasks = agentTaskStates .Select(agentTaskState => new Task(IntegrationTestsHelper.RunAgent, agentTaskState)).ToList(); foreach (var agentTask in agentTasks) { Thread.Sleep(100); agentTask.Start(); } gmTask.Wait(); List <GameMaster.Agent> lobby = gmTaskState.GameMaster.ConnectionLogic.FlushLobby(); Assert.AreEqual(agentsInTeam * 2, lobby.Count); Assert.AreEqual(2, lobby.Where(agent => agent.IsTeamLeader).Count()); Assert.AreEqual(agentsInTeam, lobby.Where(agent => agent.Team == TeamId.Blue).Count()); Assert.AreEqual(agentsInTeam, lobby.Where(agent => agent.Team == TeamId.Red).Count()); // Cleanup gmTaskState.GameMaster.OnDestroy(); try { gmTaskState.GameMaster.OnDestroy(); csTask.Wait(200); } catch (AggregateException ex) { Assert.AreEqual(TaskStatus.Faulted, csTask.Status); var exception = ex.InnerException as CommunicationErrorException; Assert.IsNotNull(exception); Assert.AreEqual(CommunicationExceptionType.GameMasterDisconnected, exception.Type); for (int i = 0; i < agentTasks.Count; i++) { agentTasks[i].Wait(100); agentTaskStates[i].Agent.OnDestroy(); } } }
public void Setup() { configuration = GameMasterConfiguration.GetDefault(); gameMaster = new GameMaster.GameMaster(configuration); connectionLogic = gameMaster.ConnectionLogic; }
public void Setup() { configuration = GameMasterConfiguration.GetDefault(); gameMaster = new GameMaster.GameMaster(configuration); gameLogicComponent = gameMaster.GameLogic; }