public async Task SendAsyncThrowsIfSerializingMessageFails() { var exception = new InvalidOperationException(); var hubConnection = CreateHubConnection(new TestConnection(), protocol: MockHubProtocol.Throw(exception)); await hubConnection.StartAsync().OrTimeout(); var actualException = await Assert.ThrowsAsync <InvalidOperationException>(async() => await hubConnection.SendAsync("test").OrTimeout()); Assert.Same(exception, actualException); }
public async Task InvokeThrowsIfSerializingMessageFails() { var exception = new InvalidOperationException(); var mockProtocol = MockHubProtocol.Throw(exception); var hubConnection = new HubConnection(new TestConnection(), mockProtocol, null); await hubConnection.StartAsync(); var actualException = await Assert.ThrowsAsync <InvalidOperationException>(async() => await hubConnection.InvokeAsync <int>("test")); Assert.Same(exception, actualException); }
public async Task InvokeThrowsIfSerializingMessageFails() { bool ExpectedErrors(WriteContext writeContext) { return(writeContext.LoggerName == typeof(HubConnection).FullName && writeContext.EventId.Name == "FailedToSendInvocation"); } using (StartVerifiableLog(ExpectedErrors)) { var exception = new InvalidOperationException(); var hubConnection = CreateHubConnection(new TestConnection(), protocol: MockHubProtocol.Throw(exception), LoggerFactory); await hubConnection.StartAsync().DefaultTimeout(); var actualException = await Assert.ThrowsAsync <InvalidOperationException>(async() => await hubConnection.InvokeAsync <int>("test").DefaultTimeout()); Assert.Same(exception, actualException); } }