public void TestEmptyParamsMethodSerialization(SoapSerializer soapSerializer) { var sampleServiceClient = _fixture.GetSampleServiceClient(soapSerializer); _fixture.ServiceMock .Setup(x => x.EmptyParamsMethod()) .Returns(ComplexModel1.CreateSample2); var emptyParamsMethodResult_client = sampleServiceClient .EmptyParamsMethod(); // check output paremeters serialization emptyParamsMethodResult_client.ShouldDeepEqual(ComplexModel1.CreateSample2()); }
public async Task TestAsyncMethodSerialization(SoapSerializer soapSerializer) { var sampleServiceClient = _fixture.GetSampleServiceClient(soapSerializer); const int output_value = 123; _fixture.ServiceMock .Setup(x => x.AsyncMethod()) .Returns(() => Task.Run(() => output_value)); var asyncMethodResult_client = await sampleServiceClient.AsyncMethod(); // check output paremeters serialization asyncMethodResult_client.ShouldBe(output_value); }
public void TestStreamResultSerialization(SoapSerializer soapSerializer) { var sampleServiceClient = _fixture.GetSampleServiceClient(soapSerializer); var streamData = Guid.NewGuid().ToString(); _fixture.ServiceMock.Setup(x => x.GetStream()).Returns(() => new MemoryStream(Encoding.ASCII.GetBytes(streamData))); var result = sampleServiceClient.GetStream(); var resultStream = new MemoryStream(); result.CopyTo(resultStream); Assert.Equal(streamData, Encoding.ASCII.GetString(resultStream.ToArray())); }
public void TestStreamBigSerialization(SoapSerializer soapSerializer) { var sampleServiceClient = _fixture.GetSampleServiceClient(soapSerializer); var streamData = string.Join(",", Enumerable.Range(1, 900000)); _fixture.ServiceMock.Setup(x => x.GetStream()).Returns(() => new MemoryStream(Encoding.ASCII.GetBytes(streamData))); var result = sampleServiceClient.GetStream(); var resultStream = new MemoryStream(); result.CopyTo(resultStream); Assert.Equal(streamData, Encoding.ASCII.GetString(resultStream.ToArray())); }
public void TestReversedParametersOrder(SoapSerializer soapSerializer) { var client = _fixture.GetReversedRequestArgumentsOrderClient(soapSerializer); _fixture.ServiceMock .Setup(x => x.TwoStringParameters(It.IsAny <string>(), It.IsAny <string>())) .Callback( (string first, string second) => { first.ShouldBe("1"); second.ShouldBe("2"); }); client.TwoStringParameters(second: "2", first: "1"); }
public void DeserializeExceptionTest2() { string soap = @"<?xml version=""1.0"" encoding=""utf-8""?> <S:Envelope xmlns:S=""http://schemas.xmlsoap.org/soap/envelope/""> <S:Body> <S:Fault xmlns:ns4=""http://www.w3.org/2003/05/soap-envelope""> <faultcode>S:Client</faultcode> <faultstring>Cannot find distribution method for {http://tempuri.org/}testException.</faultstring> </S:Fault> </S:Body> </S:Envelope>"; SoapSerializer serializer = new SoapSerializer("http://tempuri.org/"); Assert.ThrowsAsync <ProtocolViolationException>(async() => await serializer.Deserialize <Vector>(soap)); }
public void TestPingComplexArrayModelWithXmlArray(SoapSerializer soapSerializer) { var sampleServiceClient = _fixture.GetSampleServiceClient(soapSerializer); _fixture.ServiceMock .Setup(x => x.PingComplexModelArray(It.IsAny <ComplexModel1[]>(), It.IsAny <ComplexModel2[]>())) .Callback((ComplexModel1[] input, ComplexModel2[] input2) => { input.ShouldDeepEqual(new[] { ComplexModel1.CreateSample1() }); input2.ShouldDeepEqual(new[] { ComplexModel2.CreateSample1() }); }) .Returns(new[] { ComplexModel1.CreateSample1() }); var result = sampleServiceClient.PingComplexModelArrayWithXmlArray(new[] { ComplexModel1.CreateSample1() }, new[] { ComplexModel2.CreateSample1() }); result.ShouldDeepEqual(new[] { ComplexModel1.CreateSample1() }); }
public void TestUnwrappedSimpleMessageBodyMemberResponse(SoapSerializer soapSerializer) { var sampleServiceClient = _fixture.GetSampleServiceClient(soapSerializer); _fixture.ServiceMock .Setup(x => x.TestUnwrappedStringMessageBodyMember(It.IsAny <BasicMessageContractPayload>())) .Returns(() => new UnwrappedStringMessageBodyMemberResponse { StringProperty = "one" }); var clientResponse = sampleServiceClient.TestUnwrappedStringMessageBodyMember(new BasicMessageContractPayload()); clientResponse.ShouldNotBeNull(); clientResponse.StringProperty.ShouldBe("one"); }
public void TestMessageHeadersModelWithBodyAndNamespace(SoapSerializer serializer) { var service = _fixture.GetSampleServiceClient(serializer); var model = new MessageHeadersModelWithBodyAndNamespace { Prop1 = Guid.NewGuid().ToString(), Prop2 = Guid.NewGuid().ToString(), Prop3 = Guid.NewGuid().ToString(), Prop4 = Guid.NewGuid().ToString(), Prop5 = Guid.NewGuid().ToString(), Prop6 = Guid.NewGuid().ToString(), Prop7 = Guid.NewGuid().ToString(), Prop8 = Guid.NewGuid().ToString(), Body1 = Guid.NewGuid().ToString(), Body2 = Guid.NewGuid().ToString() }; _fixture.ServiceMock.Setup(x => x.GetWithBodyAndNamespace(It.IsAny <MessageHeadersModelWithBodyAndNamespace>())).Callback((MessageHeadersModelWithBodyAndNamespace m) => { m.ShouldDeepEqual(model); }).Returns(new MessageHeadersModelWithBodyAndNamespace() { Prop1 = model.Prop1, Prop2 = model.Prop2, Prop3 = model.Prop3, Prop4 = model.Prop4, Prop5 = model.Prop5, Prop6 = model.Prop6, Prop7 = model.Prop7, Prop8 = model.Prop8, Body1 = model.Body1, Body2 = model.Body2 }); var result = service.GetWithBodyAndNamespace(model); Assert.Equal(model.Prop1, result.Prop1); Assert.Equal(model.Prop2, result.Prop2); Assert.Equal(model.Prop3, result.Prop3); Assert.Equal(model.Prop4, result.Prop4); Assert.Equal(model.Prop5, result.Prop5); Assert.Equal(model.Prop6, result.Prop6); Assert.Equal(model.Prop7, result.Prop7); Assert.Equal(model.Prop8, result.Prop8); Assert.Equal(model.Body1, result.Body1); Assert.Equal(model.Body2, result.Body2); }
public void DeserializeExceptionTest() { string soap = @"<?xml version=""1.0"" encoding=""utf-8""?> <soap:Envelope xmlns:tns=""http://tempuri.org/"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/""> <soap:Header /> <soap:Body> <soap:Fault> <faultcode>System.IO.DirectoryNotFoundException</faultcode> <faultstring>The directory was not found.</faultstring> </soap:Fault> </soap:Body> </soap:Envelope>"; SoapSerializer serializer = new SoapSerializer("http://tempuri.org/"); Assert.ThrowsAsync <ProtocolViolationException>(async() => await serializer.Deserialize <Vector>(soap)); }
public void Soap_CannnotSerializeAGenericList() { // So we got this: // System.Runtime.Serialization.SerializationException: // Soap Serializer does not support serializing Generic Types // which will cause: System.Xml.XmlException try { SoapSerializer.SerializeObjectGraph(_lstInfoToSave, "SaveAndLoad.xml"); } catch (SerializationException) { Assert.Pass(); } Assert.Fail("Should have thrown SerializationException"); }
public void TestStreamSerializationWtihModel(SoapSerializer soapSerializer) { var sampleServiceClient = _fixture.GetSampleServiceClient(soapSerializer); var model = new DataContractWithStream { Data = new MemoryStream(Encoding.ASCII.GetBytes(Guid.NewGuid().ToString())), Header1 = Guid.NewGuid().ToString(), Header2 = Guid.NewGuid().ToString(), Header3 = Guid.NewGuid().ToString(), Header4 = Guid.NewGuid().ToString() }; _fixture.ServiceMock.Setup(x => x.PingStream(It.IsAny <DataContractWithStream>())).Callback((DataContractWithStream inputModel) => { Assert.Equal(model.Data.Length, inputModel.Data.Length); Assert.Equal(model.Header1, inputModel.Header1); Assert.Equal(model.Header2, inputModel.Header2); Assert.Equal(model.Header3, inputModel.Header3); Assert.Equal(model.Header4, inputModel.Header4); }).Returns(() => { return(new DataContractWithStream { Data = model.Data, Header1 = model.Header1, Header2 = model.Header2, Header3 = model.Header3, Header4 = model.Header4 }); }); var result = sampleServiceClient.PingStream(model); model.Data.Position = 0; var resultStream = new MemoryStream(); result.Data.CopyTo(resultStream); Assert.Equal(Encoding.ASCII.GetString((model.Data as MemoryStream).ToArray()), Encoding.ASCII.GetString(((MemoryStream)resultStream).ToArray())); Assert.Equal(model.Header1, result.Header1); Assert.Equal(model.Header2, result.Header2); Assert.Equal(model.Header3, result.Header3); Assert.Equal(model.Header4, result.Header4); }
public void TestParameterWithXmlElementNamespace(SoapSerializer soapSerializer) { var sampleServiceClient = _fixture.GetSampleServiceClient(soapSerializer); var obj = new DataContractWithoutNamespace { IntProperty = 1234, StringProperty = "2222" }; _fixture.ServiceMock.Setup(x => x.GetComplexObjectWithXmlElement(obj)).Returns(obj); _fixture.ServiceMock.Setup(x => x.GetComplexObjectWithXmlElement(It.IsAny <DataContractWithoutNamespace>())).Callback( (DataContractWithoutNamespace o) => { Assert.Equal(obj.IntProperty, o.IntProperty); Assert.Equal(obj.StringProperty, o.StringProperty); }); sampleServiceClient.GetComplexObjectWithXmlElement(obj); }
public async Task SerializeExceptionTest2() { using MemoryStream stream = new MemoryStream(); SoapSerializer serializer = new SoapSerializer("http://tempuri.org/") { Indent = true }; try { Uri uri = new Uri("httpx://]"); } catch (Exception ex) { TestContext.WriteLine(await serializer.SerializeException(ex)); } Assert.Pass(); }
public void TestNullableMethodSerialization(SoapSerializer soapSerializer, bool?input_value, int?output_value) { var sampleServiceClient = _fixture.GetSampleServiceClient(soapSerializer); _fixture.ServiceMock .Setup(x => x.NullableMethod(It.IsAny <bool?>())) .Callback( (bool?arg_service) => { // check input paremeters serialization arg_service.ShouldBe(input_value); }) .Returns(output_value); var nullableMethodResult_client = sampleServiceClient.NullableMethod(input_value); // check output paremeters serialization nullableMethodResult_client.ShouldBe(output_value); }
public void TestNotWrappedFieldDoubleComplexInput(SoapSerializer soapSerializer) { var sampleServiceClient = _fixture.GetSampleServiceClient(soapSerializer); _fixture.ServiceMock .Setup(x => x.NotWrappedFieldDoubleComplexInputRequestMethod(It.IsAny <NotWrappedFieldDoubleComplexInputRequest>())) .Callback((NotWrappedFieldDoubleComplexInputRequest request) => { // Check deserialisation in service! request.NotWrappedComplexInput1.ShouldNotBeNull(); request.NotWrappedComplexInput1.StringProperty.ShouldBe("z"); request.NotWrappedComplexInput2.ShouldNotBeNull(); request.NotWrappedComplexInput2.StringProperty.ShouldBe("x"); }) .Returns(() => new NotWrappedFieldComplexInputResponse { NotWrappedComplexInput = new NotWrappedFieldComplexInput { StringProperty = "z" } }); var clientResponse = sampleServiceClient.NotWrappedFieldDoubleComplexInputRequestMethod(new NotWrappedFieldDoubleComplexInputRequest { NotWrappedComplexInput1 = new NotWrappedFieldComplexInput { StringProperty = "z" }, NotWrappedComplexInput2 = new NotWrappedFieldComplexInput { StringProperty = "x" } }); clientResponse.ShouldNotBeNull(); // The client does not support unpacking these message contracts, so further assertions have been // commented // clientResponse.NotWrappedComplexInput.ShouldNotBeNull(); // clientResponse.NotWrappedComplexInput.StringProperty.ShouldBe("z"); }
public async Task DeserializeTest() { string soap = @"<?xml version=""1.0"" encoding=""utf-8""?> <soap:Envelope xmlns:tns=""http://tempuri.org/"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/""> <soap:Header /> <soap:Body> <tns:Point> <tns:X>9.6</tns:X> <tns:Y>4.2</tns:Y> </tns:Point> </soap:Body> </soap:Envelope>"; SoapSerializer serializer = new SoapSerializer("http://tempuri.org/"); Vector v = await serializer.Deserialize <Vector>(soap); TestContext.WriteLine(v); Assert.Pass(); }
public SoapEndpointMiddleware(ILogger <SoapEndpointMiddleware> logger, RequestDelegate next, SoapOptions options) { _logger = logger; _next = next; _endpointPath = options.Path; _serializer = options.SoapSerializer; _pathComparisonStrategy = options.CaseInsensitivePath ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal; _service = new ServiceDescription(options.ServiceType); _soapModelBounder = options.SoapModelBounder; _binding = options.Binding; _httpGetEnabled = options.HttpGetEnabled; _httpsGetEnabled = options.HttpsGetEnabled; _messageEncoders = new SoapMessageEncoder[options.EncoderOptions.Length]; for (var i = 0; i < options.EncoderOptions.Length; i++) { _messageEncoders[i] = new SoapMessageEncoder(options.EncoderOptions[i].MessageVersion, options.EncoderOptions[i].WriteEncoding, options.EncoderOptions[i].ReaderQuotas); } }
public void TestMessageHeadersModelWithoutBody(SoapSerializer serializer) { var service = _fixture.GetSampleServiceClient(serializer); var model = new MessageHeadersModel { Prop1 = "test" }; _fixture.ServiceMock.Setup(x => x.Get(It.IsAny <MessageHeadersModel>())).Callback((MessageHeadersModel m) => { m.ShouldDeepEqual(model); }).Returns(new MessageHeadersModel { Prop1 = model.Prop1 }); var result = service.Get(model); Assert.Equal(model.Prop1, result.Prop1); }
public void TestPingComplexLegacyModelResponse(SoapSerializer soapSerializer) { var sampleServiceClient = _fixture.GetSampleServiceClient(soapSerializer); var expected = "1234"; var request = new ComplexLegacyModel { QualifiedItems = new[] { expected }, UnqualifiedItems = new[] { expected } }; _fixture.ServiceMock .Setup(x => x.PingComplexLegacyModel(It.IsAny <ComplexLegacyModel>())) .Returns(request); var actual = sampleServiceClient.PingComplexLegacyModel(request); Assert.NotNull(actual); Assert.Equal(new[] { expected }, actual.QualifiedItems); Assert.Equal(new[] { expected }, actual.UnqualifiedItems); }
public SoapEndpointMiddleware(ILogger <SoapEndpointMiddleware> logger, RequestDelegate next, Type serviceType, string path, SoapEncoderOptions[] encoderOptions, SoapSerializer serializer, bool caseInsensitivePath, ISoapModelBounder soapModelBounder, Binding binding, bool httpGetEnabled, bool httpsGetEnabled) { _logger = logger; _next = next; _endpointPath = path; _serializer = serializer; _pathComparisonStrategy = caseInsensitivePath ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal; _service = new ServiceDescription(serviceType); _soapModelBounder = soapModelBounder; _binding = binding; _httpGetEnabled = httpGetEnabled; _httpsGetEnabled = httpsGetEnabled; _messageEncoders = new SoapMessageEncoder[encoderOptions.Length]; for (var i = 0; i < encoderOptions.Length; i++) { _messageEncoders[i] = new SoapMessageEncoder(encoderOptions[i].MessageVersion, encoderOptions[i].WriteEncoding, encoderOptions[i].ReaderQuotas); } }
public void TestVoidMethodSerialization(SoapSerializer soapSerializer) { var sampleServiceClient = _fixture.GetSampleServiceClient(soapSerializer); const string output_value = "output_value"; _fixture.ServiceMock .Setup(x => x.VoidMethod(out It.Ref <string> .IsAny)) .Callback(new VoidMethodCallback( (out string s_service) => { // sample response s_service = output_value; })); sampleServiceClient.VoidMethod(out var s_client); // check output paremeters serialization s_client.ShouldBe(output_value); }
public void TestNotWrappedFieldDoubleComplexInput(SoapSerializer soapSerializer) { var sampleServiceClient = _fixture.GetSampleServiceClient(soapSerializer); _fixture.ServiceMock .Setup(x => x.NotWrappedFieldDoubleComplexInputRequestMethod(It.IsAny <NotWrappedFieldDoubleComplexInputRequest>())) .Callback((NotWrappedFieldDoubleComplexInputRequest request) => { // Check deserialisation in service! request.NotWrappedComplexInput1.ShouldNotBeNull(); request.NotWrappedComplexInput1.StringProperty.ShouldBe("z"); request.NotWrappedComplexInput2.ShouldNotBeNull(); request.NotWrappedComplexInput2.StringProperty.ShouldBe("x"); }) .Returns(() => new NotWrappedFieldComplexInputResponse { NotWrappedComplexInput = new NotWrappedFieldComplexInput { StringProperty = "z" } }); var clientResponse = sampleServiceClient.NotWrappedFieldDoubleComplexInputRequestMethod(new NotWrappedFieldDoubleComplexInputRequest { NotWrappedComplexInput1 = new NotWrappedFieldComplexInput { StringProperty = "z" }, NotWrappedComplexInput2 = new NotWrappedFieldComplexInput { StringProperty = "x" } }); clientResponse.ShouldNotBeNull(); clientResponse.NotWrappedComplexInput.ShouldNotBeNull(); clientResponse.NotWrappedComplexInput.StringProperty.ShouldBe("z"); }
public void TestMessageContractWithArrays(SoapSerializer soapSerializer) { var sampleServiceClient = _fixture.GetSampleServiceClient(soapSerializer); _fixture.ServiceMock .Setup(x => x.TestMessageContractWithArrays(It.IsAny <MessageContractRequestWithArrays>())) .Callback( (MessageContractRequestWithArrays inputModel_service) => { // check input paremeters serialization inputModel_service.ShouldDeepEqual(MessageContractRequestWithArrays.CreateSample()); }) .Returns(() => MessageContractResponseWithArrays.CreateSample()); var pingComplexModelResult_client = sampleServiceClient .TestMessageContractWithArrays(MessageContractRequestWithArrays.CreateSample()); // check output paremeters serialization pingComplexModelResult_client.ShouldDeepEqual(MessageContractResponseWithArrays.CreateSample()); }
public void TestPingComplexModelSerializationWithNoNameSpace(SoapSerializer soapSerializer) { var sampleServiceClient = _fixture.GetSampleServiceClient(soapSerializer); _fixture.ServiceMock .Setup(x => x.PingComplexModel1(It.IsAny <ComplexModel1>())) .Callback( (ComplexModel1 inputModel_service) => { // check input paremeters serialization inputModel_service.ShouldDeepEqual(ComplexModel1.CreateSample3()); }) .Returns(ComplexModel2.CreateSample2); var pingComplexModelResult_client = sampleServiceClient .PingComplexModel1(ComplexModel1.CreateSample3()); // check output paremeters serialization pingComplexModelResult_client.ShouldDeepEqual(ComplexModel2.CreateSample2()); }
public void TestPingSerialization(SoapSerializer soapSerializer) { var sampleServiceClient = _fixture.GetSampleServiceClient(soapSerializer); const string input_value = "input_value"; const string output_value = "output_value"; _fixture.ServiceMock .Setup(x => x.Ping(It.IsAny <string>())) .Callback( (string s_service) => { // check input paremeters serialization s_service.ShouldBe(input_value); }) .Returns(output_value); var pingResult_client = sampleServiceClient.Ping(input_value); // check output paremeters serialization pingResult_client.ShouldBe(output_value); }
public void TestEnumMethodSerialization(SoapSerializer soapSerializer) { var sampleServiceClient = _fixture.GetSampleServiceClient(soapSerializer); const SampleEnum output_value = SampleEnum.C; _fixture.ServiceMock .Setup(x => x.EnumMethod(out It.Ref <SampleEnum> .IsAny)) .Callback(new EnumMethodCallback( (out SampleEnum e_service) => { // sample response e_service = output_value; })) .Returns(true); var enumMethodResult_client = sampleServiceClient.EnumMethod(out var e_client); // check output paremeters serialization enumMethodResult_client.ShouldBe(true); e_client.ShouldBe(output_value); }
public SoapEndpointMiddleware(ILogger <SoapEndpointMiddleware <T_MESSAGE> > logger, RequestDelegate next, SoapOptions options) { _logger = logger; _next = next; _options = options; _endpointPath = options.Path; _serializer = options.SoapSerializer; _serializerHelper = new SerializerHelper(_serializer); _pathComparisonStrategy = options.CaseInsensitivePath ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal; _service = new ServiceDescription(options.ServiceType); _soapModelBounder = options.SoapModelBounder; _binding = options.Binding; _httpGetEnabled = options.HttpGetEnabled; _httpsGetEnabled = options.HttpsGetEnabled; _xmlNamespaceManager = options.XmlNamespacePrefixOverrides ?? Namespaces.CreateDefaultXmlNamespaceManager(); Namespaces.AddDefaultNamespaces(_xmlNamespaceManager); _messageEncoders = new SoapMessageEncoder[options.EncoderOptions.Length]; for (var i = 0; i < options.EncoderOptions.Length; i++) { _messageEncoders[i] = new SoapMessageEncoder(options.EncoderOptions[i].MessageVersion, options.EncoderOptions[i].WriteEncoding, options.EncoderOptions[i].ReaderQuotas, options.OmitXmlDeclaration, options.IndentXml); } }
public SoapEndpointMiddleware(ILogger <SoapEndpointMiddleware> logger, RequestDelegate next, Type serviceType, string path, MessageEncoder encoder, SoapSerializer serializer) { _logger = logger; _next = next; _endpointPath = path; _messageEncoder = encoder; _serializer = serializer; _service = new ServiceDescription(serviceType); }
public TReversedParametersOrderService GetReversedRequestArgumentsOrderClient(SoapSerializer soapSerializer) { return(_reversedRequestArgumentsOrderClients[soapSerializer]); }
public void SoapSerializerConstructorTest() { SoapSerializer target = new SoapSerializer(); Assert.IsNotNull(target); }