Пример #1
0
        public async Task SubscribeWithMessage()
        {
            var(server, client) = SignalRConnectionBuilder.CreateTestConnection <MqttBridgeHub, IMqttBridgeClient>();

            string message        = null;
            var    msgTokenSource = new CancellationTokenSource(TestTimeout);

            client.On <string>("ReceiveMessage", msg =>
            {
                message = msg;
                msgTokenSource.Cancel();
            });

            await client.StartAsync();

            await client.InvokeAsync <SubscribedMessage>("Subscribe", new SubscribeMessage()
            {
                DeviceId = TestDeviceId
            });

            var testMessage = "test";

            await server.Clients.Group(TestDeviceId).ReceiveMessage(testMessage);

            //await hubContext.Clients.All.ReceiveMessage(testMessage);

            await CancelableDelay(msgTokenSource);

            await client.StopAsync();

            Assert.Equal(testMessage, message);
        }
Пример #2
0
        public async Task UnsubscribeWithResponse()
        {
            var(_, client) = SignalRConnectionBuilder.CreateTestConnection <MqttBridgeHub, IMqttBridgeClient>();

            await client.StartAsync();

            var result = await client.InvokeAsync <UnsubscribedMessage>("Unsubscribe", new UnsubscribeMessage()
            {
                DeviceId = TestDeviceId
            });

            await client.StopAsync();

            Assert.Equal(TestDeviceId, result.DeviceId);
        }