public async Task Opening_Throws_Ensure_ProperState(bool canRecover) { string sessionid = "temp session"; SessionErrorHandling.Setup(e => e.Handle(It.IsAny <ClientActionContext>(), It.IsAny <InvalidOperationException>())) .Returns(canRecover ? ErrorHandlingResult.Recover : ErrorHandlingResult.Close); var pipeline = CreatePipeline( (next, ctxt) => { throw new InvalidOperationException(); }); SetupSessionHandler(sessionid); var proxy = CreateProxy(pipeline); await Assert.ThrowsAsync <InvalidOperationException>(() => proxy.OpenSession("test")); if (canRecover) { Assert.Equal(ProxyState.Ready, proxy.State); } else { Assert.Equal(ProxyState.Closed, proxy.State); } SessionErrorHandling.Verify(); }
public async Task Open_NoSessionIdReceived_Throws() { var pipeline = CreatePipeline(); SessionHandler.Setup(s => s.GetSessionIdentifier(It.IsAny <HttpResponseMessage>())).Returns((string)null).Verifiable(); SessionErrorHandling.Setup(r => r.Handle(It.IsAny <ClientActionContext>(), It.IsAny <Exception>())).Returns(ErrorHandlingResult.Recover); var proxy = CreateProxy(pipeline); await Assert.ThrowsAsync <BoltClientException>(() => proxy.OpenSession("test")); SessionHandler.Verify(); }
public async Task Execute_ThrowsError_Handle(bool recoverableProxy, ErrorHandlingResult handlingResult) { var pipeline = CreatePipeline( (next, ctxt) => { ctxt.ServerConnection = ConnectionDescriptor; if (ctxt.Action != ContractDescriptor.InitSession) { throw new InvalidOperationException(); } return(next(ctxt)); }); var session = pipeline.Find <SessionMiddleware>(); session.Recoverable = recoverableProxy; SetupSessionHandler("test session", true); SessionErrorHandling.Setup(r => r.Handle(It.IsAny <ClientActionContext>(), It.IsAny <Exception>())).Returns( () => { return(handlingResult); }); var proxy = CreateProxy(pipeline); await proxy.OpenSession("param"); await Assert.ThrowsAsync <InvalidOperationException>(proxy.ExecuteAsync); if (recoverableProxy) { switch (handlingResult) { case ErrorHandlingResult.Close: Assert.Equal(ProxyState.Closed, proxy.State); break; case ErrorHandlingResult.Recover: Assert.Equal(ProxyState.Ready, proxy.State); break; case ErrorHandlingResult.Rethrow: Assert.Equal(ProxyState.Open, proxy.State); break; default: throw new ArgumentOutOfRangeException(nameof(handlingResult), handlingResult, null); } } else { switch (handlingResult) { case ErrorHandlingResult.Close: Assert.Equal(ProxyState.Closed, proxy.State); break; case ErrorHandlingResult.Recover: Assert.Equal(ProxyState.Closed, proxy.State); break; case ErrorHandlingResult.Rethrow: Assert.Equal(ProxyState.Open, proxy.State); break; default: throw new ArgumentOutOfRangeException(nameof(handlingResult), handlingResult, null); } } }