8

I'm using WireMock-Net for stubbing requests.

I want to do the following request:

Request:

http://localhost:63078/services/query/?q=SELECT Id from User where username='user@gmail.com'

The request is composed by a SOQL Query. Here's a snippet of what I tried to do:

stub.Given(Request.Create()
   .WithPath("/services/query/")
   .WithParam("q", "SELECT Id from User where username='user@gmail.com'")
   .UsingGet())
   .RespondWith(Response.Create()
      .WithStatusCode(200)
      .WithHeader("Content-Type", "application/json")
      .WithBodyAsJson(new { Id = "5bdf076c-5654-4b3e-842c-7caf1fabf8c9" }));

The problem is: wiremock always replies with a 404. I've also tried using the RegexMatcher, like so:

   .WithPath("/services/query/")
   .WithParam("q", new WireMock.Matchers.RegexMatcher("SELECT Id from User where username.*$"))

But I still got a 404.

I think the problem is in the query parameter, because it has two equals "=". Can someone help me solve this?

2 Answers2

1

You could try to do the url encode. So when you are doing

SELECT Id from User where username='user@gmail.com'

you should be doing

SELECT %20Id%20from%20User%20where%20username%3D%27user%40gmail.com%27

Hope it helps.

Barrosy
  • 1,407
  • 2
  • 25
  • 56
  • It works if I use the following expectation: - SELECT Id from User where username%3D%27user%40gmail.com%27 But to use it, I have to change my current implementation and, in my opinion, it is not right. I'll try another strategy or wait for the "fix" by the wiremock.net library. – José Sampaio May 24 '19 at 16:48
  • @JoséSampaio : please try version 1.0.19 – Stef Heyenrath Jun 15 '19 at 08:43
1

This has been fixed in the latest version (1.0.19) from WireMock.Net

Please retry and mark this answer as accepted if it works correctly for you.

Details: the solution is based on Get url parameters from a string in .NET

Stef Heyenrath
  • 9,335
  • 12
  • 66
  • 121