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 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; }
public void SyncClientRpcCallsServerThrowsException() { 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(); 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)); }