Exemplo n.º 1
0
        public void Should_invoke_method_on_real_instance_and_map_response_params()
        {
            // 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",
                MethodName      = "Search",
                Params          = new Dictionary <string, object> {
                    { "page", (long)1 /* long value will be converted to proper int value */ }, { "query", new SomeMessage
                                                                                                  {
                                                                                                      Name = "vantheshark"
                                                                                                  } }
                }
            };
            var methodInfo = typeof(ISomeService).GetMethod("Search");

            methodMatcher.Match <ISomeService>(request)
            .Returns(methodInfo);

            var returnValue = new List <SomeMessage> {
                new SomeMessage {
                    Money = "$1"
                }, new SomeMessage {
                    Money = "$1"
                }
            };

            instance.Search(1, Arg.Is <SomeMessage>(arg => arg.Name == "vantheshark"))
            .Returns(returnValue);

            // Action
            server.Start();
            server.HandleMesage(request);

            // Assert
            tunnel.Received(1).Publish(Arg.Is <RpcResponse>(arg => arg.Exception == null &&
                                                            arg.ReturnValue == returnValue &&
                                                            arg.ChangedParams["query"] is SomeMessage &&
                                                            1.Equals(arg.ChangedParams["page"]) &&
                                                            arg.RequestId == request.Id), "Address");
        }
Exemplo n.º 2
0
        public void Should_publish_nothing_if_msg_is_Async()
        {
            // 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(),
            };

            // Action
            server.Start();
            server.HandleMesage(request);

            // Assert
            tunnel.DidNotReceive().Publish(Arg.Any<RpcResponse>(), Arg.Any<string>());
        }
Exemplo n.º 3
0
        public void Should_publish_nothing_if_msg_is_Async()
        {
            // 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(),
            };

            // Action
            server.Start();
            server.HandleMesage(request);

            // Assert
            tunnel.DidNotReceive().Publish(Arg.Any <RpcResponse>(), Arg.Any <string>());
        }
Exemplo n.º 4
0
        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");
        }
Exemplo n.º 5
0
        public void Should_print_warn_msg_and_return_if_msg_is_expired()
        {
            // 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
            {
                UtcExpiryTime = DateTime.UtcNow.AddSeconds(-10)
            };

            // Action
            server.HandleMesage(request);

            // Assert
            Global.DefaultWatcher.Received(1).WarnFormat(Arg.Any<string>(), Arg.Any<object[]>());
            tunnel.DidNotReceive().Publish(Arg.Any<RpcResponse>(), Arg.Any<string>());
        }
Exemplo n.º 6
0
        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");
        }
Exemplo n.º 7
0
        public void Should_print_warn_msg_and_return_if_msg_is_expired()
        {
            // 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
            {
                UtcExpiryTime = DateTime.UtcNow.AddSeconds(-10)
            };

            // Action
            server.HandleMesage(request);

            // Assert
            Global.DefaultWatcher.Received(1).WarnFormat(Arg.Any <string>(), Arg.Any <object[]>());
            tunnel.DidNotReceive().Publish(Arg.Any <RpcResponse>(), Arg.Any <string>());
        }
Exemplo n.º 8
0
        public void Should_invoke_method_on_real_instance_and_map_response_params()
        {
            // 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",
                MethodName = "Search",
                Params = new Dictionary<string, object> { { "page", 1 }, {"query", new SomeMessage
                {
                    Name = "vantheshark"
                }}}
            };
            var methodInfo = typeof(ISomeService).GetMethod("Search");
            methodMatcher.Match<ISomeService>(request)
                         .Returns(methodInfo);

            var returnValue = new List<SomeMessage> { new SomeMessage { Money = "$1" }, new SomeMessage { Money = "$1" } };
            instance.Search(1, Arg.Is<SomeMessage>(arg => arg.Name == "vantheshark"))
                    .Returns(returnValue);

            // Action
            server.Start();
            server.HandleMesage(request);

            // Assert
            tunnel.Received(1).Publish(Arg.Is<RpcResponse>(arg => arg.Exception == null && 
                                                                  arg.ReturnValue == returnValue &&
                                                                  arg.ChangedParams["query"] is SomeMessage &&
                                                                  1.Equals(arg.ChangedParams["page"]) &&
                                                                  arg.RequestId == request.Id), "Address");
        }