public void Can_provide_null_route_finder() { // Arrange InternalDependencies.RpcQueueHelper = Substitute.For <IRpcQueueHelper>(); // Action new BurrowRpcClientCoordinator <ISomeService>("host=anyhost;username=guest;password=guest"); // Assert tunnel.Received(1).SetRouteFinder(Arg.Is <IRouteFinder>(arg => arg is RpcRouteFinderAdapter)); }
public void Should_create_tunnel_and_set_serializer_and_route_finder() { // Arrange var routeFinder = Substitute.For <IRpcRouteFinder>(); var instance = Substitute.For <ISomeService>(); var server = new BurrowRpcServerCoordinator <ISomeService>(instance, routeFinder, "queue-connnection-string"); // Action server.Start(); // Assert tunnel.Received(1).SetRouteFinder(Arg.Any <IRouteFinder>()); tunnel.Received(1).SetSerializer(Arg.Any <ISerializer>()); }
public void Should_publish_request_with_address() { // Arrange var routeFinder = Substitute.For <IRpcRouteFinder>(); routeFinder.RequestQueue.Returns("RequestQueue"); InternalDependencies.RpcQueueHelper = Substitute.For <IRpcQueueHelper>(); var client = new BurrowRpcClientCoordinator <ISomeService>(null, routeFinder); var res = new RpcRequest { MethodName = "TryParse", Id = Guid.NewGuid(), UtcExpiryTime = DateTime.UtcNow.AddSeconds(20), }; tunnel.When(x => x.Publish(Arg.Any <RpcRequest>(), Arg.Any <string>())) .Do(callInfo => { var waithHandler = client.GetCachedWaitHandlers()[res.Id]; waithHandler.WaitHandle.Set(); waithHandler.Response = new RpcResponse { ChangedParams = new Dictionary <string, object> { { "result", "1000" } } }; }); // Action client.Send(res); // Assert tunnel.Received(1).Publish(Arg.Any <RpcRequest>(), "RequestQueue"); }
public void Should_publish_respones_with_Exception_if_method_not_match() { // Arrange var routeFinder = Substitute.For <IRpcRouteFinder>(); var instance = Substitute.For <ISomeService>(); var server = new BurrowRpcServerCoordinator <ISomeService>(instance, routeFinder, "queue-connnection-string", "10"); var request = new RpcRequest { Id = Guid.NewGuid(), ResponseAddress = "Address" }; // Action server.Start(); server.HandleMesage(request); // Assert tunnel.Received(1).Publish(Arg.Is <RpcResponse>(arg => arg.Exception != null && arg.RequestId == request.Id), "Address"); }
public void Should_use_DefaulRpcRouteFinder_if_not_provide_serverId() { // Arrange var model = Substitute.For <IModel>(); InternalDependencies.RpcQueueHelper = Substitute.For <IRpcQueueHelper>(); InternalDependencies.RpcQueueHelper .When(x => x.CreateQueues(Arg.Any <string>(), Arg.Any <Action <IModel> >())) .Do(callInfo => callInfo.Arg <Action <IModel> >()(model)); // Action var server = RpcFactory.CreateServer(Substitute.For <ISomeService>()) as BurrowRpcServerCoordinator <ISomeService>; Assert.IsNotNull(server); server.Start(); // Assert model.Received(1).QueueDeclare("Burrow.Queue.Rpc.ISomeService.Requests", true, false, false, Arg.Any <IDictionary <string, object> >()); model.DidNotReceive().ExchangeDeclare(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <bool>(), Arg.Any <bool>(), Arg.Any <IDictionary <string, object> >()); tunnel.Received(1).SubscribeAsync(typeof(ISomeService).Name, Arg.Any <Action <RpcRequest> >()); }
public void Should_publish_request_without_address() { // Arrange InternalDependencies.RpcQueueHelper = Substitute.For <IRpcQueueHelper>(); var client = new BurrowRpcClientCoordinator <ISomeService>(null, Substitute.For <IRpcRouteFinder>()); var res = new RpcRequest { ResponseAddress = "abc" }; // Action client.SendAsync(res); // Assert tunnel.Received(1).Publish(Arg.Any <RpcRequest>(), Arg.Any <string>()); Assert.IsNull(res.ResponseAddress); }
public void Should_use_DefaultFanoutRpcRequestRouteFinder() { // Arrange var model = Substitute.For <IModel>(); InternalDependencies.RpcQueueHelper = Substitute.For <IRpcQueueHelper>(); InternalDependencies.RpcQueueHelper .When(x => x.CreateQueues(Arg.Any <string>(), Arg.Any <Action <IModel> >())) .Do(callInfo => callInfo.Arg <Action <IModel> >()(model)); // Action var server = RpcFactory.CreateFanoutServer(Substitute.For <ISomeService>(), serverId: "ServerId") as BurrowRpcServerCoordinator <ISomeService>; Assert.IsNotNull(server); server.Start(); // Assert model.Received(1).QueueDeclare("Burrow.Queue.Rpc.ServerId.ISomeService.Requests", true, false, true, Arg.Any <IDictionary <string, object> >()); model.Received(1).ExchangeDeclare("Burrow.Exchange.FANOUT.Rpc.ISomeService.Requests", "fanout", true, false, null); tunnel.Received(1).SubscribeAsync("ServerId", Arg.Any <Action <RpcRequest> >()); }