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 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 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 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 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 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 SubscriberGetsArgumentsKeywordsEventAsKeywordTuple()
        {
            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 MyKeywordTupleEventConverter());

            MyKeywordSubscriber mySubscriber = new MyKeywordSubscriber();

            subject.Subscribe(mySubscriber);

            IWampTopicProxy topicProxy =
                publisher.RealmProxy.TopicContainer.GetTopicByUri("com.myapp.topic2");

            MyClass instance = new MyClass()
            {
                Counter = 1,
                Foo     = new[] { 1, 2, 3 }
            };

            long?publish =
                await topicProxy.Publish(new PublishOptions(),
                                         new object[0],
                                         new Dictionary <string, object>()
            {
                { "number1", 47 },
                { "d", instance },
                { "c", "Hello" },
                { "number2", 23 },
            });

            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));
        }
Example #8
0
        public async Task PrefixPubSubTest()
        {
            WampPlayground playground = new WampPlayground();

            PublisherSubscriber dualChannel =
                await playground.GetPublisherSubscriberDualChannel();

            IWampChannel publisherChannel  = dualChannel.Publisher;
            IWampChannel subscriberChannel = dualChannel.Subscriber;

            var mySubscriber = new MyPrefixSubscriber();

            Task <IAsyncDisposable> subscribeTask =
                subscriberChannel
                .RealmProxy.Services.RegisterSubscriber
                    (mySubscriber,
                    new SubscriberRegistrationInterceptor(
                        new SubscribeOptions()
            {
                Match = "prefix"
            }));

            await subscribeTask;

            string msg     = "Hello prefix pattern subscriber!";
            int    counter = 0;

            // these are all received
            Publish(publisherChannel, "com.myapp.topic1.foobar", new object[] { msg, counter++ });
            Publish(publisherChannel, "com.myapp.topic1", new object[] { msg, counter++ });
            Publish(publisherChannel, "com.myapp.topi", new object[] { msg, counter++ });
            Publish(publisherChannel, "com.myapp2.foobar", new object[] { msg, counter++ });
            Publish(publisherChannel, "com.myapp2", new object[] { msg, counter++ });
            Publish(publisherChannel, "com.myapp.2", new object[] { msg, counter++ });
            Publish(publisherChannel, "com.myapp", new object[] { msg, counter++ });

            // these are not received
            Publish(publisherChannel, "com.app.topic1", new object[] { msg, counter++ });
            Publish(publisherChannel, "com.myap", new object[] { msg, counter++ });
            Publish(publisherChannel, "com", new object[] { msg, counter++ });

            CollectionAssert.AreEquivalent(Enumerable.Range(0, 7), mySubscriber.Results);
        }
        public async Task PublisherCustomDelegateEventRaisePublishesEventWithKeywordArguments()
        {
            WampPlayground playground = new WampPlayground();

            PublisherSubscriber dualChannel = await playground.GetPublisherSubscriberDualChannel();

            IWampChannel publisher  = dualChannel.Publisher;
            IWampChannel subscriber = dualChannel.Subscriber;

            MyPublisher myPublisher = new MyPublisher();

            IDisposable disposable =
                publisher.RealmProxy.Services.RegisterPublisher
                    (myPublisher);

            IWampTopicProxy topicProxy =
                subscriber.RealmProxy.TopicContainer.GetTopicByUri("com.myapp.topic2");

            MyCustomSubscriber myCustomSubscriber = new MyCustomSubscriber();

            IAsyncDisposable subscribe =
                await topicProxy.Subscribe(myCustomSubscriber,
                                           new SubscribeOptions());

            MyClass instance = new MyClass()
            {
                Counter = 1,
                Foo     = new[] { 1, 2, 3 }
            };

            myPublisher.RaiseMyEvent(37, 23, "Hello", instance);

            Assert.That(myCustomSubscriber.Arguments, Is.Empty);

            IDictionary <string, ISerializedValue> argumentsKeywords =
                myCustomSubscriber.ArgumentsKeywords;

            Assert.That(argumentsKeywords["number1"].Deserialize <int>(), Is.EqualTo(37));
            Assert.That(argumentsKeywords["number2"].Deserialize <int>(), Is.EqualTo(23));
            Assert.That(argumentsKeywords["c"].Deserialize <string>(), Is.EqualTo("Hello"));
            Assert.That(argumentsKeywords["d"].Deserialize <MyClass>(), Is.EqualTo(instance));
        }
        public async Task SubscriberGetsEventAsParameters()
        {
            WampPlayground playground = new WampPlayground();

            PublisherSubscriber dualChannel = await playground.GetPublisherSubscriberDualChannel();

            IWampChannel publisher  = dualChannel.Publisher;
            IWampChannel subscriber = dualChannel.Subscriber;

            MySubscriber mySubscriber = new MySubscriber();

            IAsyncDisposable disposable =
                await subscriber.RealmProxy.Services.RegisterSubscriber
                    (mySubscriber);

            IWampTopicProxy topicProxy =
                publisher.RealmProxy.TopicContainer.GetTopicByUri("com.myapp.topic2");

            MyClass instance = new MyClass()
            {
                Counter = 1,
                Foo     = new[] { 1, 2, 3 }
            };

            long?publish =
                await topicProxy.Publish(new PublishOptions(), new object[]
            {
                47,
                23,
            },
                                         new Dictionary <string, object>()
            {
                { "d", instance },
                { "c", "Hello" }
            });


            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 KeywordTupleObservableOnNextPublishesEventWithPositionalArguments()
        {
            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.topic2",
                    new MyKeywordTupleEventConverter());

            IWampTopicProxy topicProxy =
                subscriber.RealmProxy.TopicContainer.GetTopicByUri("com.myapp.topic2");

            MyCustomSubscriber myCustomSubscriber = new MyCustomSubscriber();

            IAsyncDisposable subscribe =
                await topicProxy.Subscribe(myCustomSubscriber,
                                           new SubscribeOptions());

            MyClass instance = new MyClass()
            {
                Counter = 1,
                Foo     = new[] { 1, 2, 3 }
            };

            // subject.OnNext((37, 23, "Hello", instance))
            subject.OnNext(ValueTuple.Create(37, 23, "Hello", instance));

            Assert.That(myCustomSubscriber.Arguments, Is.Empty);

            IDictionary <string, ISerializedValue> argumentsKeywords =
                myCustomSubscriber.ArgumentsKeywords;

            Assert.That(argumentsKeywords["number1"].Deserialize <int>(), Is.EqualTo(37));
            Assert.That(argumentsKeywords["number2"].Deserialize <int>(), Is.EqualTo(23));
            Assert.That(argumentsKeywords["c"].Deserialize <string>(), Is.EqualTo("Hello"));
            Assert.That(argumentsKeywords["d"].Deserialize <MyClass>(), Is.EqualTo(instance));
        }
