예제 #1
0
        public async Task ShouldLogMessage_WhenSetLogDelate()
        {
            var       eventBus         = new InProcessServiceBus();
            var       logMsg           = "";
            var       testException    = new Exception("Test Exception");
            Exception catchedException = null;

            eventBus.OnLogBusMessage += (logLevel, msg, ex) =>
            {
                logMsg           = msg;
                catchedException = ex;
            };
            eventBus.AddDynamicSubscription(typeof(TestEventData).Name, eventData =>
            {
                return(Task.Run(() =>
                {
                    throw testException;
                }));
            });

            var testEventData = new TestEventData()
            {
                Msg = "success"
            };
            await eventBus.Publish(testEventData);

            Assert.AreNotEqual(0, logMsg.Length);
            Assert.AreEqual(testException, catchedException);
        }
예제 #2
0
        public async Task ShouldRaiseException_WhenPublishSetOption()
        {
            var eventBus = new InProcessServiceBus();

            eventBus.AddDynamicSubscription(typeof(TestEventData).Name, eventData =>
            {
                return(Task.Run(() =>
                {
                    throw new Exception("Test Exception");
                }));
            });

            var testEventData = new TestEventData()
            {
                Msg = "success"
            };
            await eventBus.Publish(testEventData, new TriggerOption(false));
        }
예제 #3
0
        public async Task DynamicSubscription_ShouldTrigger()
        {
            var eventBus = new InProcessServiceBus();
            var result   = "error";

            eventBus.AddDynamicSubscription(typeof(TestEventData).Name, eventData =>
            {
                return(Task.Run(() =>
                {
                    result = eventData.Msg;
                }));
            });

            var testEventData = new TestEventData()
            {
                Msg = "success"
            };
            await eventBus.Publish(testEventData);

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