public async Task PatternRpcTest(string procedureToInvoke, string matchedProcedure) { WampPlayground playground = new WampPlayground(); playground.Host.Open(); IWampChannel calleeChannel = playground.CreateNewChannel("realm1"); await calleeChannel.Open(); Action <MyOperation, InvocationDetails> action = (operation, details) => { Assert.That(details.Procedure, Is.EqualTo(procedureToInvoke)); Assert.That(operation.Procedure, Is.EqualTo(matchedProcedure)); }; await Register(calleeChannel, "com.myapp.manage.47837483.create", "exact", action); await Register(calleeChannel, "com.myapp", "prefix", action); await Register(calleeChannel, "com.myapp.manage", "prefix", action); await Register(calleeChannel, "com....", "wildcard", action); await Register(calleeChannel, ".myapp...create", "wildcard", action); IWampChannel callerChannel = playground.CreateNewChannel("realm1"); await callerChannel.Open(); var callback = new MyCallback(); callerChannel.RealmProxy.RpcCatalog.Invoke (callback, new CallOptions(), procedureToInvoke); Assert.That(callback.Called, Is.EqualTo(true)); }
public void RequestContextIsSet() { WampPlayground playground = new WampPlayground(); IWampHost host = playground.Host; WampRequestContext context = null; Mock<ICalculator> calculatorMock = new Mock<ICalculator>(); calculatorMock.Setup(x => x.Square(It.IsAny<int>())) .Callback((int x) => context = WampRequestContext.Current) .Returns((int x) => x*x); host.HostService(calculatorMock.Object); host.Open(); IWampChannel<MockRaw> channel = playground.CreateNewChannel(); channel.Open(); ICalculator proxy = channel.GetRpcProxy<ICalculator>(); int sixteen = proxy.Square(4); Assert.That(context.SessionId, Is.EqualTo(channel.GetMonitor().SessionId)); }
public void AsyncClientRpcCallsServer() { WampPlayground playground = new WampPlayground(); IWampHost host = playground.Host; Mock <ICalculator> calculatorMock = GetCalculatorMock(); host.HostService(calculatorMock.Object); host.Open(); IWampChannel <MockRaw> channel = playground.CreateNewChannel(); channel.Open(); IAsyncCalculator proxy = channel.GetRpcProxy <IAsyncCalculator>(); Task <int> sevenTask = proxy.Add(3, 4); int seven = sevenTask.Result; calculatorMock.Verify(x => x.Add(3, 4)); Assert.That(seven, Is.EqualTo(7)); }
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)); }
public async Task KillAllTest(int killer) { WampPlayground playground = SetupHost(); List <IWampChannel> channels = new List <IWampChannel>(); for (int i = 0; i < 30; i++) { IWampChannel channel = playground.CreateNewChannel("realm1"); channels.Add(channel); } Dictionary <int, (string reason, string message)> disconnectionDetails = await OpenChannels(channels).ConfigureAwait(false); Assert.That(disconnectionDetails.Count, Is.EqualTo(0)); IWampSessionManagementServiceProxy proxy = channels[killer].RealmProxy.Services .GetCalleeProxy <IWampSessionManagementServiceProxy>(); const string expectedReason = "wamp.myreason"; const string expectedMessage = "Bye bye bye"; await proxy.KillAllAsync(expectedReason, expectedMessage).ConfigureAwait(false); AssertClosedChannels(Enumerable.Range(0, 30).Except(new[] { killer }), disconnectionDetails, expectedMessage, expectedReason); }
public void RequestContextIsSet() { WampPlayground playground = new WampPlayground(); IWampHost host = playground.Host; WampRequestContext context = null; Mock <ICalculator> calculatorMock = new Mock <ICalculator>(); calculatorMock.Setup(x => x.Square(It.IsAny <int>())) .Callback((int x) => context = WampRequestContext.Current) .Returns((int x) => x * x); host.HostService(calculatorMock.Object); host.Open(); IWampChannel <MockRaw> channel = playground.CreateNewChannel(); channel.Open(); ICalculator proxy = channel.GetRpcProxy <ICalculator>(); int sixteen = proxy.Square(4); Assert.That(context.SessionId, Is.EqualTo(channel.GetMonitor().SessionId)); }
public void AsyncAwaitTaskWork() { WampPlayground playground = new WampPlayground(); IWampHost host = playground.Host; WampRequestContext context = null; Mock <INumberProcessor> mock = new Mock <INumberProcessor>(); mock.Setup(x => x.ProcessNumber(It.IsAny <int>())) .Returns(async(int x) => { }); host.HostService(mock.Object); host.Open(); IWampChannel <MockRaw> channel = playground.CreateNewChannel(); channel.Open(); INumberProcessor proxy = channel.GetRpcProxy <INumberProcessor>(); Task task = proxy.ProcessNumber(4); mock.Verify(x => x.ProcessNumber(4)); }
public void TopicOnNextCallsSubjectOnNext() { WampPlayground playground = new WampPlayground(); IWampHost host = playground.Host; IWampTopicContainer topicContainer = host.TopicContainer; host.Open(); IWampChannel<MockRaw> channel = playground.CreateNewChannel(); channel.Open(); IWampTopic topic = null; topicContainer.TopicCreated += (sender, args) => topic = args.Topic; object @event = null; string topicUri = "http://example.com/simple"; ISubject<object> subject = channel.GetSubject<object>(topicUri); subject.Subscribe(x => @event = x); Assert.That(topic, Is.Not.Null); Assert.That(topic.TopicUri, Is.EqualTo(topicUri)); string value = "Test :)"; topic.OnNext(value); Assert.That(@event, Is.EqualTo(value)); }
public void AsyncClientRpcCallsServer() { WampPlayground playground = new WampPlayground(); IWampHost host = playground.Host; Mock<ICalculator> calculatorMock = GetCalculatorMock(); host.HostService(calculatorMock.Object); host.Open(); IWampChannel<MockRaw> channel = playground.CreateNewChannel(); channel.Open(); IAsyncCalculator proxy = channel.GetRpcProxy<IAsyncCalculator>(); Task<int> sevenTask = proxy.Add(3, 4); int seven = sevenTask.Result; calculatorMock.Verify(x => x.Add(3, 4)); Assert.That(seven, Is.EqualTo(7)); }
public void TopicOnNextCallsSubjectOnNext() { WampPlayground playground = new WampPlayground(); IWampHost host = playground.Host; IWampTopicContainer topicContainer = host.TopicContainer; host.Open(); IWampChannel <MockRaw> channel = playground.CreateNewChannel(); channel.Open(); IWampTopic topic = null; topicContainer.TopicCreated += (sender, args) => topic = args.Topic; object @event = null; string topicUri = "http://example.com/simple"; ISubject <object> subject = channel.GetSubject <object>(topicUri); subject.Subscribe(x => @event = x); Assert.That(topic, Is.Not.Null); Assert.That(topic.TopicUri, Is.EqualTo(topicUri)); string value = "Test :)"; topic.OnNext(value); Assert.That(@event, Is.EqualTo(value)); }
private static async Task <Registration> RegisterCallee (WampPlayground playground, Action <Registration> action, string invocationPolicy) { IWampChannel calleeChannel = playground.CreateNewChannel("realm1"); await calleeChannel.Open(); Registration registration = null; MyOperation operation = new MyOperation(() => action(registration)); IAsyncDisposable disposable = await calleeChannel.RealmProxy.RpcCatalog.Register (operation, new RegisterOptions() { Invoke = invocationPolicy }); registration = new Registration(operation, disposable); return(registration); }
private static async Task <IPingService> GetCaller(WampPlayground playground) { IWampChannel channel = playground.CreateNewChannel("realm1"); await channel.Open(); IPingService pingService = channel.RealmProxy.Services.GetCalleeProxy <IPingService>(); return(pingService); }
public async Task KillBySessionIdTest(int killer, int killed, bool expectException = false) { WampPlayground playground = SetupHost(); List <IWampChannel> channels = new List <IWampChannel>(); IDictionary <int, long> channelToSessionId = new Dictionary <int, long>(); for (int i = 0; i < 30; i++) { IWampChannel channel = playground.CreateNewChannel("realm1"); int copyOfKey = i; channel.RealmProxy.Monitor.ConnectionEstablished += (sender, args) => { channelToSessionId[copyOfKey] = args.SessionId; }; channels.Add(channel); } Dictionary <int, (string reason, string message)> disconnectionDetails = await OpenChannels(channels).ConfigureAwait(false); Assert.That(disconnectionDetails.Count, Is.EqualTo(0)); IWampSessionManagementServiceProxy proxy = channels[killer].RealmProxy.Services .GetCalleeProxy <IWampSessionManagementServiceProxy>(); const string expectedReason = "wamp.myreason"; const string expectedMessage = "Bye bye bye"; WampException exception = null; try { await proxy.KillBySessionIdAsync(channelToSessionId[killed], expectedReason, expectedMessage).ConfigureAwait(false); } catch (WampException ex) { exception = ex; } if (expectException) { Assert.That(exception, Is.Not.Null); Assert.That(exception.ErrorUri, Is.EqualTo("wamp.error.no_such_session")); } AssertClosedChannels(new [] { killed }.Except(new[] { killer }), disconnectionDetails, expectedMessage, expectedReason); }
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 async Task <IWampChannel> SetupService <TService>(WampPlayground playground) where TService : new() { const string realmName = "realm1"; IWampHostedRealm realm = playground.Host.RealmContainer.GetRealmByName(realmName); TService service = new TService(); await realm.Services.RegisterCallee(service); playground.Host.Open(); IWampChannel channel = playground.CreateNewChannel(realmName); await channel.Open(); return(channel); }
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)); }
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)); }