public void DynamicSubscription_ShouldNotTrigger_AfterRemove()
        {
            var eventBus = new InProcessServiceBus();
            var result   = "error";

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

            eventBus.AddDynamicSubscription(typeof(TestEventData).Name, delateFunc);

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

            eventBus.PublishSync(testEventData);

            Assert.AreEqual(testEventData.Msg, result);

            result = "error";
            eventBus.RemoveDynamicSubscription(typeof(TestEventData).Name, delateFunc);
            eventBus.PublishSync(testEventData);
            Assert.AreNotEqual(testEventData.Msg, result);
        }
        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);
        }
        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);
        }
        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);
        }
        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);
        }