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 async Task PublisherActionDelegateEventRaisePublishesEventWithPositionalArguments() { WampPlayground playground = new WampPlayground(); PublisherSubscriber dualChannel = await playground.GetPublisherSubscriberDualChannel(); IWampChannel publisher = dualChannel.Publisher; IWampChannel subscriber = dualChannel.Subscriber; MyOtherPublisher myPublisher = new MyOtherPublisher(); IDisposable disposable = publisher.RealmProxy.Services.RegisterPublisher (myPublisher); IWampTopicProxy topicProxy = subscriber.RealmProxy.TopicContainer.GetTopicByUri("com.myapp.mytopic2"); MyCustomSubscriber myCustomSubscriber = new MyCustomSubscriber(); IAsyncDisposable subscribe = await topicProxy.Subscribe(myCustomSubscriber, new SubscribeOptions()); myPublisher.RaiseMyEvent("Hello", 37, 23); Assert.That(myCustomSubscriber.ArgumentsKeywords, Is.Null.Or.Empty); ISerializedValue[] arguments = myCustomSubscriber.Arguments; Assert.That(arguments[0].Deserialize <string>(), Is.EqualTo("Hello")); Assert.That(arguments[1].Deserialize <int>(), Is.EqualTo(37)); Assert.That(arguments[2].Deserialize <int>(), Is.EqualTo(23)); }
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 async Task LongPositionalTupleServiceCallee() { WampPlayground playground = new WampPlayground(); var channel = await SetupService <LongValueTuplesCalleeService>(playground); MockRawCallback callback = new MockRawCallback(); string name = "Homer Simpson"; channel.RealmProxy.RpcCatalog.Invoke (callback, new CallOptions(), "com.myapp.get_long_positional_tuple", new object[] { name }, new Dictionary <string, object>()); int count = callback.Arguments.Count() - 1; Assert.That(callback.Arguments.Take(count).Select(x => x.Deserialize <string>()), Is.EquivalentTo(Enumerable.Range(1, 10).Select(index => name + " " + index))); Assert.That(callback.Arguments.Last().Deserialize <int>(), Is.EqualTo(name.Length)); Assert.That(callback.ArgumentsKeywords, Is.Null); }
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 async Task SubscriberGetsEventContextWithPublisherId(bool?discloseMe) { WampPlayground playground = new WampPlayground(); PublisherSubscriber dualChannel = await playground.GetPublisherSubscriberDualChannel(); IWampChannel publisher = dualChannel.Publisher; IWampChannel subscriber = dualChannel.Subscriber; MyOtherSubscriber mySubscriber = new MyOtherSubscriber(); IAsyncDisposable disposable = await subscriber.RealmProxy.Services.RegisterSubscriber (mySubscriber); IWampTopicProxy topicProxy = publisher.RealmProxy.TopicContainer.GetTopicByUri("com.myapp.mytopic2"); long?publish = await topicProxy.Publish (new PublishOptions { DiscloseMe = discloseMe }, new object[] { 47, 23, "Hello" }); long?publisherId = mySubscriber.EventContext.EventDetails.Publisher; if (discloseMe == true) { Assert.That(publisherId, Is.EqualTo(dualChannel.PublisherSessionId)); } else { Assert.That(publisherId, Is.EqualTo(null)); } }
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 async Task ComplexPositionalTupleServiceAddComplex() { WampPlayground playground = new WampPlayground(); var channel = await SetupService <PositionalTupleComplexResultService>(playground); MockRawCallback callback = new MockRawCallback(); Dictionary <string, object> argumentsKeywords = new Dictionary <string, object>() { { "a", 2 }, { "ai", 3 }, { "b", 4 }, { "bi", 5 } }; channel.RealmProxy.RpcCatalog.Invoke (callback, new CallOptions(), "com.myapp.add_complex", new object[0], argumentsKeywords); Assert.That(callback.Arguments.Select(x => x.Deserialize <int>()), Is.EquivalentTo(new[] { 6, 8 })); }
private static async Task RawTest(bool hasSessionId, RegisterOptions registerOptions, CallOptions callOptions) { WampPlayground playground = new WampPlayground(); CallerCallee dualChannel = await playground.GetCallerCalleeDualChannel(); IWampChannel calleeChannel = dualChannel.CalleeChannel; IWampChannel callerChannel = dualChannel.CallerChannel; MyOperation myOperation = new MyOperation(); await calleeChannel.RealmProxy.RpcCatalog.Register(myOperation, registerOptions); MyCallback myCallback = new MyCallback(); callerChannel.RealmProxy.RpcCatalog.Invoke(myCallback, callOptions, myOperation.Procedure); long?expectedCaller = null; if (hasSessionId) { expectedCaller = dualChannel.CallerSessionId; } if (callOptions.DiscloseMe == false && registerOptions.DiscloseCaller == true) { Assert.That(myCallback.ErrorUri, Is.EqualTo(WampErrors.DiscloseMeNotAllowed)); } else { Assert.That(myOperation.Details.Caller, Is.EqualTo(expectedCaller)); } }
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); }
public async Task ProgressiveCallsCallerProgress() { WampPlayground playground = new WampPlayground(); CallerCallee dualChannel = await playground.GetCallerCalleeDualChannel(); IWampChannel calleeChannel = dualChannel.CalleeChannel; IWampChannel callerChannel = dualChannel.CallerChannel; await calleeChannel.RealmProxy.Services.RegisterCallee(new LongOpService()); MyCallback callback = new MyCallback(); callerChannel.RealmProxy.RpcCatalog.Invoke (callback, new CallOptions() { ReceiveProgress = true }, "com.myapp.longop", new object[] { 10 }); callback.Task.Wait(2000); CollectionAssert.AreEquivalent(Enumerable.Range(0, 10), callback.ProgressiveResults); Assert.That(callback.Task.Result, Is.EqualTo(10)); }
public async Task ProgressiveCallsCalleeProxyProgress() { WampPlayground playground = new WampPlayground(); CallerCallee dualChannel = await playground.GetCallerCalleeDualChannel(); IWampChannel calleeChannel = dualChannel.CalleeChannel; IWampChannel callerChannel = dualChannel.CallerChannel; MyOperation myOperation = new MyOperation(); await calleeChannel.RealmProxy.RpcCatalog.Register(myOperation, new RegisterOptions()); ILongOpService proxy = callerChannel.RealmProxy.Services.GetCalleeProxy <ILongOpService>(); List <int> results = new List <int>(); MyProgress <int> progress = new MyProgress <int>(i => results.Add(i)); Task <int> result = proxy.LongOp(10, progress); result.Wait(); CollectionAssert.AreEquivalent(Enumerable.Range(0, 10), results); Assert.That(result.Result, Is.EqualTo(10)); }
public async Task ProgressiveCallsCallerProgressCancelObservable() { WampPlayground playground = new WampPlayground(); CallerCallee dualChannel = await playground.GetCallerCalleeDualChannel(); IWampChannel calleeChannel = dualChannel.CalleeChannel; IWampChannel callerChannel = dualChannel.CallerChannel; var service = new LongOpObsService(); await calleeChannel.RealmProxy.Services.RegisterCallee(service); MyCallback callback = new MyCallback(); var invocation = callerChannel.RealmProxy.RpcCatalog.Invoke (callback, new CallOptions() { ReceiveProgress = true }, "com.myapp.longop", new object[] { 10, false }); Assert.That(service.State, Is.EqualTo(LongOpObsService.EState.Called)); invocation.Cancel(new CancelOptions()); Assert.That(service.State, Is.EqualTo(LongOpObsService.EState.Cancelled)); }
public async Task LongKeywordTupleServiceCalleeProxy() { WampPlayground playground = new WampPlayground(); CallerCallee dualChannel = await playground.GetCallerCalleeDualChannel(); IWampChannel calleeChannel = dualChannel.CalleeChannel; var registration = await calleeChannel.RealmProxy.RpcCatalog.Register(new LongValueTuplesService.KeywordTupleOperation(), new RegisterOptions()); IWampChannel callerChannel = dualChannel.CallerChannel; ILongValueTuplesServiceProxy proxy = callerChannel.RealmProxy.Services.GetCalleeProxy <ILongValueTuplesServiceProxy>(); string name = "Homer Simpson"; var(item1, item2, item3, item4, item5, item6, item7, item8, length, item9, item10) = proxy.GetLongKeywordTuple(name); Assert.That(item1, Is.EqualTo(name + " " + 0)); Assert.That(item10, Is.EqualTo(name + " " + 9)); Assert.That(length, Is.EqualTo(name.Length)); }
public async void SubscriberGetsEventContextWithPublicationId(bool?acknowledge) { WampPlayground playground = new WampPlayground(); PublisherSubscriber dualChannel = await playground.GetPublisherSubscriberDualChannel(); IWampChannel publisher = dualChannel.Publisher; IWampChannel subscriber = dualChannel.Subscriber; MyOtherSubscriber mySubscriber = new MyOtherSubscriber(); IAsyncDisposable disposable = await subscriber.RealmProxy.Services.RegisterSubscriber (mySubscriber); IWampTopicProxy topicProxy = publisher.RealmProxy.TopicContainer.GetTopicByUri("com.myapp.mytopic2"); long?publish = await topicProxy.Publish (new PublishOptions { Acknowledge = acknowledge }, new object[] { 47, 23, "Hello" }); if (acknowledge == true) { Assert.That(publish, Is.EqualTo(mySubscriber.EventContext.PublicationId)); } else { Assert.That(mySubscriber.EventContext.PublicationId, Is.Not.Null); } }
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 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 async Task ErrorsService(int number, object[] arguments, string errorUri) { WampPlayground playground = new WampPlayground(); var channel = await SetupService <ErrorsService>(playground); IErrorsService proxy = channel.RealmProxy.Services.GetCalleeProxyPortable <IErrorsService>(); Task <int> result = proxy.SqrtAsync(number); if (arguments == null) { Assert.That(result.Exception, Is.Null); Assert.That(result.IsCompleted, Is.True); } else { AggregateException exception = result.Exception; Exception actualException = exception.InnerException; Assert.That(actualException, Is.TypeOf <WampException>()); WampException wampException = actualException as WampException; Assert.That(wampException.Arguments, Is.EquivalentTo(arguments.Select(x => playground.Binding.Formatter.Serialize(x))) .Using(playground.EqualityComparer)); Assert.That(wampException.ErrorUri, Is.EqualTo(errorUri)); } }
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 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 async Task LongPositionalTupleServiceCalleeProxy() { WampPlayground playground = new WampPlayground(); var channel = await SetupService <LongValueTuplesService>(playground); ILongValueTuplesServiceProxy proxy = channel.RealmProxy.Services.GetCalleeProxyPortable <ILongValueTuplesServiceProxy>(); string name = "Homer Simpson"; //(string item1, string item2, string item3, string item4, string item5, string item6, string item7, string item8, string item9, string item10, int length) = // proxy.GetLongPositionalTuple(name); ValueTuple <string, string, string, string, string, string, string, ValueTuple <string, string, string, int> > expr_3E = proxy.GetLongPositionalTuple(name); string item1 = expr_3E.Item1; string item2 = expr_3E.Item2; string item3 = expr_3E.Item3; string item4 = expr_3E.Item4; string item5 = expr_3E.Item5; string item6 = expr_3E.Item6; string item7 = expr_3E.Item7; string item8 = expr_3E.Rest.Item1; string item9 = expr_3E.Rest.Item2; string item10 = expr_3E.Rest.Item3; int length = expr_3E.Rest.Item4; Assert.That(item1, Is.EqualTo(name + " " + 0)); Assert.That(item10, Is.EqualTo(name + " " + 9)); Assert.That(length, Is.EqualTo(name.Length)); }
public async Task SubscriberGetsArgumentsArrayEventAsPositionalTuple() { WampPlayground playground = new WampPlayground(); PublisherSubscriber dualChannel = await playground.GetPublisherSubscriberDualChannel(); IWampChannel publisher = dualChannel.Publisher; IWampChannel subscriber = dualChannel.Subscriber; var subject = subscriber.RealmProxy.Services.GetSubject ("com.myapp.topic2", new MyPositionalTupleEventConverter()); MyPositionalSubscriber mySubscriber = new MyPositionalSubscriber(); subject.Subscribe(mySubscriber); IWampTopicProxy topicProxy = publisher.RealmProxy.TopicContainer.GetTopicByUri("com.myapp.topic2"); long?publish = await topicProxy.Publish(new PublishOptions(), new object[] { "Hello", 47, 23, }); Assert.That(mySubscriber.Number1, Is.EqualTo(47)); Assert.That(mySubscriber.Number2, Is.EqualTo(23)); Assert.That(mySubscriber.C, Is.EqualTo("Hello")); }
public async Task ArgumentsStarsDefaultValues(string nick, int?stars, string result) { WampPlayground playground = new WampPlayground(); var channel = await SetupService <ArgumentsService>(playground); MockRawCallback callback = new MockRawCallback(); Dictionary <string, object> argumentsKeywords = new Dictionary <string, object>(); if (nick != null) { argumentsKeywords["nick"] = nick; } if (stars != null) { argumentsKeywords["stars"] = stars; } channel.RealmProxy.RpcCatalog.Invoke (callback, new CallOptions(), "com.arguments.stars", new object[0], argumentsKeywords); Assert.That(callback.Arguments.Select(x => x.Deserialize <string>()), Is.EquivalentTo(new[] { result })); }
public async Task PositionalTupleObservableOnNextPublishesEventWithPositionalArguments() { WampPlayground playground = new WampPlayground(); PublisherSubscriber dualChannel = await playground.GetPublisherSubscriberDualChannel(); IWampChannel publisher = dualChannel.Publisher; IWampChannel subscriber = dualChannel.Subscriber; var subject = publisher.RealmProxy.Services.GetSubject ("com.myapp.mytopic2", new MyPositionalTupleEventConverter()); IWampTopicProxy topicProxy = subscriber.RealmProxy.TopicContainer.GetTopicByUri("com.myapp.mytopic2"); MyCustomSubscriber myCustomSubscriber = new MyCustomSubscriber(); IAsyncDisposable subscribe = await topicProxy.Subscribe(myCustomSubscriber, new SubscribeOptions()); // subject.OnNext(("Hello", 37, 23)); subject.OnNext(ValueTuple.Create("Hello", 37, 23)); Assert.That(myCustomSubscriber.ArgumentsKeywords, Is.Null.Or.Empty); ISerializedValue[] arguments = myCustomSubscriber.Arguments; Assert.That(arguments[0].Deserialize <string>(), Is.EqualTo("Hello")); Assert.That(arguments[1].Deserialize <int>(), Is.EqualTo(37)); Assert.That(arguments[2].Deserialize <int>(), Is.EqualTo(23)); }
public async Task ProgressiveCancellationTokenCancelCallsInterrupt() { WampPlayground playground = new WampPlayground(); CallerCallee dualChannel = await playground.GetCallerCalleeDualChannel(); IWampChannel calleeChannel = dualChannel.CalleeChannel; IWampChannel callerChannel = dualChannel.CallerChannel; MyCancellableOperation myOperation = new MyCancellableOperation("com.myapp.longop"); await calleeChannel.RealmProxy.RpcCatalog.Register(myOperation, new RegisterOptions()); ICancellableLongOpService proxy = callerChannel.RealmProxy.Services.GetCalleeProxyPortable <ICancellableLongOpService>(); CancellationTokenSource tokenSource = new CancellationTokenSource(); MyProgress <int> progress = new MyProgress <int>(x => { }); Task <int> result = proxy.LongOp(10, progress, tokenSource.Token); Assert.That(myOperation.CancellableInvocation.InterruptCalled, Is.False); tokenSource.Cancel(); Assert.That(myOperation.CancellableInvocation.InterruptCalled, Is.True); }
public async Task CancelCallsCalleeCancellationToken() { WampPlayground playground = new WampPlayground(); CallerCallee dualChannel = await playground.GetCallerCalleeDualChannel(); IWampChannel calleeChannel = dualChannel.CalleeChannel; IWampChannel callerChannel = dualChannel.CallerChannel; CancellableService service = new CancellableService(); await calleeChannel.RealmProxy.Services.RegisterCallee(service); MyCallback callback = new MyCallback(); IWampCancellableInvocationProxy cancellable = callerChannel.RealmProxy.RpcCatalog.Invoke (callback, new CallOptions() { ReceiveProgress = true }, "com.myapp.cancellable", new object[] { 100 }); Assert.That(service.CancellationToken, Is.Not.Null); Assert.That(service.CancellationToken.IsCancellationRequested, Is.False); cancellable.Cancel(new CancelOptions()); Assert.That(service.CancellationToken.IsCancellationRequested, Is.True); }
public async Task BasicTestamentServiceTest(bool flushTestaments) { WampPlayground playground = new WampPlayground(); playground.Host.RealmContainer.GetRealmByName("realm1") .HostTestamentService(); PublisherSubscriber publisherSubscriber = await playground.GetPublisherSubscriberDualChannel(); MySubscriber mySubscriber = new MySubscriber(); await publisherSubscriber.Subscriber.RealmProxy.Services .RegisterSubscriber(mySubscriber); MyClass instance = new MyClass() { Counter = 1, Foo = new int[] { 1, 2, 3 } }; await publisherSubscriber .Publisher.RealmProxy.GetTestamentServiceProxy() .AddTestamentAsync("com.myapp.topic2", new object[] { 47, 23 }, new Dictionary <string, object>() { { "c", "Hello" }, { "d", instance } }); Assert.That(mySubscriber.Counter, Is.EqualTo(0)); if (flushTestaments) { await publisherSubscriber.Publisher.RealmProxy.GetTestamentServiceProxy().FlushTestamentsAsync(); } publisherSubscriber.Publisher.Close(); if (flushTestaments) { Assert.That(mySubscriber.Counter, Is.EqualTo(0)); } else { Assert.That(mySubscriber.Counter, Is.EqualTo(1)); Assert.That(mySubscriber.Number1, Is.EqualTo(47)); Assert.That(mySubscriber.Number2, Is.EqualTo(23)); Assert.That(mySubscriber.C, Is.EqualTo("Hello")); Assert.That(mySubscriber.D, Is.EqualTo(instance)); } }
public async Task SubscriberGetsRetainedEvent(bool?publishRetained, bool?getRetained, int expectedCount, bool?acknowledge = null) { WampPlayground playground = new WampPlayground(); playground.Host.Open(); ChannelWithExtraData publisher = await playground.GetChannel().ConfigureAwait(false); ChannelWithExtraData subscriber = await playground.GetChannel().ConfigureAwait(false); IWampTopicProxy topicProxy = publisher.Channel.RealmProxy.TopicContainer.GetTopicByUri ("com.myapp.mytopic2"); long?lastPublicationId = null; for (int i = 0; i <= 42; i++) { lastPublicationId = await topicProxy.Publish (new PublishOptions { Retain = publishRetained, Acknowledge = acknowledge }, new object[] { i, 23, "Hello" }); } publisher.Channel.Close(); MyOtherSubscriber mySubscriber = new MyOtherSubscriber(); IAsyncDisposable disposable = await subscriber.Channel.RealmProxy.Services.RegisterSubscriber(mySubscriber, new SubscriberRegistrationInterceptor(new SubscribeOptions() { GetRetained = getRetained })) .ConfigureAwait(false); Assert.That(mySubscriber.Parameters.Count, Is.EqualTo(expectedCount)); if (expectedCount == 1) { MyTopic2Parameters actual = mySubscriber.Parameters[0]; Assert.That(actual.Number1, Is.EqualTo(42)); Assert.That(actual.Number2, Is.EqualTo(23)); Assert.That(actual.C, Is.EqualTo("Hello")); Assert.That(actual.EventContext.EventDetails.Retained, Is.EqualTo(true)); if (acknowledge == true) { Assert.That(actual.EventContext.PublicationId, Is.EqualTo(lastPublicationId)); } } }
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 async Task ArgumentsAdd2Async() { WampPlayground playground = new WampPlayground(); var channel = await SetupService <ArgumentsService>(playground); IArgumentsService proxy = channel.RealmProxy.Services.GetCalleeProxyPortable <IArgumentsService>(); Task <int> task = proxy.Add2Async(2, 3); Assert.That(task.Result, Is.EqualTo(5)); }
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)); }