Пример #1
0
        public void FailUnpublishedServiceProviderStubTest()
        {
            var binder = new TestLightweightMethodBinder();
            var definitionsProviderMock = new Mock <IRpcServiceDefinitionsProvider>(MockBehavior.Strict);

            definitionsProviderMock.Setup(p => p.IsServiceRegistered(It.IsAny <Type>())).Returns(true);
            definitionsProviderMock.Setup(p => p.GetServiceOptions(It.IsAny <Type>())).Returns((RpcServerOptions)null);

            RpcServicePublisher servicePublisher = new RpcServicePublisher(definitionsProviderMock.Object);
            var serviceImpl = new AutoPublishServiceProviderServiceImpl();

            var publishedServiceScope = servicePublisher.PublishInstance(serviceImpl);

            CreateSimpleServiceStub <IImplicitServiceProviderService>(servicePublisher, binder, false);

            LightweightMethodStub getServiceStub = binder.GetHandler <RpcObjectRequest <int>, RpcResponse <RpcObjectRef> >(
                "SciTech.Rpc.Tests.ImplicitServiceProviderService.GetSimpleService");

            Assert.NotNull(getServiceStub);

            var objectId = publishedServiceScope.Value.ObjectId;

            Assert.ThrowsAsync <RpcFailureException>(async() =>
                                                     await LightweightStubHelper.SendReceiveAsync <RpcObjectRequest <int>, RpcResponse <RpcObjectRef <ISimpleService> > >(
                                                         getServiceStub, new RpcObjectRequest <int>(objectId, 1), DefaultSerializer));
        }
Пример #2
0
        public async Task GenerateSimpleServiceStubTest()
        {
            var binder = new TestLightweightMethodBinder();

            CreateSimpleServiceStub <ISimpleService>(new TestSimpleServiceImpl(), binder);

            LightweightMethodStub addStub = binder.GetHandler <RpcObjectRequest <int, int>, RpcResponse <int> >("SciTech.Rpc.Tests.SimpleService.Add");

            Assert.NotNull(addStub);

            var objectId = RpcObjectId.NewId();
            var request  = new RpcObjectRequest <int, int>(objectId, 5, 6);
            RpcResponse <int> addResponse = await LightweightStubHelper.SendReceiveAsync <RpcObjectRequest <int, int>, RpcResponse <int> >(addStub, request, DefaultSerializer);

            Assert.AreEqual(11, addResponse.Result);

            LightweightMethodStub setStub = binder.GetHandler <RpcObjectRequest <double>, RpcResponse>("SciTech.Rpc.Tests.SimpleService.SetValue");

            Assert.NotNull(setStub);
            var setResponse = await LightweightStubHelper.SendReceiveAsync <RpcObjectRequest <double>, RpcResponse>(setStub, new RpcObjectRequest <double>(objectId, 20), DefaultSerializer);

            Assert.NotNull(setResponse);

            LightweightMethodStub getStub = binder.GetHandler <RpcObjectRequest, RpcResponse <double> >("SciTech.Rpc.Tests.SimpleService.GetValue");

            Assert.NotNull(getStub);
            var getResponse = await LightweightStubHelper.SendReceiveAsync <RpcObjectRequest, RpcResponse <double> >(getStub, new RpcObjectRequest(objectId), DefaultSerializer);

            Assert.AreEqual(20, getResponse.Result);
        }
Пример #3
0
        public async Task GenerateImplicitServiceProviderStubTest()
        {
            var binder = new TestLightweightMethodBinder();
            var definitionsProviderMock = new Mock <IRpcServiceDefinitionsProvider>(MockBehavior.Strict);

            definitionsProviderMock.Setup(p => p.IsServiceRegistered(It.IsAny <Type>())).Returns(true);
            definitionsProviderMock.Setup(p => p.GetServiceOptions(It.IsAny <Type>())).Returns((RpcServerOptions)null);

            RpcServicePublisher servicePublisher = new RpcServicePublisher(definitionsProviderMock.Object);
            var serviceImpl = new ImplicitServiceProviderServiceImpl(servicePublisher);

            var publishedServiceScope = servicePublisher.PublishInstance(serviceImpl);

            CreateSimpleServiceStub <IImplicitServiceProviderService>(servicePublisher, binder, false);

            var objectId = publishedServiceScope.Value.ObjectId;

            LightweightMethodStub getServiceStub = binder.GetHandler <RpcObjectRequest <int>, RpcResponse <RpcObjectRef> >(
                "SciTech.Rpc.Tests.ImplicitServiceProviderService.GetSimpleService");

            Assert.NotNull(getServiceStub);

            var getServiceResponse = await LightweightStubHelper.SendReceiveAsync <RpcObjectRequest <int>, RpcResponse <RpcObjectRef> >(
                getServiceStub, new RpcObjectRequest <int>(objectId, 1), DefaultSerializer);

            Assert.NotNull(getServiceResponse.Result);

            var actualServiceRef = servicePublisher.GetPublishedInstance(serviceImpl.GetSimpleService(1));

            Assert.AreEqual(actualServiceRef, getServiceResponse.Result);
        }
        public IReadOnlyList <object> GenerateMethodStubs <TService>(IRpcServerCore rpcServer) where TService : class
        {
            var builder = new LightweightServiceStubBuilder <TService>(null);

            var binder = new TestLightweightMethodBinder();

            builder.GenerateOperationHandlers(rpcServer, binder);

            return(binder.methods);
        }
Пример #5
0
        public void SingletonServiceStub_ShouldUseRpcRequest()
        {
            var builder = new LightweightServiceStubBuilder <ISingletonService>(null);

            //var binderMock = new Mock<ILightweightMethodBinder>();
            //binderMock.Setup(b => b.AddMethod(It.IsAny<LightweightMethodStub>())).Callback<LightweightMethodStub>(m => {
            //    switch(m.OperationName)
            //    {
            //        case "SciTech.Rpc.Tests.SingletonService.Add":
            //            Assert.AreEqual(typeof(RpcRequest<int, int>), m.RequestType);
            //            break;
            //    }
            //});

            var binder             = new TestLightweightMethodBinder();
            var serverMock         = new Mock <IRpcServerCore>();
            var definitionsBuilder = new RpcServiceDefinitionsBuilder();
            var serializer         = new ProtobufRpcSerializer();

            serverMock.SetupGet(m => m.ServiceDefinitionsProvider).Returns(definitionsBuilder);
            serverMock.SetupGet(m => m.Serializer).Returns(serializer);

            var stub = builder.GenerateOperationHandlers(serverMock.Object, binder);;

            var addMethod = binder.methods.Single(m => m.OperationName == "SciTech.Rpc.Tests.SingletonService.Add");

            Assert.AreEqual(typeof(RpcRequest <int, int>), addMethod.RequestType);

            var subMethod = binder.methods.Single(m => m.OperationName == "SciTech.Rpc.Tests.SingletonService.Sub");

            Assert.AreEqual(typeof(RpcRequest <int, int>), subMethod.RequestType);

            var getStringsMethod = binder.methods.Single(m => m.OperationName == "SciTech.Rpc.Tests.SingletonService.GetStrings");

            Assert.AreEqual(typeof(RpcRequest <int>), getStringsMethod.RequestType);
        }
 public void OneTimeTearDown()
 {
     server.Dispose();
     server = null;
     binder = null;
 }
 public void OneTimeSetUp()
 {
     server = new LightweightRpcServer();
     binder = new TestLightweightMethodBinder();
 }