public async Task SendConnectionAsyncDoesNotThrowIfConnectionFailsToWrite() { using (var client = new TestClient()) { var manager = new DefaultHubLifetimeManager <MyHub>(new Logger <DefaultHubLifetimeManager <MyHub> >(NullLoggerFactory.Instance)); var connectionMock = HubConnectionContextUtils.CreateMock(client.Connection); // Force an exception when writing to connection connectionMock.Setup(m => m.WriteAsync(It.IsAny <HubMessage>())).Throws(new Exception("Message")); var connection = connectionMock.Object; await manager.OnConnectedAsync(connection).OrTimeout(); await manager.SendConnectionAsync(connection.ConnectionId, "Hello", new object[] { "World" }).OrTimeout(); } }
public async Task SendConnectionAsyncWritesToConnectionOutput() { using (var client = new TestClient()) { var manager = new DefaultHubLifetimeManager <MyHub>(new Logger <DefaultHubLifetimeManager <MyHub> >(NullLoggerFactory.Instance)); var connection = HubConnectionContextUtils.Create(client.Connection); await manager.OnConnectedAsync(connection).OrTimeout(); await manager.SendConnectionAsync(connection.ConnectionId, "Hello", new object[] { "World" }).OrTimeout(); var message = Assert.IsType <InvocationMessage>(client.TryRead()); Assert.Equal("Hello", message.Target); Assert.Single(message.Arguments); Assert.Equal("World", (string)message.Arguments[0]); } }
public async Task InvokeConnectionAsyncThrowsIfConnectionFailsToWrite() { using (var client = new TestClient()) { // Force an exception when writing to connection var manager = new DefaultHubLifetimeManager <MyHub>(); var connectionMock = HubConnectionContextUtils.CreateMock(client.Connection); connectionMock.Setup(m => m.WriteAsync(It.IsAny <HubMessage>())).Throws(new Exception("Message")); var connection = connectionMock.Object; await manager.OnConnectedAsync(connection).OrTimeout(); var exception = await Assert.ThrowsAsync <Exception>(() => manager.SendConnectionAsync(connection.ConnectionId, "Hello", new object[] { "World" }).OrTimeout()); Assert.Equal("Message", exception.Message); } }
public Task SendConnectionAsync() { return(_hubLifetimeManager.SendConnectionAsync(_connectionIds[0], "MethodName", Array.Empty <object>())); }
public async Task SendConnectionAsyncOnNonExistentConnectionNoops() { var manager = new DefaultHubLifetimeManager <MyHub>(new Logger <DefaultHubLifetimeManager <MyHub> >(NullLoggerFactory.Instance)); await manager.SendConnectionAsync("NotARealConnectionId", "Hello", new object[] { "World" }).OrTimeout(); }
public async Task InvokeConnectionAsyncOnNonExistentConnectionNoops() { var manager = new DefaultHubLifetimeManager <MyHub>(); await manager.SendConnectionAsync("NotARealConnectionId", "Hello", new object[] { "World" }).OrTimeout(); }