Full path required in Stub #51

Closed
opened 2025-12-29 08:21:42 +01:00 by adam · 3 comments
Owner

Originally created by @jvandervelden on GitHub (Nov 22, 2017).

Originally assigned to: @StefH on GitHub.

Hi,

I am trying to mock out some api that my test is hitting. When I use a relative path in 'Request.Create().WithUrl()' and then try and hit the endpoint, I get a 'Mapping was not found' error and a 404. If I specify the full path 'http://localhost:port/path' it works.

Looking at the documentation, using a relative path should be possible.

Below are 2 methods I created to do a simple request. The test 'TestHttpMockServerGood' passes and the test 'TestHttpMockServerFail' fails. The fail function uses a relative path in the WithUrl function where the good function uses a full path in the WithUrl funciton.

Environment:

Visual Studio 2017
Dot Net Core 2.0
Wiremock 1.0.2.7

Am I missing anything?

[TestMethod]
public void TestHttpMockServerFail()
{
    FluentMockServer _httpServer = FluentMockServer.Start();

    _httpServer
        .Given(Request.Create().WithUrl("/test").UsingAnyVerb())
        .RespondWith(Response.Create().WithStatusCode(200).WithBody("TEST"));

    string result = new WebClient().DownloadString(_httpServer.Urls[0] + "test");

    Assert.AreEqual("TEST", result);
}

[TestMethod]
public void TestHttpMockServerGood()
{
    FluentMockServer _httpServer = FluentMockServer.Start();

    _httpServer
        .Given(Request.Create().WithUrl(_httpServer.Urls[0] + "test").UsingAnyVerb())
        .RespondWith(Response.Create().WithStatusCode(200).WithBody("TEST"));

    string result = new WebClient().DownloadString(_httpServer.Urls[0] + "test");

    Assert.AreEqual("TEST", result);
}
Originally created by @jvandervelden on GitHub (Nov 22, 2017). Originally assigned to: @StefH on GitHub. Hi, I am trying to mock out some api that my test is hitting. When I use a relative path in 'Request.Create().WithUrl()' and then try and hit the endpoint, I get a 'Mapping was not found' error and a 404. If I specify the full path 'http://localhost:port/path' it works. Looking at the documentation, using a relative path should be possible. Below are 2 methods I created to do a simple request. The test 'TestHttpMockServerGood' passes and the test 'TestHttpMockServerFail' fails. The fail function uses a relative path in the WithUrl function where the good function uses a full path in the WithUrl funciton. Environment: Visual Studio 2017 Dot Net Core 2.0 Wiremock 1.0.2.7 Am I missing anything? ```c# [TestMethod] public void TestHttpMockServerFail() { FluentMockServer _httpServer = FluentMockServer.Start(); _httpServer .Given(Request.Create().WithUrl("/test").UsingAnyVerb()) .RespondWith(Response.Create().WithStatusCode(200).WithBody("TEST")); string result = new WebClient().DownloadString(_httpServer.Urls[0] + "test"); Assert.AreEqual("TEST", result); } [TestMethod] public void TestHttpMockServerGood() { FluentMockServer _httpServer = FluentMockServer.Start(); _httpServer .Given(Request.Create().WithUrl(_httpServer.Urls[0] + "test").UsingAnyVerb()) .RespondWith(Response.Create().WithStatusCode(200).WithBody("TEST")); string result = new WebClient().DownloadString(_httpServer.Urls[0] + "test"); Assert.AreEqual("TEST", result); } ```
adam added the question label 2025-12-29 08:21:42 +01:00
adam closed this issue 2025-12-29 08:21:42 +01:00
Author
Owner

@StefH commented on GitHub (Nov 22, 2017):

Hi.

You need to use a wildcard in the first test.

Like WithUrl("*/test");

See also linked unit tests : https://github.com/WireMock-Net/WireMock.Net/blob/master/test/WireMock.Net.Tests/RequestTests.Url.cs#L12

@StefH commented on GitHub (Nov 22, 2017): Hi. You need to use a wildcard in the first test. Like `WithUrl("*/test");` See also linked unit tests : https://github.com/WireMock-Net/WireMock.Net/blob/master/test/WireMock.Net.Tests/RequestTests.Url.cs#L12
Author
Owner

@jvandervelden commented on GitHub (Nov 22, 2017):

Thanks, I think I figured out where my confusion came from. On this wiki page (https://github.com/WireMock-Net/WireMock.Net/wiki/Using-WireMock-in-UnitTests) it shows that you are able to use a relative path with the 'WithUrl' function. I then dug into this page (https://github.com/WireMock-Net/WireMock.Net/wiki/Stubbing-and-Request-Matching) and glossed over the 'WithPath' function that I should've been using.

The (https://github.com/WireMock-Net/WireMock.Net/wiki/Using-WireMock-in-UnitTests) should be updated with either 'WithUrl("*/foo")' or 'WithPath("/foo")' to avoid future confusion.

@jvandervelden commented on GitHub (Nov 22, 2017): Thanks, I think I figured out where my confusion came from. On this wiki page (https://github.com/WireMock-Net/WireMock.Net/wiki/Using-WireMock-in-UnitTests) it shows that you are able to use a relative path with the 'WithUrl' function. I then dug into this page (https://github.com/WireMock-Net/WireMock.Net/wiki/Stubbing-and-Request-Matching) and glossed over the 'WithPath' function that I should've been using. The (https://github.com/WireMock-Net/WireMock.Net/wiki/Using-WireMock-in-UnitTests) should be updated with either 'WithUrl("*/foo")' or 'WithPath("/foo")' to avoid future confusion.
Author
Owner

@StefH commented on GitHub (Nov 23, 2017):

I've updated WIKI.

@StefH commented on GitHub (Nov 23, 2017): I've updated WIKI.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#51