Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 29 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,34 +43,34 @@ Make sure to check out [the documentation](http://docs.teststack.net/fluentmvcte
Say you set up the following test class (this example with NUnit, but it will work for any test framework).

```c#
using MyApp.Controllers;
using NUnit.Framework;
using TestStack.FluentMVCTesting;

namespace MyApp.Tests.Controllers
using MyApp.Controllers;
using NUnit.Framework;
using TestStack.FluentMVCTesting;

namespace MyApp.Tests.Controllers
{
[TestFixture]
class HomeControllerShould
{
[TestFixture]
class HomeControllerShould
{
private HomeController _controller;
private HomeController _controller;

[SetUp]
public void Setup()
{
_controller = new HomeController();
}
[SetUp]
public void Setup()
{
_controller = new HomeController();
}
}
}
```

Then you can create a test like this:

```c#
[Test]
public void Render_default_view_for_get_to_index()
{
_controller.WithCallTo(c => c.Index()).ShouldRenderDefaultView();
}
[Test]
public void Render_default_view_for_get_to_index()
{
_controller.WithCallTo(c => c.Index()).ShouldRenderDefaultView();
}
```

This checks that when `_controller.Index()` is called then the `ActionResult` that is returned is of type `ViewResult` and that the view name returned is either "Index" or "" (the default view for the Index action); easy huh?
Expand Down Expand Up @@ -105,16 +105,21 @@ _controller.WithCallTo(c => c.Index())
.ShouldRedirectTo<SomeOtherController>(c => c.SomeAction());

_controller.WithCallTo(c => c.Index())
.ShouldRenderFile("text/plain");
.ShouldRenderAnyFile("content/type");

_controller.WithCallTo(c => c.Index())
.ShouldRenderFileContents("text");

_controller.WithCallTo(c => c.Index())
.ShouldReturnContent("expected content");

_controller.WithCallTo(c => c.Index())
.ShouldGiveHttpStatus(404);

_controller.WithCallTo(c => c.Index()).ShouldReturnJson(data =>
{
Assert.That(data.SomeProperty, Is.EqualTo("SomeValue");
}
);
{
Assert.That(data.SomeProperty, Is.EqualTo("SomeValue");
});
```

Any questions, comments or additions?
Expand Down