public void NoAuthenticationThrowsException() { JsonFormatter formatter = new JsonFormatter(); WampCraPlayground <JToken> playground = new WampCraPlayground <JToken> (formatter, new MockWampCraAuthenticaticationBuilder <JToken>()); IWampChannelFactory <JToken> channelFactory = playground.ChannelFactory; IWampHost host = playground.Host; host.HostService(new Sample()); host.Open(); IControlledWampConnection <JToken> connection = playground.CreateClientConnection(); IWampChannel <JToken> channel = channelFactory.CreateChannel(connection); channel.Open(); Task <string> result = channel.GetRpcProxy <ISampleAsync>() .Hello("Foobar"); AggregateException aggregateException = result.Exception; Exception exception = aggregateException.InnerException; WampRpcCallException casted = exception as WampRpcCallException; Assert.IsNotNull(casted); }
public void AuthenticationFailure() { JsonFormatter formatter = new JsonFormatter(); WampCraPlayground <JToken> playground = new WampCraPlayground <JToken> (formatter, new MockWampCraAuthenticaticationBuilder <JToken>()); IWampChannelFactory <JToken> channelFactory = playground.ChannelFactory; IWampHost host = playground.Host; host.HostService(new Sample()); host.Open(); IControlledWampConnection <JToken> connection = playground.CreateClientConnection(); IWampChannel <JToken> channel = channelFactory.CreateChannel(connection); channel.Open(); IWampCraProcedures proceduresProxy = channel.GetRpcProxy <IWampCraProcedures>(); WampRpcCallException callException = Assert.Throws <WampRpcCallException> (() => proceduresProxy.Authenticate(formatter, "foobar", null, "secret2")); }
public void SyncClientRpcCallsAsyncServerThrowsException() { WampPlayground playground = new WampPlayground(); IWampHost host = playground.Host; WampRpcCallException exception = new WampRpcCallException("calculator.add", "This is very bad caclulator implementation", null); Mock <IAsyncCalculator> calculatorMock = GetAsyncErrorCalculatorMock(exception); host.HostService(calculatorMock.Object); host.Open(); IWampChannel <MockRaw> channel = playground.CreateNewChannel(); channel.Open(); ICalculator proxy = channel.GetRpcProxy <ICalculator>(); WampRpcCallException thrown = Assert.Throws <WampRpcCallException>(() => proxy.Add(3, 4)); Assert.That(thrown.ProcUri, Is.EqualTo("test/add")); Assert.That(thrown.ErrorDetails, Is.EqualTo(exception.ErrorDetails)); Assert.That(thrown.ErrorUri, Is.EqualTo(exception.ErrorUri)); Assert.That(thrown.Message, Is.EqualTo(exception.Message)); }
private static Mock <ICalculator> GetErrorCalculatorMock(WampRpcCallException exception) { Mock <ICalculator> calculatorMock = new Mock <ICalculator>(); calculatorMock.Setup(x => x.Add(It.IsAny <int>(), It.IsAny <int>())) .Throws(exception); return(calculatorMock); }
private static Mock <IAsyncCalculator> GetAsyncErrorCalculatorMock(WampRpcCallException exception) { Mock <IAsyncCalculator> calculatorMock = new Mock <IAsyncCalculator>(); TaskCompletionSource <int> completionSource = new TaskCompletionSource <int>(); completionSource.SetException(exception); calculatorMock.Setup(x => x.Add(It.IsAny <int>(), It.IsAny <int>())) .Returns(completionSource.Task); return(calculatorMock); }
public void HandleAsync_ClientCallError_SetsTasksException (WampRpcCall rpcCall, CallErrorDetails callErrorDetails) { MockWampRpcCallManager <MockRaw> callManager = new MockWampRpcCallManager <MockRaw>(); IWampRpcClientHandler handler = GetHandler(client => callManager.GetServer(client)); Task <object> task = handler.HandleAsync(rpcCall); MockWampRpcCallDetails <MockRaw> details = callManager.GetCallDetails(rpcCall.CallId); Assert.IsFalse(task.IsCompleted); object errorDetails = callErrorDetails.ErrorDetails; if (errorDetails == null) { details.Client.CallError(rpcCall.CallId, callErrorDetails.ErrorUri, callErrorDetails.ErrorDesc); } else { details.Client.CallError(rpcCall.CallId, callErrorDetails.ErrorUri, callErrorDetails.ErrorDesc, new MockRaw(errorDetails)); } AggregateException aggregatedException = task.Exception; Assert.IsNotNull(aggregatedException); Exception innerException = aggregatedException.InnerException; Assert.That(innerException, Is.TypeOf(typeof(WampRpcCallException))); WampRpcCallException casted = innerException as WampRpcCallException; Assert.That(casted.Message, Is.EqualTo(callErrorDetails.ErrorDesc)); Assert.That(casted.CallId, Is.EqualTo(rpcCall.CallId)); Assert.That(casted.ErrorUri, Is.EqualTo(callErrorDetails.ErrorUri)); Assert.That(casted.ErrorDetails, Is.EqualTo(errorDetails) .Using(StructuralComparisons.StructuralEqualityComparer)); }
public void AsyncClientRpcCallsServerThrowsException() { WampPlayground playground = new WampPlayground(); IWampHost host = playground.Host; WampRpcCallException exception = new WampRpcCallException("calculator.add", "This is very bad caclulator implementation", null); Mock <ICalculator> calculatorMock = GetErrorCalculatorMock(exception); host.HostService(calculatorMock.Object); host.Open(); IWampChannel <MockRaw> channel = playground.CreateNewChannel(); channel.Open(); IAsyncCalculator proxy = channel.GetRpcProxy <IAsyncCalculator>(); Task <int> task = proxy.Add(3, 4); try { task.Wait(); } catch (Exception) { } AggregateException aggregateException = task.Exception; Assert.That(aggregateException, Is.Not.Null); Exception innerException = aggregateException.InnerException; Assert.That(innerException, Is.InstanceOf <WampRpcCallException>()); WampRpcCallException thrown = innerException as WampRpcCallException; Assert.That(thrown.ProcUri, Is.EqualTo("test/add")); Assert.That(thrown.ErrorDetails, Is.EqualTo(exception.ErrorDetails)); Assert.That(thrown.ErrorUri, Is.EqualTo(exception.ErrorUri)); Assert.That(thrown.Message, Is.EqualTo(exception.Message)); }
private static void HandleWampException(IWampClient client, string callId, WampRpcCallException callException) { client.CallError(callId, callException.ErrorUri, callException.Message, callException.ErrorDetails); }