Skip to content

Commit

Permalink
Reflect ping payload in pong (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane32 authored Oct 27, 2024
1 parent 5ee3f0a commit cbd7a33
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ public override async Task OnMessageReceivedAsync(OperationMessage message)
/// Executes when a ping message is received.
/// </summary>
protected virtual Task OnPingAsync(OperationMessage message)
=> Connection.SendMessageAsync(_pongMessage);
=> message.Payload == null
? Connection.SendMessageAsync(_pongMessage)
: Connection.SendMessageAsync(new OperationMessage { Type = MessageType.Pong, Payload = message.Payload });

/// <summary>
/// Executes when a pong message is received.
Expand Down
10 changes: 7 additions & 3 deletions src/Tests/WebSockets/NewSubscriptionServerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,15 @@ public async Task Message_ThrowsWhenNotInitialized(string? messageType)
}

[Theory]
[InlineData(false)]
[InlineData(true)]
public async Task Message_Ping(bool initialized)
[InlineData(false, false)]
[InlineData(false, true)]
[InlineData(true, false)]
[InlineData(true, true)]
public async Task Message_Ping(bool initialized, bool withPayload)
{
var message = new OperationMessage { Type = "ping" };
if (withPayload)
message.Payload = new { id = Guid.NewGuid().ToString("N") };
_mockServer.Protected().Setup<Task>("OnPingAsync", message)
.Returns(Task.CompletedTask).Verifiable();
if (initialized) {
Expand Down

0 comments on commit cbd7a33

Please sign in to comment.