public async Task TestSendInformationExchangeResponseMessage() { var conf = GenerateConfiguration(); var queue = GenerateBuffer(); var client = GenerateSocketClient(); var lifetime = Mock.Of <IApplicationLifetime>(); var gameMaster = new GM(lifetime, conf, queue, client, logger); gameMaster.Invoke("InitGame"); int player1ID = 1; int player2ID = 2; int player3ID = 3; await InitializeAndBegForInfo(gameMaster, player1ID, player2ID); GiveInfoPayload giveInfoPayload = new GiveInfoPayload() { RespondToID = player1ID, Distances = new int[] { 1, 1 }, RedTeamGoalAreaInformations = new GoalInfo[] { GoalInfo.IDK }, BlueTeamGoalAreaInformations = new GoalInfo[] { GoalInfo.IDK }, }; Message giveMessage1 = new Message() { MessageID = MessageID.GiveInfo, AgentID = player2ID, Payload = giveInfoPayload, }; Message giveMessage2 = new Message() { MessageID = MessageID.GiveInfo, AgentID = player3ID, Payload = giveInfoPayload, }; await gameMaster.AcceptMessage(giveMessage1, CancellationToken.None); var lastMessage = sendedMessages.Pop(); Assert.Equal(MessageID.InformationExchangeResponse, lastMessage.MessageID); Assert.True(((InformationExchangePayload)lastMessage.Payload).Succeeded); await gameMaster.AcceptMessage(giveMessage2, CancellationToken.None); lastMessage = sendedMessages.Pop(); Assert.Equal(MessageID.InformationExchangeResponse, lastMessage.MessageID); Assert.False(((InformationExchangePayload)lastMessage.Payload).Succeeded); }
private async Task InitializeAndBegForInfo(GM gameMaster, int player1ID, int player2ID) { JoinGamePayload joinGamePayload = new JoinGamePayload() { TeamID = Team.Blue, }; Message joinMessage1 = new Message() { MessageID = MessageID.JoinTheGame, AgentID = player1ID, Payload = joinGamePayload, }; Message joinMessage2 = new Message() { MessageID = MessageID.JoinTheGame, AgentID = player2ID, Payload = joinGamePayload, }; await gameMaster.AcceptMessage(joinMessage1, CancellationToken.None); await gameMaster.AcceptMessage(joinMessage2, CancellationToken.None); gameMaster.Invoke("StartGame", CancellationToken.None); BegForInfoPayload begForInfoPayload = new BegForInfoPayload() { AskedAgentID = player2ID, }; Message askMessage = new Message() { MessageID = MessageID.BegForInfo, AgentID = player1ID, Payload = begForInfoPayload, }; await gameMaster.AcceptMessage(askMessage, CancellationToken.None); }
public async Task TestSendInformationExchangeRequesMessage() { var conf = GenerateConfiguration(); var queue = GenerateBuffer(); var client = GenerateSocketClient(); var lifetime = Mock.Of <IApplicationLifetime>(); var gameMaster = new GM(lifetime, conf, queue, client, logger); gameMaster.Invoke("InitGame"); int player1ID = 1; int player2ID = 2; int player3ID = 3; await InitializeAndBegForInfo(gameMaster, player1ID, player2ID); var lastMessage = sendedMessages.Pop(); Assert.Equal(MessageID.InformationExchangeRequest, lastMessage.MessageID); Assert.True(((InformationExchangePayload)lastMessage.Payload).Succeeded); BegForInfoPayload begForInfoPayload = new BegForInfoPayload() { AskedAgentID = player3ID, }; Message askMessage = new Message() { MessageID = MessageID.BegForInfo, AgentID = player1ID, Payload = begForInfoPayload, }; await gameMaster.AcceptMessage(askMessage, CancellationToken.None); lastMessage = sendedMessages.Pop(); Assert.Equal(MessageID.InformationExchangeRequest, lastMessage.MessageID); Assert.False(((InformationExchangePayload)lastMessage.Payload).Succeeded); }