public void TestPingComplexModelOutAndRefSerialization(SoapSerializer soapSerializer)
        {
            var sampleServiceClient = _fixture.GetSampleServiceClient(soapSerializer);

            _fixture.ServiceMock
            .Setup(x => x.PingComplexModelOutAndRef(
                       It.IsAny <ComplexModel1>(),
                       ref It.Ref <ComplexModel2> .IsAny,
                       It.IsAny <ComplexObject>(),
                       ref It.Ref <ComplexModel1> .IsAny,
                       It.IsAny <ComplexObject>(),
                       out It.Ref <ComplexModel2> .IsAny,
                       out It.Ref <ComplexModel1> .IsAny))
            .Callback(new PingComplexModelOutAndRefCallback(
                          (
                              ComplexModel1 inputModel_service,
                              ref ComplexModel2 responseModelRef1_service,
                              ComplexObject data1_service,
                              ref ComplexModel1 responseModelRef2_service,
                              ComplexObject data2_service,
                              out ComplexModel2 responseModelOut1_service,
                              out ComplexModel1 responseModelOut2_service) =>
            {
                // check input paremeters serialization
                inputModel_service.ShouldDeepEqual(ComplexModel1.CreateSample2());
                responseModelRef1_service.ShouldDeepEqual(ComplexModel2.CreateSample1());
                responseModelRef2_service.ShouldDeepEqual(ComplexModel1.CreateSample2());
                data1_service.ShouldDeepEqual(ComplexObject.CreateSample1());
                data2_service.ShouldDeepEqual(ComplexObject.CreateSample2());

                //sample response
                responseModelRef1_service = ComplexModel2.CreateSample2();
                responseModelRef2_service = ComplexModel1.CreateSample1();
                responseModelOut1_service = ComplexModel2.CreateSample3();
                responseModelOut2_service = ComplexModel1.CreateSample1();
            }))
            .Returns(true);

            var responseModelRef1_client = ComplexModel2.CreateSample1();
            var responseModelRef2_client = ComplexModel1.CreateSample2();

            var pingComplexModelOutAndRefResult_client =
                sampleServiceClient.PingComplexModelOutAndRef(
                    ComplexModel1.CreateSample2(),
                    ref responseModelRef1_client,
                    ComplexObject.CreateSample1(),
                    ref responseModelRef2_client,
                    ComplexObject.CreateSample2(),
                    out var responseModelOut1_client,
                    out var responseModelOut2_client);

            // check output paremeters serialization
            pingComplexModelOutAndRefResult_client.ShouldBeTrue();
            responseModelRef1_client.ShouldDeepEqual(ComplexModel2.CreateSample2());
            responseModelRef2_client.ShouldDeepEqual(ComplexModel1.CreateSample1());
            responseModelOut1_client.ShouldDeepEqual(ComplexModel2.CreateSample3());
            responseModelOut2_client.ShouldDeepEqual(ComplexModel1.CreateSample1());
        }
        public void TestPingComplexModelOldStyleSerialization(SoapSerializer soapSerializer)
        {
            var sampleServiceClient = _fixture.GetSampleServiceClient(soapSerializer);

            _fixture.ServiceMock
            .Setup(x => x.PingComplexModelOldStyle(It.IsAny <PingComplexModelOldStyleRequest>()))
            .Callback(
                (PingComplexModelOldStyleRequest request_service) =>
            {
                // check input paremeters serialization
                request_service.InputModel.ShouldDeepEqual(ComplexModel1.CreateSample2());
                request_service.ResponseModelRef1.ShouldDeepEqual(ComplexModel2.CreateSample1());
                request_service.ResponseModelRef2.ShouldDeepEqual(ComplexModel1.CreateSample2());
                request_service.Data1.ShouldDeepEqual(ComplexObject.CreateSample1());
                request_service.Data2.ShouldDeepEqual(ComplexObject.CreateSample2());
            })
            .Returns(
                () => new PingComplexModelOldStyleResponse
            {
                // sample response
                PingComplexModelOldStyleResult = true,
                ResponseModelRef1 = ComplexModel2.CreateSample2(),
                ResponseModelRef2 = ComplexModel1.CreateSample1(),
                ResponseModelOut1 = ComplexModel2.CreateSample3(),
                ResponseModelOut2 = ComplexModel1.CreateSample1()
            });

            var pingComplexModelOldStyleResult_client =
                sampleServiceClient.PingComplexModelOldStyle(
                    new PingComplexModelOldStyleRequest
            {
                InputModel        = ComplexModel1.CreateSample2(),
                ResponseModelRef1 = ComplexModel2.CreateSample1(),
                Data1             = ComplexObject.CreateSample1(),
                ResponseModelRef2 = ComplexModel1.CreateSample2(),
                Data2             = ComplexObject.CreateSample2()
            });

            // check output paremeters serialization
            pingComplexModelOldStyleResult_client
            .PingComplexModelOldStyleResult
            .ShouldBeTrue();
            pingComplexModelOldStyleResult_client
            .ResponseModelRef1
            .ShouldDeepEqual(ComplexModel2.CreateSample2());
            pingComplexModelOldStyleResult_client
            .ResponseModelRef2
            .ShouldDeepEqual(ComplexModel1.CreateSample1());
            pingComplexModelOldStyleResult_client
            .ResponseModelOut1
            .ShouldDeepEqual(ComplexModel2.CreateSample3());
            pingComplexModelOldStyleResult_client
            .ResponseModelOut2
            .ShouldDeepEqual(ComplexModel1.CreateSample1());
        }
