public async Task TestGiveInfoReturnsAppropriateMessage() { // Arrange PlayerConfiguration configuration = GenerateSampleConfiguration(); BufferBlock <Message> inputBuffer = new BufferBlock <Message>(); ISocketClient <Message, Message> client = GenerateSocketClient(); var player = new Models.Player(configuration, inputBuffer, client, logger); Message messageStart = CreateStartMessage(); inputBuffer.Post(messageStart); await player.AcceptMessage(CancellationToken.None); BegForInfoForwardedPayload payload = new BegForInfoForwardedPayload() { AskingID = 2, Leader = false, TeamID = Team.Red, }; Message beg4Info = new Message(MessageID.BegForInfoForwarded, agentID, payload); inputBuffer.Post(beg4Info); await player.AcceptMessage(CancellationToken.None); // Act await player.GiveInfo(CancellationToken.None); // Assert Assert.Equal(MessageID.GiveInfo, lastSended.MessageID); }
public async Task TestAcceptMessageBegForInfoAccept() { BegForInfoForwardedPayload payloadBeg = new BegForInfoForwardedPayload() { AskingID = 2, Leader = false, TeamID = Team.Red, }; Message messageBeg = new Message(MessageID.BegForInfoForwarded, agentID, payloadBeg); Message messageStart = CreateStartMessage(); BufferBlock <Message> inputBuffer = new BufferBlock <Message>(); inputBuffer.Post(messageStart); inputBuffer.Post(messageBeg); PlayerConfiguration configuration = GenerateSampleConfiguration(); var player = new Player.Models.Player(configuration, inputBuffer, new TcpSocketClient <Message, Message>(logger), logger); await player.AcceptMessage(CancellationToken.None); await player.AcceptMessage(CancellationToken.None); Assert.Single(player.WaitingPlayers); }
public void TestBegForInfoForwardedPayloadSerialization() { // Arrange var payload = new BegForInfoForwardedPayload() { AskingID = 0, Leader = true, TeamID = Team.Red, }; // Act var expectedJsonString = "{\"askingID\":0,\"leader\":true,\"teamID\":\"red\"}"; var serializedPayload = JsonConvert.SerializeObject(payload); // Assert Assert.Equal(expectedJsonString, serializedPayload); }