public void MicroServiceResponseCorrelatesToRequest() { var options = new BusOptions() { QueueName = "CallbackTest02" }; var serviceMock = new CallbackMock(); using (var host = new MicroserviceHost <CallbackMock>(serviceMock, options)) using (var proxy = new MicroserviceProxy(options)) { host.Open(); RequestCommand requestCommand = new RequestCommand { Name = "Marco" }; SlowRequestCommand slowCommand = new SlowRequestCommand { Name = "Slow" }; TestResponse slowResponse = proxy.Execute <TestResponse>(slowCommand); TestResponse response = proxy.Execute <TestResponse>(requestCommand); Assert.Equal("Hello, Marco", response.Greeting); Assert.Equal("Hello, Slow", slowResponse.Greeting); } }
public void ProxySendsCommandsAndTheyAreReceivedCorrectly() { var options = new BusOptions() { QueueName = "ProxyTestQueue02" }; var serviceMock = new OtherMicroserviceMock(); using (var host = new MicroserviceHost <OtherMicroserviceMock>(serviceMock, options)) using (var proxy = new MicroserviceProxy(options)) { host.Open(); var command = new SomeCommand() { SomeValue = "teststring" }; proxy.Execute(command); serviceMock.ReceivedFlag.WaitOne(500); Assert.True(serviceMock.SomeCommandHandlerHasBeenCalled); Assert.Equal("teststring", serviceMock.SomeCommandHandlerReceivedSomeCommand.SomeValue); } }
public void HandlerNotInInterfaceShouldNotBeTriggered2() { var options = new BusOptions() { QueueName = "TestQueue02" }; var serviceMock = new HalfServiceMock(); using (var host = new MicroserviceHost <HalfServiceMock>(serviceMock, options)) using (var proxy = new MicroserviceProxy(options)) { host.Open(); var command = new TestCommand(); proxy.Execute(command); Thread.Sleep(500); Assert.True(serviceMock.TestCommandHandlerHasBeenCalled); } }
public void HandlerNotInInterfaceShouldNotBeTriggered() { var options = new BusOptions() { QueueName = "TestQueue01" }; var serviceMock = new HalfServiceMock(); using (var host = new MicroserviceHost <HalfServiceMock>(serviceMock, options)) using (var proxy = new MicroserviceProxy(options)) { host.Open(); var command = new SomeCommand() { SomeValue = "teststring" }; Action action = () => proxy.Execute(command); Assert.Throws <MicroserviceException>(action); Assert.False(serviceMock.SomeCommandHandlerHasBeenCalled); } }
public void MicroServiceThrowsException() { // Arrange var options = new BusOptions() { QueueName = "ExceptionThrowingTest01" }; using (var host = new MicroserviceHost <ExceptionThrowingService>(options)) using (var proxy = new MicroserviceProxy(options)) { host.Open(); // Act WorkCommand command = new WorkCommand { Name = "Marco" }; Action action = () => proxy.Execute(command); // Assert Assert.Throws <NotImplementedException>(action); } }
public void ProxySendsCommands() { var options = new BusOptions() { QueueName = "ProxyTestQueue01" }; var serviceMock = new OtherMicroserviceMock(); using (var host = new MicroserviceHost <OtherMicroserviceMock>(serviceMock, options)) using (var proxy = new MicroserviceProxy(options)) { host.Open(); var command = new SomeCommand() { SomeValue = "teststring" }; proxy.Execute(command); Thread.Sleep(500); Assert.True(serviceMock.SomeCommandHandlerHasBeenCalled); } }