Skip to content

Commit 84c4276

Browse files
committed
Minor edits to readme
1 parent 127b37a commit 84c4276

1 file changed

Lines changed: 15 additions & 13 deletions

File tree

README.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ This library provides a fluent interface for creating terse and expressive tests
55

66
This library is testing framework agnostic, so you can combine it with the testing library of your choice (e.g. NUnit, xUnit, etc.).
77

8-
The library is compatible with the AAA testing methodology, although it combines the Act and Assert parts together (but you can have other assertions after the Fluent assertion). See the code examples below for more information.
8+
The library is compatible with the AAA testing methodology, although it combines the Act and Assert parts together (but you can also have other assertions after the Fluent assertion). See the code examples below for more information.
99

10-
The motivation behind this library is to provide a way to test MVC actions quickly, tersely and maintainably. Most examples I find on MVC controller testing are incredibly verbose, repetitive and time-consuming to write and maintain. Given how quickly you can write controller actions and how simple they are (assuming you are following best practices and keeping them lean) the time to test them generally isn't worth it given you can glance at most of your controller actions and know they are right or wrong instantly. This library aims to make the time to implement the tests inconsequential and then the value your tests are providing is worth it. The other problem that I've noticed with most examples of controller testing is that there are a lot of magic strings being used to test view and action names; this library also aims to utilise the type system to resolve a lot of those magic strings, thus ensuring your tests are more maintainable and require less re-work when you perform major refactoring of your code.
10+
The motivation behind this library is to provide a way to test MVC actions quickly, tersely and maintainably. Most examples I find on MVC controller testing are incredibly verbose, repetitive and time-consuming to write and maintain. Given how quickly you can write controller actions and how simple they are (assuming you are following best practices and keeping them lean) the time to test them generally isn't worth it given you can glance at most of your controller actions and know they are right or wrong instantly. This library aims to make the time to implement the tests inconsequential and then the value your tests are providing is worth it. The other problem that I've noticed with most examples of controller testing is that there are a lot of magic strings being used to test view and action names; this library also aims to (where possible) utilise the type system to resolve a lot of those magic strings, thus ensuring your tests are more maintainable and require less re-work when you perform major refactoring of your code.
11+
12+
I came up with this library after using the [MVCContrib.TestHelper](http://mvccontrib.codeplex.com/wikipage?title=TestHelper) library for quite a while, but becoming frustrated with it; the library was initially created during an [experiment I conducted](http://robdmoore.id.au/blog/2011/03/14/terse-controller-testing-with-asp-net-mvc/) to try and create terse controller tests. I (and my team) have been using the library for over a year on a number of projects for the company that I work for.
1113

1214
Installation
1315
------------
@@ -125,17 +127,17 @@ You can also pass through a MethodInfo object against the method you are redirec
125127

126128
If you use this option (I don't recommend it because it uses a "magic" string so if you change the action name then the string won't change, although at least the test will break because the Method name will no longer be valid; in saying that if you change your parameters more often than the action name this might be a better option) be careful that you don't get an AmbiguousMatchException if there are multiple actions with that name.
127129

128-
At this stage there isn't support for the `[ActionName()]` attribute or simply passing through a string to check against the action name, but if either are important to you feel free to add an issue for this GitHub project and I can add them.
130+
At this stage there isn't support for the `[ActionName()]` attribute or simply passing through a string to check against the action name, but if either are important to you feel free to add an issue in this GitHub project and I can add them.
129131

130132
### Redirect to action in another controller
131133

132134
If you are redirecting to an action in another controller, then there are two syntaxes that you can currently use (similar to the last two mentioned above):
133135

134136
_controller.WithCallTo(c => c.Index())
135-
.ShouldRedirectTo<SomeOtherController>(typeof(SomeOtherController).GetMethod("SomeAction"));
137+
.ShouldRedirectTo<SomeOtherController>(c2 => c2.SomeAction());
136138

137139
_controller.WithCallTo(c => c.Index())
138-
.ShouldRedirectTo<SomeOtherController>(c2 => c2.SomeAction());
140+
.ShouldRedirectTo<SomeOtherController>(typeof(SomeOtherController).GetMethod("SomeAction"));
139141

140142
### View results (where the view name is the same as the action name - explicitly or via an empty string)
141143

@@ -225,23 +227,23 @@ You can also make assertions on the content of the error message(s); these metho
225227

226228
// Equality
227229
_controller.WithCallTo(c => c.Index()).ShouldRenderDefaultView()
228-
.WithModel<ModelType>().AndModelErrorFor(m => m.Property1)
229-
.ThatEquals("The error message.");
230+
.WithModel<ModelType>()
231+
.AndModelErrorFor(m => m.Property1).ThatEquals("The error message.");
230232

231233
// Start of message
232234
_controller.WithCallTo(c => c.Index()).ShouldRenderDefaultView()
233-
.WithModel<ModelType>().AndModelErrorFor(m => m.Property1)
234-
.BeginningWith("The error");
235+
.WithModel<ModelType>()
236+
.AndModelErrorFor(m => m.Property1).BeginningWith("The error");
235237

236238
// End of message
237239
_controller.WithCallTo(c => c.Index()).ShouldRenderDefaultView()
238-
.WithModel<ModelType>().AndModelErrorFor(m => m.Property1)
239-
.BeginningWith("message.");
240+
.WithModel<ModelType>()
241+
.AndModelErrorFor(m => m.Property1).BeginningWith("message.");
240242

241243
// Containing
242244
_controller.WithCallTo(c => c.Index()).ShouldRenderDefaultView()
243-
.WithModel<ModelType>().AndModelErrorFor(m => m.Property1)
244-
.Containing("e error m");
245+
.WithModel<ModelType>()
246+
.AndModelErrorFor(m => m.Property1).Containing("e error m");
245247

246248
You can chain the error property checks after any of these checks (you can only perform one of the checks though):
247249

0 commit comments

Comments
 (0)