Example #12
0
        public async Task WildCardPubSubTest()
        {
            WampPlayground playground = new WampPlayground();

            PublisherSubscriber dualChannel =
                await playground.GetPublisherSubscriberDualChannel();

            IWampChannel publisherChannel  = dualChannel.Publisher;
            IWampChannel subscriberChannel = dualChannel.Subscriber;

            var mySubscriber = new MyWildcardSubscriber();

            Task <IAsyncDisposable> subscribeTask =
                subscriberChannel
                .RealmProxy.Services.RegisterSubscriber
                    (mySubscriber,
                    new SubscriberRegistrationInterceptor(
                        new SubscribeOptions()
            {
                Match = "wildcard"
            }));

            await subscribeTask;

            string msg     = "Hello wildcard pattern subscriber!";
            int    counter = 0;

            // these are all received
            Publish(publisherChannel, "com.example.foobar.create", new object[] { msg, counter++ });
            Publish(publisherChannel, "com.example.1.create", new object[] { msg, counter++ });

            // these are not received
            Publish(publisherChannel, "com.example.foobar.delete", new object[] { msg, counter++ });
            Publish(publisherChannel, "com.example.foobar.create2", new object[] { msg, counter++ });
            Publish(publisherChannel, "com.example.foobar.create.barbaz", new object[] { msg, counter++ });
            Publish(publisherChannel, "com.example.foobar", new object[] { msg, counter++ });
            Publish(publisherChannel, "com.example.create", new object[] { msg, counter++ });
            Publish(publisherChannel, "com.example", new object[] { msg, counter++ });

            CollectionAssert.AreEquivalent(Enumerable.Range(0, 2), mySubscriber.Results);
        }