首页 > 解决方案 > 用于服务/集成测试的 SignalR 服务模拟实现

问题描述

我希望能够模拟 SignalR Hub 进行服务测试。这个想法是能够通过以下方式创建测试:启动 SignalR 服务器(应在运行时配置 url、端口和集线器类) - 为此目的,将在测试模块中创建集线器。所以第一部分 - 启动一个运行时可配置的 SignalR 服务器是可能的:

StartOptions so = new StartOptions("http://127.0.0.1:8080");
so.AppStartup = "SrServer.Startup1"; // set the startup class (will be defined in the test module)

以下是 Startup1 的示例:

class Startup1
{
    public void Configuration(IAppBuilder app)
    {

        app.UseCors(CorsOptions.AllowAll);
        app.MapSignalR();
    }
}

我缺少的唯一问题是能够从我的测试模块设置要使用的集线器 - 这可能吗?

标签: testingservicesignalrintegration

解决方案


只需在调用“app.MapSignalR();”之前加载包含集线器的程序集

AppDomain.CurrentDomain.Load(typeof(MyHub).Assembly.FullName);

来源: https ://stackoverflow.com/a/21597197/10720979


推荐阅读