hibri / HttpMock

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

made OK, WithStatus and NotFound on stub to return IRequestVerify #88

Closed kesot closed 6 years ago

hibri commented 6 years ago

Thanks for this @kesot :) Could you write a test(s) for this? It makes sure the functionality is not broken in future, and also it would be good to use the test as an example on how to use the functionality.

kesot commented 6 years ago

Ok... Will do

hibri commented 6 years ago

Hi @kesot, Looking at the tests, I can't see a use case for this change. Can you explain a bit more what you are trying to do?

IRequestVerify is an interface that is used with AssertWasCalled, and to verify how requests are made. IRequestStub is used to setup how the mock responds, and the interface strictly caters to that. It will be confusing to a user of a fluent interface if things that are not related are returned.

kesot commented 6 years ago

Well, when I setup mock I expect to have an object at the end of the fluent interface which I can use for assertion. How do you assert now headers or body of request sent to the handler?

hibri commented 6 years ago

You can assert using the AssertWasCalled extensions. See https://github.com/hibri/HttpMock/blob/master/src/HttpMock.Integration.Tests/HttpExpectationTests.cs for some examples.

kesot commented 6 years ago

It's not shipped with nuget package

kesot commented 6 years ago

Oh, I see the problem now, I was not able to find any verification methods because they are separated to the different package. But why?

hibri commented 6 years ago

Didn't want to ship a NUnit dependency with the main project, and if you are using your own testing framework it's easier to extend it.

kesot commented 6 years ago

And why do I have to depend on NUnit if I use HttpMock in MSTests for example?

hibri commented 6 years ago

You are free to use MSTest, but if you use MSTest, you can write your own extensions, using the example in the HttpMock.Verify.NUnit library. I'd like to keep the verification concerns separate from the main library.