Esempio n. 3
0
        public static void Main(string[] args)
        {
            Newtonsoft.Json.JsonConvert.DefaultSettings = (() =>
            {
                var settings = new Newtonsoft.Json.JsonSerializerSettings();
                settings.Formatting = Newtonsoft.Json.Formatting.Indented;
                settings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter {
                    CamelCaseText = true
                });
                return(settings);
            });

            var binding = new BasicHttpBinding();
            // todo: why DataContractSerializer not working?
            var endpoint       = new EndpointAddress(new Uri(string.Format("http://{0}:5050/Service.svc", Environment.MachineName)));
            var channelFactory = new ChannelFactory <ISampleService>(binding, endpoint);
            var serviceClient  = channelFactory.CreateChannel();
            var result         = serviceClient.Ping("hey");

            Console.WriteLine("Ping method result: {0}", result);

            var complexModel = new ComplexModelInput
            {
                StringProperty = Guid.NewGuid().ToString(),
                IntProperty    = int.MaxValue / 2,
                ListProperty   = new List <string> {
                    "test", "list", "of", "strings"
                },
                //DateTimeOffsetProperty = new DateTimeOffset(2018, 12, 31, 13, 59, 59, TimeSpan.FromHours(1))
            };

            var pingComplexModelResult = serviceClient.PingComplexModel(complexModel);

            Console.WriteLine($"{nameof(pingComplexModelResult)}:\n{Newtonsoft.Json.JsonConvert.SerializeObject(pingComplexModelResult)}\n");

            serviceClient.EnumMethod(out var enumValue);
            Console.WriteLine("Enum method result: {0}", enumValue);

            var responseModelRef1 = ComplexModelResponse.CreateSample1();
            var responseModelRef2 = ComplexModelResponse.CreateSample2();
            var pingComplexModelOutAndRefResult =
                serviceClient.PingComplexModelOutAndRef(
                    ComplexModelInput.CreateSample1(),
                    ref responseModelRef1,
                    ComplexObject.CreateSample1(),
                    ref responseModelRef2,
                    ComplexObject.CreateSample2(),
                    out var responseModelOut1,
                    out var responseModelOut2);

            Console.WriteLine($"{nameof(pingComplexModelOutAndRefResult)}: {pingComplexModelOutAndRefResult}\n");
            Console.WriteLine($"{nameof(responseModelRef1)}:\n{Newtonsoft.Json.JsonConvert.SerializeObject(responseModelRef1)}\n");
            Console.WriteLine($"{nameof(responseModelRef2)}:\n{Newtonsoft.Json.JsonConvert.SerializeObject(responseModelRef2)}\n");
            Console.WriteLine($"{nameof(responseModelOut1)}:\n{Newtonsoft.Json.JsonConvert.SerializeObject(responseModelOut1)}\n");
            Console.WriteLine($"{nameof(responseModelOut2)}:\n{Newtonsoft.Json.JsonConvert.SerializeObject(responseModelOut2)}\n");

            serviceClient.VoidMethod(out var stringValue);
            Console.WriteLine("Void method result: {0}", stringValue);

            var asyncMethodResult = serviceClient.AsyncMethod().Result;

            Console.WriteLine("Async method result: {0}", asyncMethodResult);

            Console.ReadKey();
        }