public void MutipleGenericRequestHandler_ByDifferentNameSpace_ShouldResponse() { var eventBus = new InProcessServiceBus(); eventBus.AddRequestHandler <TestRequestDataT <TestEventData> >((eventData, context) => { return(Task.Run(() => { context.Response = eventData.Msg + "1"; })); }); eventBus.AddRequestHandler <TestRequestDataT <TestDemo.TestEventData> >((eventData, context) => { return(Task.Run(() => { context.Response = context.Response + "2"; })); }); var testRequestData = new TestRequestDataT <TestEventData>(new TestEventData()) { Msg = "success" }; var result = eventBus.Send <string>(testRequestData); Assert.AreEqual(testRequestData.Msg + "12", result); }
public void MutipleRequestHandler_ShouldResponseForPipeline_ReturnFirst() { var eventBus = new InProcessServiceBus(); eventBus.AddRequestHandler <TestRequestData>((eventData, context) => { return(Task.Run(() => { context.Response = eventData.Msg + "1"; context.IsEnd = true; })); }); eventBus.AddRequestHandler <TestRequestData>((eventData, context) => { return(Task.Run(() => { context.Response = context.Response + "2"; })); }); var testRequestData = new TestRequestData() { Msg = "success" }; var result = eventBus.Send <string>(testRequestData); Assert.AreEqual(testRequestData.Msg + "1", result); }
public async Task Saga_StartsWithCommand() { var command = new FakeStartingCommand(new MyDomainId(Guid.NewGuid()), correlationId, "abc", "user_tester"); await serviceBus.Send(command); var commands = serviceBus.SentCommands(); Assert.Equal(2, commands.Count); Assert.IsType <FakeStep2Command>(commands[1]); Assert.Equal("abc", ((FakeStep2Command)commands[1]).Value1); var data = await inMemorySagaRepository.GetById <SagaToTest.MyData>(correlationId); Assert.Null(data); }
public void Request_ShouldResponse() { var eventBus = new InProcessServiceBus(); eventBus.AddRequestHandler <TestRequestData>((eventData, context) => { return(Task.Run(() => { context.Response = 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); }