@@ -43,34 +43,34 @@ Make sure to check out [the documentation](http://docs.teststack.net/fluentmvcte
43
43
Say you set up the following test class (this example with NUnit, but it will work for any test framework).
44
44
45
45
``` c#
46
- using MyApp .Controllers ;
47
- using NUnit .Framework ;
48
- using TestStack .FluentMVCTesting ;
49
-
50
- namespace MyApp .Tests .Controllers
46
+ using MyApp .Controllers ;
47
+ using NUnit .Framework ;
48
+ using TestStack .FluentMVCTesting ;
49
+
50
+ namespace MyApp .Tests .Controllers
51
+ {
52
+ [TestFixture ]
53
+ class HomeControllerShould
51
54
{
52
- [TestFixture ]
53
- class HomeControllerShould
54
- {
55
- private HomeController _controller ;
55
+ private HomeController _controller ;
56
56
57
- [SetUp ]
58
- public void Setup ()
59
- {
60
- _controller = new HomeController ();
61
- }
57
+ [SetUp ]
58
+ public void Setup ()
59
+ {
60
+ _controller = new HomeController ();
62
61
}
63
62
}
63
+ }
64
64
```
65
65
66
66
Then you can create a test like this:
67
67
68
68
``` c#
69
- [Test ]
70
- public void Render_default_view_for_get_to_index ()
71
- {
72
- _controller .WithCallTo (c => c .Index ()).ShouldRenderDefaultView ();
73
- }
69
+ [Test ]
70
+ public void Render_default_view_for_get_to_index ()
71
+ {
72
+ _controller .WithCallTo (c => c .Index ()).ShouldRenderDefaultView ();
73
+ }
74
74
```
75
75
76
76
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?
@@ -105,16 +105,21 @@ _controller.WithCallTo(c => c.Index())
105
105
.ShouldRedirectTo <SomeOtherController >(c => c .SomeAction ());
106
106
107
107
_controller .WithCallTo (c => c .Index ())
108
- .ShouldRenderFile (" text/plain" );
108
+ .ShouldRenderAnyFile (" content/type" );
109
+
110
+ _controller .WithCallTo (c => c .Index ())
111
+ .ShouldRenderFileContents (" text" );
112
+
113
+ _controller .WithCallTo (c => c .Index ())
114
+ .ShouldReturnContent (" expected content" );
109
115
110
116
_controller .WithCallTo (c => c .Index ())
111
117
.ShouldGiveHttpStatus (404 );
112
118
113
119
_controller .WithCallTo (c => c .Index ()).ShouldReturnJson (data =>
114
- {
115
- Assert .That (data .SomeProperty , Is .EqualTo (" SomeValue" );
116
- }
117
- );
120
+ {
121
+ Assert .That (data .SomeProperty , Is .EqualTo (" SomeValue" );
122
+ });
118
123
```
119
124
120
125
Any questions , comments or additions ?
0 commit comments