hibri / HttpMock

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

AssertWasNotCalled & AssertWasCalled broken #19

Closed juamei closed 10 years ago

juamei commented 10 years ago

The two Assert methods (AssertWasNotCalled & AssertWasCalled) in HttpServer are both broken. Debugging shows that the path and method parameters are called the wrong way round so in the test below path comes through as "POST" whilst method comes through as "/api/echo" or "/api/status". The simple nunit test method below shows AssertWasNotCalled returning true when it should return false.

   [Test]
    public void showAssertNotCalledBrokenTest()
    {
        var stubHttp = HttpMockRepository.At("http://localhost:11235");
        stubHttp.Stub(x => x.Get("/api/status")).Return("OK").OK();
        stubHttp.Stub(x => x.Get("/api/echo")).Return("OK").OK();

        new WebClient().DownloadString("http://localhost:11235/api/status");

        // Should pass and does
        stubHttp.AssertWasNotCalled(x => x.Get("/api/echo"));

        // Should fail but passes
        stubHttp.AssertWasNotCalled(x => x.Get("/api/status"));
    }
knocte commented 10 years ago

It looks like this could have been caused by this commit: https://github.com/hibri/HttpMock/commit/b81f3cec26d6c34c6a989d38b8f28d169329fef4

hibri commented 10 years ago

It's this line. The params are swapped. https://github.com/hibri/HttpMock/blob/master/src/HttpMock/RequestWasNotCalled.cs#L19

juamei commented 10 years ago

I think its the call before that. When I debug, this call to AssertHandler has the parameters the wrong way round. https://github.com/hibri/HttpMock/blob/master/src/HttpMock/RequestWasNotCalled.cs#L15

juamei commented 10 years ago

Thanks for fixing it so fast!

hibri commented 10 years ago

@juamei Pushed a new package 1.1.3. Let me know if you have any more issues. Thanks for the test to reproduce the issue.