public async Task ShouldRaiseException_WhenSendSetOption() { var eventBus = new InProcessServiceBus(); eventBus.AddDynamicRequestHandler(typeof(TestRequestData).Name, (requestData, requetContext) => { return(Task.Run(() => { throw new Exception("Test Exception"); })); }); var testRequestData = new TestRequestData() { Msg = "success" }; await eventBus.SendAsync <string>(testRequestData, new TriggerOption(false)); }
public void DynamicRequest_ShouldResponse() { var eventBus = new InProcessServiceBus(); eventBus.AddDynamicRequestHandler(typeof(TestRequestData).Name, (eventData, context) => { return(Task.Run(() => { context.Response = (string)eventData.Msg; })); }); var testRequestData = new TestRequestData() { Msg = "success" }; var result = eventBus.Send <string>(testRequestData); Assert.AreEqual(testRequestData.Msg, result); }
public void DynamicRequest_ShouldNotResponse_AfterRemove() { var eventBus = new InProcessServiceBus(); Func <dynamic, IRequestHandlerContext, Task> delateFunc = (eventData, context) => { return(Task.Run(() => { context.Response = (string)eventData.Msg; })); }; eventBus.AddDynamicRequestHandler(typeof(TestRequestData).Name, delateFunc); eventBus.RemoveDynamicRequestHandler(typeof(TestRequestData).Name, delateFunc); var testRequestData = new TestRequestData() { Msg = "success" }; var result = eventBus.Send <string>(testRequestData); Assert.AreEqual(null, result); }