hibri / HttpMock

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

Using "/api" in base url does not work #100

Closed cross-apps closed 5 years ago

cross-apps commented 5 years ago

Hi,

I was wondering why my mock server didn't return the correct response till I noticed that an attached "/api" or sth. at the end of the base url did not work.

_testServer = HttpMockRepository.At("http://localhost:9011/api"); _testServer.Stub(s => s.Post("makeDonuts")) changed into _testServer = HttpMockRepository.At("http://localhost:9011"); _testServer.Stub(s => s.Post("/api/makeDonuts"))

hibri commented 5 years ago

Hi @cross-apps This is expected. You setup the server and then mock the request paths to it.

cross-apps commented 5 years ago

Yes but the server could be any url in my opinion. If I use a client for example there I can define a baseUrl which accepts a routing part as well.

hibri commented 5 years ago

Thanks @cross-apps I want to keep the server flexible so that it can handle multiple paths. The server can also be re-used between test fixtures. A TCP socket is an expensive resource, and it takes a while for the OS to release the port. This delays the next test. We keep the server alive, but use new mocks with the same server.

Hope this helps.

cross-apps commented 5 years ago

@hibri yeah this sounds great, thank you for your effort!