Question: Matching Query with XML
abrousseau001 opened this issue · 4 comments
Good morning,
I am currently using your library to mock http GET requests to an endpoint that uses XML as a query parameter (USPS made this decision...). I am able to get two of my requests to work without an issue, but the third request, when I add it, it fails to match the endpoint. I have attempted to even change the request to the same format as the previous two working requests and it fails. Please see my code below:
// Build the unescaped url request string for the single address request
var addressRequest = "http://production.shippingapis.com/ShippingAPI.dll?API=Verify&XML=<AddressValidateRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" USERID=\"myUserId\"><Address ID=\"0\"><Address1 /><Address2>5029 Columbia Road</Address2><City>Columbia</City><State>MD</State><Zip5>21044</Zip5><Zip4 /></Address></AddressValidateRequest>";
// Create the Mock HttpClient
// Setup the response to the request using the addressRequest and return a HttpResponseMessage
// with the expected HttpStatusCode(HttpStatusCode.OK - 200) and the expected response string
var mockHttp = new MockHttpMessageHandler();
_ = mockHttp.Expect(addressRequest).Respond(req =>
new HttpResponseMessage
{
Content = new StringContent("XMLGoodResponse"),
StatusCode = HttpStatusCode.OK
});
// Build the unescaped url request string for the multiple address request
addressRequest = "http://production.shippingapis.com/ShippingAPI.dll?API=Verify&XML=<AddressValidateRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" USERID="myUserId"><Address ID="0"><Address1 /><Address2>5029 Columbia Road</Address2><City>Columbia</City><State>MD</State><Zip5>21044</Zip5><Zip4 /></Address><Address ID="1"><Address1 /><Address2>5023 Columbia Road</Address2><City>Columbia</City><State>MD</State><Zip5>21044</Zip5><Zip4 /></Address></AddressValidateRequest>";
// Setup the response to the request using the addressRequest and return a HttpResponseMessage
// with the expected HttpStatusCode(HttpStatusCode.OK - 200) and the expected response string
mockHttp.Expect(addressRequest).Respond(req =>
new HttpResponseMessage
{
Content = new StringContent("XMLGoodResponseMultiple"),
StatusCode = HttpStatusCode.OK
});
// My issue starts here....
// Build the unescaped url request string for the multiple address request
addressRequest = "http://production.shippingapis.com/ShippingAPI.dll?API=Verify&XML=http://production.shippingapis.com/ShippingAPI.dll?API=Verify&XML=<AddressValidateRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" USERID="myUserId"><Address ID="0"><Address1 /><Address2>5029<>#Columbia Road</Address2><City>Columbia</City><State>MD</State><Zip5>21044</Zip5><Zip4 /></Address></AddressValidateRequest>";
// Setup the response to the request using the addressRequest and return a HttpResponseMessage
// with the expected HttpStatusCode(HttpStatusCode.OK - 200) and the expected response string
mockHttp.Expect(addressRequest.ToString()).Respond(req =>
new HttpResponseMessage
{
Content = new StringContent("XMLBadResponse"),
StatusCode = HttpStatusCode.OK
});
I have stepped through my side of the code and I am correctly building the request that should match to the third entry, but I am not matching. Do you have a recommended method to enable debugging the library while running my code so I can dig deeper into the root cause?
Thank you for your assistance,
Adam Brousseau
Hi Adam, can you create a standalone repro for this issue? I can see you're doing the setup above, but there are no actual http calls.
Good morning Richard,
I have added a private repository, and sent you a request to join as a collaborator, with a slightly simplified test that does fail as I have in my more built out internal testing. Hopefully this will make sense. Let me know if there is anything else I can do. I appreciate your time and effort.
Thanks,
Adam Brousseau
@richardszalay were you able to look into this?
@abrousseau001 Apologies I've only just gotten around to looking at this. Debugging through your sample, the first thing that jumped out is that you're validating the result of XmlGoodResponse
but your setup with MockHttp returns XMLGoodResponse
. Your controller is using string.Equals
, which defaults to a case-sensitive match, so it's failing at this point and falling back to the default switch case that returns NoContentResult.
Hope this helps (and apologies again for the delay!)