Ejemplo n.º 1
0
        public void ShouldClearAllSubscriptions()
        {
            var coursier = new Coursier();

            var msgOneReceived = false;
            var msgTwoReceived = false;

            coursier.Subscribe <TestMessageOne>(msg => { msgOneReceived = true; });
            coursier.Subscribe <TestMessageTwo>(msg => { msgTwoReceived = true; });

            coursier.ClearAllSubscriptions();

            coursier.Publish(new TestMessageOne(this));
            coursier.Publish(new TestMessageTwo(this));

            Assert.False(msgOneReceived);
            Assert.False(msgTwoReceived);
        }
Ejemplo n.º 2
0
        public void ShouldNotRunOnThreadPoolThread()
        {
            var coursier = new Coursier();

            coursier.SubscribeOnThreadPoolThread <TestMessageOne>(msg =>
            {
                Assert.False(Thread.CurrentThread.IsBackground);
            });

            coursier.Publish(new TestMessageOne(this));
        }
Ejemplo n.º 3
0
        public void ShouldPublishMessage()
        {
            var coursier    = new Coursier();
            var msgReceived = false;

            coursier.Subscribe <TestMessageOne>(msg =>
            {
                msgReceived = true;
            });

            coursier.Publish(new TestMessageOne(this));

            Assert.True(msgReceived);
        }
Ejemplo n.º 4
0
        public void ShouldNotReceiveMessageIfUnSubscribed()
        {
            var coursier    = new Coursier();
            var msgReceived = false;

            var token = coursier.Subscribe <TestMessageOne>(msg =>
            {
                msgReceived = true;
            });

            coursier.Unsubscribe <TestMessageOne>(token);

            coursier.Publish(new TestMessageOne(this));

            Assert.False(msgReceived);
        }
Ejemplo n.º 5
0
        public void ShouldRegisterAndInvokeAsyncHandler()
        {
            var coursier    = new Coursier();
            var msgReceived = false;

            coursier.Subscribe <TestMessageOne>(async msg =>
            {
                await Task.Run(() =>
                {
                    msgReceived = true;
                });
            });

            coursier.Publish(new TestMessageOne(this));

            Thread.Sleep(1000);

            Assert.True(msgReceived);
        }
Ejemplo n.º 6
0
        public void ShouldThrowIfMessageIsNull()
        {
            var coursier = new Coursier();

            Assert.Throws <NullReferenceException>(() => coursier.Publish <TestMessageOne>(null));
        }