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); }
public static IActionResult Connect( [HttpTrigger(AuthorizationLevel.Function, "get", Route = "connect/{hubName}")] HttpRequest req, string hubName, [SignalR(ServiceName = "%service_name%", AccessKey = "%access_key%")] SignalRConnectionBuilder connectionBuilder, TraceWriter log) { log.Info("C# HTTP trigger function processed a request."); return(new OkObjectResult( connectionBuilder.CreateConnectionInfo(hubName) )); }
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); }