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.42k stars 209 forks source link

No server response in Postman and Receive Failure in Fiddler #276

Closed codeplayer14 closed 5 years ago

codeplayer14 commented 5 years ago

I'm using the following code

       FluentMockServer fms = FluentMockServer.Start();
            fms.Given(Request
                    .Create()
                    .WithPath("/api/evaluator/start")
                    .UsingPost())
                .RespondWith(
                    Response.Create()
                        .WithStatusCode(202));

On hitting this with Postman or Fiddler I get no response. The server is started as mentioned below. I also face the same issue when I start it with Admin interface and try to access one of the admin routes. From the Immediate Window, this is the status of the fms variable

    IsStarted: true
    LogEntries: Count = 0
    Mappings: {WireMock.IMapping[1]}
    Ports: Count = 1
    Scenarios: Count = 0
    Urls: {string[1]}
StefH commented 5 years ago

After your start code, can you try to add this code?

System.Console.WriteLine("Press any key to stop the server");
System.Console.ReadKey();
fms.Stop();
codeplayer14 commented 5 years ago

I tried. Same result. I was using a while(true) loop before to block the thread from exiting. Replaced it with your code. But the result is still the same.

StefH commented 5 years ago

Note that when you start the server like this, a random port is used. If you want to fix the port, use:

FluentMockServer fms = FluentMockServer.Start("http://localhost:9999");

or

FluentMockServer fms = FluentMockServer.Start(9999);
codeplayer14 commented 5 years ago

Yeah. But that's not the issue I'm facing. I've been getting the port from fms.Ports and using it in the request. However, I don't get a response.

StefH commented 5 years ago

You are sending a POST request ?

(Can you also export the Postman request so that I can re-play this on my machine?)

codeplayer14 commented 5 years ago

Yes I'm using a POST request. Attaching the Postman request.

Wiremock.net Test.postman_collection.zip

StefH commented 5 years ago

I'm using this code (tested in Linqpad):

FluentMockServer fms = FluentMockServer.Start(9999);
fms.Given(
    Request.Create().WithPath("/api/evaluator/start").UsingPost())
    .RespondWith(Response.Create().WithBody("hello").WithStatusCode(202)
);

Thread.Sleep(1000*1000);
fms.Stop();

image

And Postman works fine: image

codeplayer14 commented 5 years ago

Okay. Thanks. Turns out I was missing one of the dependencies! :/