hibri / HttpMock

A library for creating Http servers on the fly in tests and stubbing responses
MIT License
128 stars 44 forks source link

Invalid GET request breaks server #24

Closed juamei closed 9 years ago

juamei commented 10 years ago

A GET request with a trailing ampersand (&) causes the mock server to return no data. If you paste the below tests into the end of MultipleTestsUsingTheSameStubServerAndDifferentUris.cs you can see the issue. It could be this is a kayak issue...

The spec is clear that this should be supported despite the url not being properly formatted.

    // Should pass and does pass
    [Test]
    public void Should_get_with_parameters()
    {
        _httpMockRepository
            .Stub(x => x.Get("/endpoint"))
            .Return("I am a GET")
            .OK();

        AssertResponse("GET", "I am a GET", "/endpoint?a=b&c=d");
    }

    // Should pass but does not pass
    [Test]
    public void Should_get_with_parameters_and_trailing_ampersand()
    {
        _httpMockRepository
            .Stub(x => x.Get("/endpoint"))
            .Return("I am a GET")
            .OK();

        AssertResponse("GET", "I am a GET", "/endpoint?a=b&c=d&");
    }

    private void AssertResponse(string method, string expected, string uri)
    {

        var webRequest = (HttpWebRequest)WebRequest.Create("Http://localhost:8080"+uri);
        webRequest.Method = method;
        using (var response = webRequest.GetResponse())
        {
            using (var sr = new StreamReader(response.GetResponseStream()))
            {
                string readToEnd = sr.ReadToEnd();
                Assert.That(readToEnd, Is.EqualTo(expected));
            }
        }
    }
hibri commented 10 years ago

Thanks. Will look into it.

hibri commented 10 years ago

I've fixed this in https://github.com/hibri/HttpMock/pull/25

There is a new version on Nuget