Exemplo n.º 1
0
        public void FeedProvidersRegisteredTwiceFailureTest()
        {
            DataBus        db            = new DataBus();
            MyFeedProvider feedProvider1 = new MyFeedProvider();

            db.RegisterFeedProvider("MyChannel", feedProvider1);
            db.RegisterFeedProvider("MyChannel", feedProvider1);


            db.Channel <string>("MyChannel").Feed(1);
        }
Exemplo n.º 2
0
        public void TwoFeedProvidersForSameContextFailureTest()
        {
            DataBus        db            = new DataBus();
            MyFeedProvider feedProvider1 = new MyFeedProvider();
            MyFeedProvider feedProvider2 = new MyFeedProvider();

            db.RegisterFeedProvider("MyChannel", feedProvider1);
            db.RegisterFeedProvider("MyChannel", feedProvider2);


            db.Channel <string>("MyChannel").Feed(1);
        }
Exemplo n.º 3
0
        public void CanSubscribeReturnsFalseFailureTest()
        {
            DataBus        db           = new DataBus();
            MyFeedProvider feedProvider = new MyFeedProvider();

            db.RegisterFeedProvider("MyChannel", feedProvider);

            try
            {
                db.Channel <string>("MyChannel").Feed(2);
            }
            finally
            {
                Assert.IsTrue(feedProvider.CanProvideForWasCalled, "IFeedProvider.CanProvideFor was not called");
            }
        }
Exemplo n.º 4
0
        public void NeverRequestFeedForTheSameContextTwiceTest()
        {
            DataBus        db           = new DataBus();
            MyFeedProvider feedProvider = new MyFeedProvider();

            db.RegisterFeedProvider("MyChannel", feedProvider);
            AutoResetEvent ev  = new AutoResetEvent(false);
            AutoResetEvent ev1 = new AutoResetEvent(false);

            int[] c             = { 0, 0 };
            var   subscribtion1 = db.Channel <string>("MyChannel").Feed(1).Subscribe(s =>
            {
                Console.WriteLine("subscribtion1\t" + s);
                if (++c[0] == 5)
                {
                    ev.Set();
                }
            });
            var subscribtion2 = db.Channel <string>("MyChannel").Feed(1).Subscribe(s =>
            {
                Console.WriteLine("subscribtion2\t" + s);
                if (++c[1] == 5)
                {
                    ev1.Set();
                }
            });

            using (subscribtion1)
            {
                using (subscribtion2)
                {
                    Assert.IsTrue(ev.WaitOne(1000), "Subscribtion handler was not called");
                    Assert.IsTrue(ev1.WaitOne(1000), "Subscribtion handler was not called");
                }
            }

            Assert.AreNotEqual(0, feedProvider.SubscribeCounters[1], "Subscriber was  not subscribed to the feed ");
            Assert.AreNotEqual(0, feedProvider.UnsubscribeCounters[1], "Subscriber was  not unsubscribed from the feed ");
            Assert.AreEqual(1, feedProvider.SubscribeCounters[1], "Subscriber was subscribed more then 1 time to the same feed ");
            Assert.AreEqual(1, feedProvider.UnsubscribeCounters[1], "Subscriber was unsubscribed more then 1 time from the same feed ");
        }