Exemplo n.º 1
0
        public ProxyGenerator(INamingConventionService namingConventionService, IMethodCompressionPicker methodCompressionPicker = null)
        {
            _namingConventionService = namingConventionService;
            _methodCompressionPicker = methodCompressionPicker;

            SetupDyanmicAssembly();
        }
Exemplo n.º 2
0
        public void ProxyGenerator_Create_Interface_Compress_Response(IRpcProxyService proxyService,
                                                                      IMethodCompressionPicker compressionPicker,
                                                                      ProxyGenerator proxyGenerator,
                                                                      Fixture fixture)
        {
            byte[] bytes = new byte[0];

            compressionPicker.CompressResponse(Arg.Any <MethodInfo>()).Returns(true);

            proxyService.MakeCallWithReturn <int>(typeof(IIntMathService).Namespace, typeof(IIntMathService).Name, nameof(IIntMathService.Add), Arg.Any <byte[]>(), false, true)
            .Returns(c =>
            {
                bytes = c.Arg <byte[]>();

                return(15);
            });

            var proxyType = proxyGenerator.GenerateProxyType(typeof(IIntMathService), true);

            var instance = (IIntMathService)fixture.Locate(proxyType);

            var value = instance.Add(5, 10);

            Assert.Equal(15, value);

            var request = bytes.Deserialize <RpcRequestMessage>();

            Assert.NotNull(request);
            Assert.Equal("2.0", request.Version);
            Assert.Equal("Add", request.Method);
            Assert.False(string.IsNullOrEmpty(request.Id));

            //var objectDictionary = request.Parameters as Dictionary<string, object>;

            //Assert.NotNull(objectDictionary);
            //Assert.Equal(2, objectDictionary.Count);
            //Assert.Equal(5, Convert.ToInt32(objectDictionary["a"]));
            //Assert.Equal(10, Convert.ToInt32(objectDictionary["b"]));
        }