Skip to content

Make select test methods return their ActionResult to enable coarse-grained tests #46

Closed
@AlexArchive

Description

@AlexArchive

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions