Something that I really like about the ShouldRenderFile and ShouldReturnContent methods is that they ultimately return the ActionResult.
Making the ActionResult instance available enables the consumer to write coarse-grained tests against the result whilst still reaping the benefits of the library:
var sut = new HomeController();
string actual = sut.WithCallTo(c => c.Index())
.ShouldReturnContent().Content;
StringAssert.Contains(actual, "foo");
I know that certain test methods need to return an interim instance to support the fluent interface - ShouldRenderDefaultView returns ViewResultTest for example - but other methods - such as ShouldReturnJson - currently return void when they could return an ActionResult.
To given an example - If we made ShouldReturnJson return the JsonResult we could enable coarse-grained tests like this one:
var sut = new HomeController();
var actual = sut.WithCallTo(c => c.Index())
.ShouldReturnJson();
Assert.AreEqual(JsonRequestBehavior.AllowGet, actual.JsonRequestBehavior);
What do you think?
I see this as being relevant for the following select test methods as of right now:
ShouldGiveHttpStatus
ShouldReturnEmptyResult
ShouldRenderJson
Do you see any other opportunities?
Something that I really like about the
ShouldRenderFileandShouldReturnContentmethods is that they ultimately return theActionResult.Making the
ActionResultinstance available enables the consumer to write coarse-grained tests against the result whilst still reaping the benefits of the library:I know that certain test methods need to return an interim instance to support the fluent interface -
ShouldRenderDefaultViewreturnsViewResultTestfor example - but other methods - such asShouldReturnJson- currently returnvoidwhen they could return anActionResult.To given an example - If we made
ShouldReturnJsonreturn theJsonResultwe could enable coarse-grained tests like this one:What do you think?
I see this as being relevant for the following select test methods as of right now:
ShouldGiveHttpStatusShouldReturnEmptyResultShouldRenderJsonDo you see any other opportunities?