Пример #1
0
        public void MutipleGenericSubscription_ByDifferentNameSpace_ShouldTrigger()
        {
            var eventBus = new InProcessServiceBus();
            var result   = "error";
            var result2  = "error";

            eventBus.AddSubscription <TestEventDataT <TestEventData> >(eventData =>
            {
                return(Task.Run(() =>
                {
                    result = eventData.Msg;
                }));
            });

            eventBus.AddSubscription <TestEventDataT <TestDemo.TestEventData> >(eventData =>
            {
                return(Task.Run(() =>
                {
                    result2 = eventData.Msg;
                }));
            });

            var testEventData = new TestEventDataT <TestEventData>(new TestEventData())
            {
                Msg = "success"
            };

            eventBus.PublishSync(testEventData);


            Assert.AreEqual(testEventData.Msg, result);
            Assert.AreEqual(testEventData.Msg, result2);
        }
Пример #2
0
        public void ShouldSupport_MutipleSameHandler()
        {
            var eventBus = new InProcessServiceBus();
            var result1  = "error";
            var result2  = "error";

            eventBus.AddSubscription <TestEventData>(eventData =>
            {
                return(Task.Run(() =>
                {
                    result1 = eventData.Msg;
                }));
            });

            eventBus.AddSubscription <TestEventData>(eventData =>
            {
                return(Task.Run(() =>
                {
                    result2 = eventData.Msg;
                }));
            });

            var testEventData = new TestEventData()
            {
                Msg = "success"
            };

            eventBus.PublishSync(testEventData);


            Assert.AreEqual(testEventData.Msg, result1);
            Assert.AreEqual(testEventData.Msg, result2);
        }
Пример #3
0
        public void MutipleSubscription_ShouldTrigger()
        {
            var eventBus = new InProcessServiceBus();
            var result   = "error";

            eventBus.AddSubscription <TestEventData>(eventData =>
            {
                return(Task.Run(() =>
                {
                    result = eventData.Msg + "1";
                }));
            });

            eventBus.AddSubscription <TestEventData>(eventData =>
            {
                return(Task.Run(() =>
                {
                    result = eventData.Msg + "2";
                }));
            });

            var testEventData = new TestEventData()
            {
                Msg = "success"
            };

            eventBus.PublishSync(testEventData);


            Assert.AreEqual(testEventData.Msg + "2", result);
        }
Пример #4
0
        public void Subscription_ShouldNotTrigger_AfterRemove()
        {
            var eventBus = new InProcessServiceBus();
            var result   = "error";

            Func <TestEventData, Task> delateFunc = eventData =>
            {
                return(Task.Run(() =>
                {
                    result = eventData.Msg;
                }));
            };

            eventBus.AddSubscription <TestEventData>(delateFunc);

            var testEventData = new TestEventData()
            {
                Msg = "success"
            };

            eventBus.PublishSync(testEventData);

            Assert.AreEqual(testEventData.Msg, result);

            result = "error";
            eventBus.RemoveSubscription <TestEventData>(delateFunc);
            eventBus.PublishSync(testEventData);
            Assert.AreNotEqual(testEventData.Msg, result);
        }
Пример #5
0
        public void SubscriptionEventDataWithParam_ShouldTrigger()
        {
            var eventBus = new InProcessServiceBus();
            var result   = "error";

            eventBus.AddSubscription <TestEventDataWithParam>(eventData =>
            {
                return(Task.Run(() =>
                {
                    result = eventData.Msg;
                }));
            });

            var testEventData = new TestEventDataWithParam("success");

            eventBus.PublishSync(testEventData);


            Assert.AreEqual(testEventData.Msg, result);
        }