mock4net icon indicating copy to clipboard operation
mock4net copied to clipboard

Provide Intent Oriented Syntax

Open dupdob opened this issue 9 years ago • 4 comments

I would like to have a syntax that focuses on intent to improve further on readability. So instead of

                    Responses
                        .WithStatusCode(200)
                        .WithBody(@"{ msg: ""Hello world!""}")

I would prefer

                    Responses
                        .Success
                        .WithBody(@"{ msg: ""Hello world!""}")

other example

                    Responses
                        .RedirectTo("/bar");

I think it may also be helpful when you want to simulate ill behaving servers

dupdob avatar Jun 17 '15 20:06 dupdob

I would prefer method chaing instead of properties, something like:

Responses
    .WithSuccess()
    .WithBody(@"{ msg: ""Hello world!""}")

This way I find the alias/shortcut more obvious.

jbuiss0n avatar Sep 07 '15 08:09 jbuiss0n

Makes sense to me. Next the next question is : which use cases should be supported through shortcuts. Should we list broad categories (such as 2xx = with success, 3xx = WithRedirect, 4xx = WithRrror, 5xx=WithServerError) , or dig into more specifics (404=WithNotFound)?

dupdob avatar Sep 07 '15 08:09 dupdob

Thanks for the feedback The problem is HTTP defines quite a bunch of possible status code. I think it is a good idea to list most common scenario as listed by dupdob and keep a generic WithStatusCode() method for hedge cases. WDYT?

alexvictoor avatar Sep 08 '15 19:09 alexvictoor

We definitely need both shortcuts for the most beaten paths as well as the ability to be very specific for the edge cases. In order to favor the 'pit of success' factor, one need to makes what is frequently used easy and what is less frequent possible. So I would propose:

Responses.WithSuccess() // ok for any 2xx code
Responses.WithOk() // ok if code = 200
Responses.WithSuccess().AndCode(2xx) // ok for code 2xx

Responses.WithError() // ok for any 4-5xx
Responses.WithNotFound() // ok for 404
Responses.WithInternalError() // ok for 5xx

Responses.WithSpecific().ForCode(xxx) // ok for code xxx

see the idea. Writing those samples, I realize I feel there is a wording issue with 'Responses'. But I will open a new issue to discuss it

dupdob avatar Sep 09 '15 11:09 dupdob