public void WhenASOAPEnvelopeWithAHeaderBlockFromAnXContainerIsBuilt() { var obj = new XmlObjectWithRootAttribute { MyProperty = 2 }; this.soapEnvelope = SoapBuilder.CreateSoap11Envelope() .WithHeader.AddBlock(XElement.Parse(ObjectXmlSerialiser.SerialiseObject(obj, null, null))) .Build() .ToString(); this.xmlTester.ArrangeActualXml(this.soapEnvelope); const string expectedXml = @"<env:Envelope xmlns:env=""http://schemas.xmlsoap.org/soap/envelope/""> <env:Header> <XmlObjectWithRootAttribute xmlns=""http://root.attribute""> <MyProperty>2</MyProperty> </XmlObjectWithRootAttribute> </env:Header> </env:Envelope>"; this.xmlTester.ArrangeExpectedXml(expectedXml); }
public void WhenASOAPEnvelopeWithABodyEntryFromAnObjectWithAnXMLRootAttributeIsBuilt_WithAGivenXMLElementNameAndNamespace() { var obj = new XmlObjectWithRootAttribute { MyProperty = 2 }; this.soapEnvelope = SoapBuilder.CreateSoap11Envelope() .WithBody.AddEntry(obj, "NewElementName", "http://new.root.namespace") .Build() .ToString(); this.xmlTester.ArrangeActualXml(this.soapEnvelope); var expectedXml = @"<env:Envelope xmlns:env=""http://schemas.xmlsoap.org/soap/envelope/""> <env:Body> <NewElementName xmlns=""http://new.root.namespace""> <MyProperty>2</MyProperty> </NewElementName> </env:Body> </env:Envelope>"; this.xmlTester.ArrangeExpectedXml(expectedXml); }
public void WhenASOAPEnvelopeWithAFaultIsBuilt() { this.soapEnvelope = SoapBuilder.CreateSoap11Envelope() .WithBody.SetFault(Soap11FaultCode.Client, "oops", "it was me!", new XContainer[] { XElement.Parse("<myDetail1>detail 1</myDetail1>"), XElement.Parse("<myDetail2>detail 2</myDetail2>") }) .Build() .ToString(); this.xmlTester.ArrangeActualXml(this.soapEnvelope); var expectedXml = @"<env:Envelope xmlns:env=""http://schemas.xmlsoap.org/soap/envelope/""> <env:Body> <env:Fault> <faultcode>env:Client</faultcode> <faultstring>oops</faultstring> <faultactor>it was me!</faultactor> <detail> <myDetail1>detail 1</myDetail1> <myDetail2>detail 2</myDetail2> </detail> </env:Fault> </env:Body> </env:Envelope>"; this.xmlTester.ArrangeExpectedXml(expectedXml); }
public void WhenASOAPEnvelopeWithAHeaderBlockFromAnObjectWithAnXMLRootAttributeIsBuilt_WithAGivenXMLElementNameAndBlankNamespace() { var obj = new XmlObjectWithRootAttribute { MyProperty = 2 }; this.soapEnvelope = SoapBuilder.CreateSoap11Envelope() .WithHeader.AddBlock(obj, "NewElementName", null) .Build() .ToString(); this.xmlTester.ArrangeActualXml(this.soapEnvelope); const string expectedXml = @"<env:Envelope xmlns:env=""http://schemas.xmlsoap.org/soap/envelope/""> <env:Header> <NewElementName xmlns=""http://root.attribute""> <MyProperty>2</MyProperty> </NewElementName> </env:Header> </env:Envelope>"; this.xmlTester.ArrangeExpectedXml(expectedXml); }
public void WhenASOAPEnvelopeWithAHeaderBlockFromAnObjectWithNoXMLAttributeIsBuilt() { var obj = new XmlObjectWithNoAttribute { MyProperty = 2 }; this.soapEnvelope = SoapBuilder.CreateSoap11Envelope() .WithHeader.AddBlock(obj) .Build() .ToString(); this.xmlTester.ArrangeActualXml(this.soapEnvelope); const string expectedXml = @"<env:Envelope xmlns:env=""http://schemas.xmlsoap.org/soap/envelope/""> <env:Header> <XmlObjectWithNoAttribute> <MyProperty>2</MyProperty> </XmlObjectWithNoAttribute> </env:Header> </env:Envelope>"; this.xmlTester.ArrangeExpectedXml(expectedXml); }
public void WhenASOAPEnvelopeWithABodyEntryFromAnObjectWithAnXMLTypeAttributeIsBuilt() { var obj = new XmlObjectWithTypeAttribute { MyProperty = 2 }; this.soapEnvelope = SoapBuilder.CreateSoap11Envelope() .WithBody.AddEntry(obj) .Build() .ToString(); this.xmlTester.ArrangeActualXml(this.soapEnvelope); var expectedXml = @"<env:Envelope xmlns:env=""http://schemas.xmlsoap.org/soap/envelope/""> <env:Body> <XmlObjectWithTypeAttribute xmlns=""http://type.attribute""> <MyProperty>2</MyProperty> </XmlObjectWithTypeAttribute> </env:Body> </env:Envelope>"; this.xmlTester.ArrangeExpectedXml(expectedXml); }
public void GivenAValidRequestForTheSOAP11Service() { this.request = SoapBuilder.CreateSoap11Envelope() .WithHeader.AddAction(TestCaseSoapActions.MySoap11ServiceTestAction) .WithBody.AddEntry("<TestAction>Hello</TestAction>") .Build().ToString(); Logger.Log("Request: " + this.request); }
public void WhenTheBodyIsSpecifiedTwice_DirectlyAsABodyEntryAndThenAsAFault() { base.ExpectedException.MessageShouldContainText = "Cannot set a fault because the body already has an entry"; Try(() => { this.soapEnvelope = SoapBuilder.CreateSoap11Envelope() .WithBody.AddEntry("<a>body entry 1</a>") .WithBody.SetFault(Soap11FaultCode.Client, "bummer1 - this will throw an exception") .Build() .ToString(); }); }
public void WhenTheBodyIsSpecifiedTwiceAsAFaultAndThenDirectlyAsABodyEntry() { base.ExpectedException.MessageShouldContainText = "Cannot add the body entry because a fault has already been specified"; Try(() => { this.soapEnvelope = SoapBuilder.CreateSoap11Envelope() .WithBody.SetFault(Soap11FaultCode.Client, "bummer1") .WithBody.AddEntry("<b>this should throw an exception</b>") .Build() .ToString(); }); }
public void WhenTheBodyIsSpecifiedTwiceAsAFault() { base.ExpectedException.MessageShouldContainText = "Cannot set a fault because the body already has an entry"; Try(() => { this.soapEnvelope = SoapBuilder.CreateSoap11Envelope() .WithBody.SetFault(Soap11FaultCode.Client, "bummer1") .WithBody.SetFault(Soap11FaultCode.Client, "bummer2") .Build() .ToString(); }); }
public void WhenASOAPEnvelopeWithAHeaderIsBuilt() { this.soapEnvelope = SoapBuilder.CreateSoap11Envelope() .WithHeader.AddAction("myActionOhYeah!") .Build() .ToString(); this.xmlTester.ArrangeActualXml(this.soapEnvelope); var expectedXml = @"<env:Envelope xmlns:env=""http://schemas.xmlsoap.org/soap/envelope/""> <env:Header> <wsa:Action xmlns:wsa=""http://www.w3.org/2005/08/addressing"">myActionOhYeah!</wsa:Action> </env:Header> </env:Envelope>"; this.xmlTester.ArrangeExpectedXml(expectedXml); }
public void GivenTheSOAPServiceWillRespondWithASuccessfulPayload() { this.expectedResponse = SoapBuilder.CreateSoap11Envelope() .WithBody.AddEntry("<TestActionResponse>World!</TestActionResponse>") .Build().ToString(); Logger.Log("Expected response: " + this.expectedResponse); this.nancySoapAdapter.RegisterSoapActionHandler( TestCaseRoutes.MySoap11Service, TestCaseSoapActions.MySoap11ServiceTestAction, (request, _) => { Logger.Log($"Fake service for action '{TestCaseSoapActions.MySoap11ServiceTestAction}' is executing..."); Logger.Log("Request message was: " + request.GetRequestBodyAsString()); return(Soap11NancyResponseFactory.Create(this.expectedResponse, HttpStatusCode.OK)); }); }
public void WhenASOAPEnvelopeWithABodyIsBuilt() { this.soapEnvelope = SoapBuilder.CreateSoap11Envelope() .WithBody.AddEntry("<a>hello from the body</a>") .Build() .ToString(); this.xmlTester.ArrangeActualXml(this.soapEnvelope); var expectedXml = @"<env:Envelope xmlns:env=""http://schemas.xmlsoap.org/soap/envelope/""> <env:Body> <a>hello from the body</a> </env:Body> </env:Envelope>"; this.xmlTester.ArrangeExpectedXml(expectedXml); }
public void WhenASOAPEnvelopeWithTheStandardSoapEncodingIsBuilt() { this.soapEnvelope = SoapBuilder.CreateSoap11Envelope() .WithBody.SetStandardSoapEncoding() .WithBody.AddEntry("<a>hello</a>") .Build() .ToString(); this.xmlTester.ArrangeActualXml(this.soapEnvelope); const string expectedXml = @"<env:Envelope xmlns:env=""http://schemas.xmlsoap.org/soap/envelope/""> <env:Body env:soapEncoding=""http://schemas.xmlsoap.org/soap/encoding/""> <a>hello</a> </env:Body> </env:Envelope>"; this.xmlTester.ArrangeExpectedXml(expectedXml); }
public void WhenASOAPEnvelopeWithACustomisedSoapEncodingIsBuilt() { this.soapEnvelope = SoapBuilder.CreateSoap11Envelope() .WithBody.SetCustomSoapEncoding("custom soap encoding namespace!!") .WithBody.AddEntry("<a>hello</a>") .Build() .ToString(); this.xmlTester.ArrangeActualXml(this.soapEnvelope); var expectedXml = @"<env:Envelope xmlns:env=""http://schemas.xmlsoap.org/soap/envelope/""> <env:Body env:soapEncoding=""custom soap encoding namespace!!""> <a>hello</a> </env:Body> </env:Envelope>"; this.xmlTester.ArrangeExpectedXml(expectedXml); }
private async Task CallHelloWorldSoapActionAsync(string soapAction, string expectedResponseMessage) { Logger.Log($"About to send the SOAP request for Action: '{soapAction}' to endpoint '{HelloWorldSampleRouteUrl}'"); this.expectedResponse = expectedResponseMessage; Logger.Log($"Expected response is: '{this.expectedResponse}'"); this.request = SoapBuilder.CreateSoap11Envelope() .WithHeader.AddAction(soapAction) .Build().ToString(); Logger.Log($"SOAP request about to be sent is: {this.request}"); var content = new StringContent(this.request); var responseMsg = await myHttpClient.PostAsync($"{NancyBaseUrl}/{HelloWorldSampleRouteUrl}", content).ConfigureAwait(true); this.actualResponse = await responseMsg.Content.ReadAsStringAsync().ConfigureAwait(true); Logger.Log($"Actual response was: {actualResponse}"); responseMsg.EnsureSuccessStatusCode(); }
public void WhenTheBodyIsSpecifiedTwice() { this.soapEnvelope = SoapBuilder.CreateSoap11Envelope() .WithBody.AddEntry("<a>body entry 1</a>") .WithBody.AddEntry("<b>body entry 2</b>") .Build() .ToString(); this.xmlTester.ArrangeActualXml(this.soapEnvelope); var expectedXml = @"<env:Envelope xmlns:env=""http://schemas.xmlsoap.org/soap/envelope/""> <env:Body> <a>body entry 1</a> <b>body entry 2</b> </env:Body> </env:Envelope>"; this.xmlTester.ArrangeExpectedXml(expectedXml); }
private void DefineHelloWorldSoapActionRoute(INancySoapAdapter soapAdapter) { const string mySoap11ServiceRoutePattern = "/MySampleSoap11Service"; DefineSoapRoute(mySoap11ServiceRoutePattern, soapAdapter); soapAdapter.RegisterSoapActionHandler( mySoap11ServiceRoutePattern, "urn:MySampleSoap11Service#HelloWorldSoapAction", (_, _) => Soap11NancyResponseFactory.Create( SoapBuilder.CreateSoap11Envelope().WithBody.AddEntry("<root>Hello SOAP World!</root>"), HttpStatusCode.OK)); soapAdapter.RegisterSoapActionHandler( mySoap11ServiceRoutePattern, "urn:MySampleSoap11Service#AnotherSoapAction", (_, _) => Soap11NancyResponseFactory.Create( SoapBuilder.CreateSoap11Envelope().WithBody.AddEntry("<root>Hello Another SOAP World!</root>"), HttpStatusCode.OK)); }