Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to submit mappings for multiple request, responses #240

Closed
arpymastro opened this issue Dec 14, 2018 · 13 comments
Closed

How to submit mappings for multiple request, responses #240

arpymastro opened this issue Dec 14, 2018 · 13 comments
Labels

Comments

@arpymastro
Copy link

arpymastro commented 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 -

static void Main(string[] args)
    {
        // see source code for all the possible properties
        var settings = new FluentMockServerSettings
            {
                AllowPartialMapping=true,
                StartAdminInterface=true
            };
        StandAloneApp.Start(settings);

        Console.WriteLine("Press any key to stop the server");
        Console.ReadKey();
    }

Now I want to create stub mappings for my multiple request, responses and so I'm posting json data to http:https://localhost:5001/__admin/mappings -

[
	{
		"Request" : {....},
		"Response" : {....}
	},
	{
		"Request" : {....},
		"Response" : {....}
	},
	{
		"Request" : {....},
		"Response" : {....}
	}
]

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 StefH added the feature label Dec 14, 2018
@StefH
Copy link
Collaborator

StefH commented 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
Copy link
Author

@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
Copy link
Collaborator

StefH commented Dec 14, 2018

  1. Yes, post them separate.

  2. You can just create this folder __admin/mappings manually. See https://github.com/WireMock-Net/WireMock.Net/tree/master/examples/WireMock.Net.Console.NETCoreApp2

The json files here are just the same as the body you normally post to the http:https://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/mappings folder.

And if needed, you are allowed to rename the files as you like.

@arpymastro
Copy link
Author

arpymastro commented Dec 14, 2018

@StefH - Can you please help me understand how to post the mappings to the server?
I have created __admin/mappings folder manually and have added two json files(mystub_get.json and mystub_post.json) in it.

I am doing a post @ http:https://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
Copy link
Author

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
Copy link
Collaborator

StefH commented Dec 14, 2018

Cool.

@StefH
Copy link
Collaborator

StefH commented Dec 15, 2018

New NuGet version 1.0.6 will be released in some time which implements posting multiple mappings as an array.

@StefH StefH closed this as completed Dec 15, 2018
@arpymastro
Copy link
Author

@StefH - I tested NuGet version 1.0.6 for multiple mappings. It works fine when I POST an array to http:https://localhost:5001/__admin/mappings.
Thank you!

But, if I have the array in an .json file kept under __admin/mappings/myJsonArray.json then it doesn't work. Will this be implemented in near future?

@StefH
Copy link
Collaborator

StefH commented Dec 20, 2018

I forgot to implement that array logic, I 'll create a new NuGet in some time.

Just watch this issue.

@StefH StefH reopened this Dec 20, 2018
@StefH
Copy link
Collaborator

StefH commented 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
Copy link
Author

@StefH
I will test this and will let you know.

@StefH
Copy link
Collaborator

StefH commented Jan 9, 2019

@arpymastro Did youhave time to test this ?

@StefH
Copy link
Collaborator

StefH commented Jan 19, 2019

New NuGet will be released shortly.

@StefH StefH closed this as completed Jan 19, 2019
@WireMock-Net WireMock-Net deleted a comment from ssamparn Jun 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants