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