jeudi 4 février 2016

Integration test with signalR

I like to do an integration test with SignalR.

In this code the hub will not be called. Is there any idea for solving this problem. The hub connection is in connected mode but the hub will not be initialised and so the event will not be fired.

Testing rest-web-api is running in this way.

internal class Startup
    {
        [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:ElementsMustBeDocumented", Justification = "Reviewed. Suppression is OK here.")]
        public void Configuration(IAppBuilder app)
        {
            // STANDARD WEB API SETUP:

            // Get your HttpConfiguration. In OWIN, you'll create one
            // rather than using GlobalConfiguration.
            HttpConfiguration config = new HttpConfiguration();

            // register the real web api config
            WebApiConfig.Register(config);

            // OWIN WEB API SETUP:
            app.UseAutofacWebApi(config);
            app.UseWebApi(config);

            app.MapSignalR();
        }
    }

    [Test]
    public void OwinAppTest()
    {
        var server = TestServer.Create<Startup>();
        var adr = server.BaseAddress.ToString();

        var hubConnection = new HubConnection(adr + "signalR");
        IHubProxy hubProxy = hubConnection.CreateHubProxy("AnalogPlcHub");

        hubConnection.Start();
        Debug.WriteLine("connection: " + hubConnection.State);
        hubProxy.On<int>(
                "currentValue",
                (message) =>
                    {
                        Debug.WriteLine("Incoming data: {0} {1}", message);
                    });
            Debug.WriteLine("CCCC: ");

        // Thread.Sleep(5500);
        // var fff = hubProxy.GetValue<int>("currentValue");
        // Debug.WriteLine(fff);

    }

Aucun commentaire:

Enregistrer un commentaire