mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-02-24 17:55:01 +01:00
FIX?
This commit is contained in:
@@ -7,16 +7,29 @@ namespace WireMock.WebSockets;
|
||||
|
||||
internal class WebSocketMessageBuilder : IWebSocketMessageBuilder
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public string? MessageText { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[]? MessageBytes { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public TimeSpan? Delay { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public WebSocketMessageType Type { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool ShouldClose { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IWebSocketMessageBuilder WithEcho()
|
||||
{
|
||||
Type = WebSocketMessageType.Close;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IWebSocketMessageBuilder WithText(string text)
|
||||
{
|
||||
MessageText = Guard.NotNull(text);
|
||||
@@ -24,6 +37,7 @@ internal class WebSocketMessageBuilder : IWebSocketMessageBuilder
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IWebSocketMessageBuilder WithBinary(byte[] bytes)
|
||||
{
|
||||
MessageBytes = Guard.NotNull(bytes);
|
||||
@@ -31,23 +45,27 @@ internal class WebSocketMessageBuilder : IWebSocketMessageBuilder
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IWebSocketMessageBuilder WithDelay(TimeSpan delay)
|
||||
{
|
||||
Delay = delay;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IWebSocketMessageBuilder WithDelay(int delayInMilliseconds)
|
||||
{
|
||||
Guard.Condition(delayInMilliseconds, d => d >= 0);
|
||||
return WithDelay(TimeSpan.FromMilliseconds(delayInMilliseconds));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IWebSocketMessageBuilder Close()
|
||||
{
|
||||
ShouldClose = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IWebSocketMessageBuilder AndClose() => Close();
|
||||
}
|
||||
@@ -1,10 +1,8 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Settings;
|
||||
using WireMock.Types;
|
||||
|
||||
namespace WireMock.WebSockets;
|
||||
|
||||
|
||||
@@ -9,6 +9,12 @@ namespace WireMock.WebSockets;
|
||||
/// </summary>
|
||||
public interface IWebSocketMessageBuilder
|
||||
{
|
||||
/// <summary>
|
||||
/// Echo all received messages back to client
|
||||
/// </summary>
|
||||
[PublicAPI]
|
||||
IWebSocketMessageBuilder WithEcho();
|
||||
|
||||
/// <summary>
|
||||
/// Send a specific text message
|
||||
/// </summary>
|
||||
|
||||
@@ -676,7 +676,7 @@ public class WebSocketIntegrationTests(ITestOutputHelper output, ITestContextAcc
|
||||
public async Task WithWebSocketProxy_Should_Proxy_Messages_To_Target_Server()
|
||||
{
|
||||
// Arrange - Start target echo server
|
||||
using var targetServer = WireMockServer.Start(new WireMockServerSettings
|
||||
var targetServer = WireMockServer.Start(new WireMockServerSettings
|
||||
{
|
||||
Logger = new TestOutputHelperWireMockLogger(output),
|
||||
Urls = ["ws://localhost:0"]
|
||||
@@ -698,14 +698,13 @@ public class WebSocketIntegrationTests(ITestOutputHelper output, ITestContextAcc
|
||||
Urls = ["ws://localhost:0"]
|
||||
});
|
||||
|
||||
var targetUrl = $"{targetServer.Url}/ws/target".Replace("http://", "ws://");
|
||||
proxyServer
|
||||
.Given(Request.Create()
|
||||
.WithPath("/ws/proxy")
|
||||
.WithWebSocketUpgrade()
|
||||
)
|
||||
.RespondWith(Response.Create()
|
||||
.WithWebSocketProxy(targetUrl)
|
||||
.WithWebSocketProxy(targetServer.Url!)
|
||||
);
|
||||
|
||||
using var client = new ClientWebSocket();
|
||||
@@ -723,6 +722,9 @@ public class WebSocketIntegrationTests(ITestOutputHelper output, ITestContextAcc
|
||||
received.Should().Be(testMessage, "message should be proxied to target echo server and echoed back");
|
||||
|
||||
await client.CloseAsync(WebSocketCloseStatus.NormalClosure, "Test complete", _ct);
|
||||
|
||||
targetServer.Stop();
|
||||
targetServer.Dispose();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
Reference in New Issue
Block a user