Esempio n. 1
0
        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));
                }
            }
        }