WireMock-Net / WireMock.Net

WireMock.Net is a flexible product for stubbing and mocking web HTTP responses using advanced request matching and response templating. Based on the functionality from http://WireMock.org, but extended with more functionality.
Apache License 2.0
1.36k stars 199 forks source link

Static Mappings present in server but the request returns 404 #979

Closed dariooo512 closed 11 months ago

dariooo512 commented 11 months ago

Describe the bug

I can't figure out how to make ReadStaticMappings work. After calling ReadStaticMappings and verifying the server has mappings in the server.Mappings array, the following request yields 404.

Expected behavior:

After adding autogenerated mappings the server should return the body found in the json

Test to reproduce

Download and run this sample Program.zip

OR

Console.WriteLine("Hello, World!"); var server = WireMockServer.Start(); server.ReadStaticMappings(Directory.GetCurrentDirectory());

if (!server.Mappings.Any()) { throw new Exception("No mappings found"); }

var client = server.CreateClient(); var response = await client.GetAsync($"{client.BaseAddress}manageToken/getToken?Key=key&Secret=secret");

response.EnsureSuccessStatusCode();

var content = await response.Content.ReadAsStringAsync();

Console.WriteLine(content);


- 3 add the following stub next to the program.cs with name `managetoken_gettoken-f14d4844-a3e0-4130-a830-03f71a7cdbe8.json`

{ "id" : "f14d4844-a3e0-4130-a830-03f71a7cdbe8", "name" : "managetoken_gettoken", "request" : { "url" : "/manageToken/getToken?Key=key&Secret=secret", "method" : "GET" }, "response" : { "status" : 200, "body" : "{\"access_token\":\"token\",\"scope\":\"device_383334.0\",\"token_type\":\"Bearer\",\"expires_in\":3600}", "headers" : { "X-Frame-Options" : "DENY", "activityid" : "782ee60c-a48c-4d64-b9b3-8f99649df207", "Access-Control-Expose-Headers" : "", "Cache-Control" : "no-store", "Access-Control-Allow-Origin" : "*", "Access-Control-Allow-Methods" : "GET", "uber-trace-id" : "df44af849f44bab6%3Acccf9a31b54cfa0d%3A2d2865c70c60927b%3A1", "X-Content-Type-Options" : "nosniff", "Pragma" : "no-cache", "X-XSS-Protection" : "1; mode=block", "Access-Control-Allow-Headers" : "content-type", "Content-Type" : "application/json", "Date" : "Fri, 21 Jul 2023 15:08:55 GMT" } }, "uuid" : "f14d4844-a3e0-4130-a830-03f71a7cdbe8", "persistent" : true, "insertionIndex" : 1 }



-4 set the Property of this file 'Copy to output directory' to 'Copy if newer'
-5 Run the program

### Other related info
The Stub was generated using Wiremock docker wiremock/wiremock:latest
StefH commented 11 months ago

@dariooo512 Your mapping file looks like a WireMock.Org mapping file.

When reading static mappings, you need to use a WireMock.Net mapping file.

(There is limited in this project for using WireMock.Org mapping files.)

See