예제 #1
0
        public static Tuple <JRpcService, T> StartService <T>(string serviceName, JRpcModule jRpcModule, string ipAdress = null, string port = null) where T : class
        {
            if (string.IsNullOrEmpty(ipAdress))
            {
                ipAdress = DEFAULT_IP_ADRESS;
            }
            if (string.IsNullOrEmpty(port))
            {
                port = DEFAULT_PORT;
            }

            ConfigurationManager.AppSettings.Set("ServiceAddress", ipAdress);
            ConfigurationManager.AppSettings.Set("ServicePort", port);
            var consulClient = new ConsulClient();
            var registry     = new DefaultModulesRegistry();

            registry.AddJRpcModule(jRpcModule);
            var service = new JRpcService(registry, consulClient);

            service.Start();
            var path        = $"http://{ipAdress}:{port}";
            var client      = new JRpcClient(path);
            var clientProxy = client.GetProxy <T>(serviceName);

            return(Tuple.Create(service, clientProxy));
        }
예제 #2
0
        public void StartService()
        {
            var startInfo = ServiceRunner.StartService <ITestServiceImpl>("TestServiceImpl", new TestServiceImpl());

            _service = startInfo.Item1;
            _client  = startInfo.Item2;
        }
예제 #3
0
        public void MissValueToNonOptionalParameterForOldClientVersionTest()
        {
            var startInfo = ServiceRunner.StartService <ITestServiceWithParametersOldVersion>("TestServiceWithParameters", new TestServiceWithParameters());

            _service = startInfo.Item1;
            _service.Start();
            Assert.Throws <JRpcException>(() => startInfo.Item2.MethodWithParameters("smt"));
        }
예제 #4
0
        public void MissValueToOptionalParameterForOldClientVersionTest()
        {
            var startInfo = ServiceRunner.StartService <ITestServiceWithParametersOldVersion>("TestServiceWithParameters", new TestServiceWithParameters());

            _service = startInfo.Item1;
            _service.Start();
            Assert.AreEqual(TestServiceWithParameters.DEFAULT_PARAMETER_VALUE, startInfo.Item2.MethodWithDefaulParameter("smt"));
        }
예제 #5
0
        public void CallMethodWithInterfaceInheritance()
        {
            var startInfo = ServiceRunner.StartService <ITestServiceImpl>("TestServiceImpl", new TestServiceImpl());

            _service = startInfo.Item1;
            _service.Start();

            Assert.AreEqual(TestService.STRING, startInfo.Item2.GetString());
        }
예제 #6
0
        public void CallMethodOnServiceWithMultipleInterfaces()
        {
            var startInfo = ServiceRunner.StartService <ITestServiceWithParamsNameMismatch2>("TestServiceWithParamsNameMismatch", new TestServiceWithParamsNameMismatch());

            _service = startInfo.Item1;
            _service.Start();
            var paramValue = "test";

            Assert.AreEqual(paramValue, startInfo.Item2.AnotherMethod(paramValue));
        }
예제 #7
0
        public void CallMethodWithSchemeMismatchTest()
        {
            var startInfo = ServiceRunner.StartService <ITestServiceWithParamsNameMismatch>("TestServiceWithParamsNameMismatch", new TestServiceWithParamsNameMismatch());

            _service = startInfo.Item1;
            _service.Start();
            var paramValue = "test";

            Assert.AreEqual(paramValue, startInfo.Item2.Method(paramValue));
        }
예제 #8
0
        public void MissValueToOptionalParameterForClientWithOtherDefaultTest()
        {
            var startInfo = ServiceRunner.StartService <ITestServiceWithParametersAndNewDefaultValue>("TestServiceWithParameters", new TestServiceWithParameters());

            _service = startInfo.Item1;
            _service.Start();
            var methodWithDefaulParameter = startInfo.Item2.MethodWithDefaulParameter("smt");

            Assert.AreEqual(TestServiceWithParameters.NEW_DEFAULT_PARAMETER_VALUE, methodWithDefaulParameter);
        }
예제 #9
0
        public void PassValueToOptionalParameterTest()
        {
            var startInfo = ServiceRunner.StartService <ITestServiceWithParameters>("TestServiceWithParameters", new TestServiceWithParameters());

            _service = startInfo.Item1;
            _service.Start();
            var methodWithDefaulParameter = startInfo.Item2.MethodWithDefaulParameter("smt", TestData);

            Assert.AreEqual(TestData, methodWithDefaulParameter);
        }
예제 #10
0
        static void Main(string[] args)
        {
            var defaultModulesRegistry = new DefaultModulesRegistry();

            defaultModulesRegistry.AddJRpcModule(new NewTestService());
            var service = new JRpcService(defaultModulesRegistry, new ConsulClient(), new KestrelJRpcServerHost());

            service.Start();
            Console.WriteLine("Hello World!");
            Console.ReadLine();
        }
예제 #11
0
        static void Main(string[] args)
        {
            var client   = new ConsulClient();
            var registry = new DefaultModulesRegistry();

            registry.AddJRpcModule(new SimpleService());
            var svc = new JRpcService(registry, client, new OwinJrpcServer());

            svc.Start();
            Console.ReadLine();
            svc.Stop();
        }