mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 21:10:32 +01:00
How to submit mappings for multiple request, responses #158
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @arpymastro on GitHub (Dec 14, 2018).
I have a .net core console app which launches a mock server(using WireMock.StandAlone and WireMock.Net nuget package) within a console app as -
Now I want to create stub mappings for my multiple request, responses and so I'm posting json data to http://localhost:5001/__admin/mappings -
But it is showing - System.InvalidCastException Unable to cast object of type Newtonsoft.Json.Linq.JArray to type Newtonsoft.Json.Linq.JObject.
If I try to create mapping for one request, response it creates successfully.
@StefH commented on GitHub (Dec 14, 2018):
This is not yet supported, but this looks like a good idea. I'll investigate and keep you informed on the progress.
@arpymastro commented on GitHub (Dec 14, 2018):
@StefH
Thanks.
Till then do I need to post the mappings separately?
Also, how can I pre-load the mappings by using .json file? I don't have __admin/mappings path in my project as I am using WireMock.Net nuget package. I also want to know how I can read and create stubs from the pre-loaded json file.
@StefH commented on GitHub (Dec 14, 2018):
Yes, post them separate.
You can just create this folder
__admin/mappingsmanually. See https://github.com/WireMock-Net/WireMock.Net/tree/master/examples/WireMock.Net.Console.NETCoreApp2The json files here are just the same as the body you normally post to the http://localhost:5001/__admin/mappings URL.
When you have posted a few mappings to the server, you can execute a POST request https://github.com/WireMock-Net/WireMock.Net/wiki/Admin-API-Reference#post-__adminmappingssave
to save the mappings to the
__admin/mappingsfolder.And if needed, you are allowed to rename the files as you like.
@arpymastro commented on GitHub (Dec 14, 2018):
@StefH - Can you please help me understand how to post the mappings to the server?
I have created
__admin/mappingsfolder manually and have added two json files(mystub_get.json and mystub_post.json) in it.I am doing a post @ http://localhost:5001/__admin/mappings/mystub_get.json but it is responding with
StatusCode:404 No matching mapping found.I am not putting any request body while posting the mappings to the server. Do I have to? How? I am not getting what I am doing wrong.
@arpymastro commented on GitHub (Dec 14, 2018):
Ignore my comment. I figured out. I needed to set property in my .csproj to copy the .json files into my bin folder. Works now! :)
@StefH commented on GitHub (Dec 14, 2018):
Cool.
@StefH commented on GitHub (Dec 15, 2018):
New NuGet version 1.0.6 will be released in some time which implements posting multiple mappings as an array.
@arpymastro commented on GitHub (Dec 20, 2018):
@StefH - I tested NuGet version 1.0.6 for multiple mappings. It works fine when I POST an array to http://localhost:5001/__admin/mappings.
Thank you!
But, if I have the array in an .json file kept under
__admin/mappings/myJsonArray.jsonthen it doesn't work. Will this be implemented in near future?@StefH commented on GitHub (Dec 20, 2018):
I forgot to implement that array logic, I 'll create a new NuGet in some time.
Just watch this issue.
@StefH commented on GitHub (Dec 20, 2018):
If you have time, you can test NuGet version
1.0.7-ci-1630(from MyGet) which fixes reading an array.@arpymastro commented on GitHub (Dec 21, 2018):
@StefH
I will test this and will let you know.
@StefH commented on GitHub (Jan 9, 2019):
@arpymastro Did youhave time to test this ?
@StefH commented on GitHub (Jan 19, 2019):
New NuGet will be released shortly.