【问题标题】:AspNet Core Integration Test For SignalRSignalR 的 AspNet 核心集成测试
【发布时间】:2018-07-10 12:43:39
【问题描述】:

是否可以使用作为集成测试的一部分生成的TestServer 来测试SignalR (https://docs.microsoft.com/en-us/aspnet/core/test/integration-tests view=aspnetcore-2.1)?

我的所有重试都未能与TestServer 实例握手失败并出现异常:System.Net.Sockets.SocketException : No connection could be made because the target machine actively refused it

运行在Debug/Console/IIS 完美运行

服务器代码

 public void Configure(...)
 {
     ...
     app.UseSignalR(router => router.MapHub<MockHub>("/ws"));
     ...
}

测试代码

        ...
        var server = factory.Server;
        var connection = new HubConnectionBuilder()
              .WithUrl(server.BaseAddress)
              .Build();
        await connection.StartAsync();

【问题讨论】:

    标签: asp.net-core signalr integration-testing


    【解决方案1】:

    看起来TestServer 要求你使用它创建的HttpMessageHandler,所以把你的代码改成

    .WithUrl(new Uri(server.BaseAddress, "ws"), o => { o.HttpMessageHandlerFactory = _ => server.CreateHandler(); })

    【讨论】:

    • 我会尽快查看
    【解决方案2】:

    它应该工作。我看到的唯一明显错误的地方是您仅将测试主机地址传递给WithUrl,而它应该是您的集线器的完整路径,即类似于:

    .WithUrl(new Uri(server.BaseAddress, Consts.TethysWebSocketPath))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多