Moq has a nice way to specify a method you want to call, using syntax like this:
mock.Setup(o => o.Do("foo", "bar).Returns(true));
The Setup portion here might work well for generating Web API routes.
For example:
public void MyController : ApiController
{
[HttpGet("...")]
public IHttpActionResult GetItem(int container, string name) { /* ... */ }
[HttpGet("...")]
public IHttpActionResult GetItems()
{
string link = Url.Route(() => this.Get(1, "a");
// ...
}
}
Using a lambda to call a method is a convenient way to represent a route.
Body params would be a little tricky (likely have to be default(T) and ignored). And disambiguating between multiple route prefixes might require something like this:
Url.Content("~/a/b", () => this.Get("a", 1));
But especially for mainline cases, the syntax is quite nice.
Comments: This is a feature request.
mock.Setup(o => o.Do("foo", "bar).Returns(true));
The Setup portion here might work well for generating Web API routes.
For example:
public void MyController : ApiController
{
[HttpGet("...")]
public IHttpActionResult GetItem(int container, string name) { /* ... */ }
[HttpGet("...")]
public IHttpActionResult GetItems()
{
string link = Url.Route(() => this.Get(1, "a");
// ...
}
}
Using a lambda to call a method is a convenient way to represent a route.
Body params would be a little tricky (likely have to be default(T) and ignored). And disambiguating between multiple route prefixes might require something like this:
Url.Content("~/a/b", () => this.Get("a", 1));
But especially for mainline cases, the syntax is quite nice.
Comments: This is a feature request.