You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I can explicitly define whatever signatures I want to allow this terser syntax, but obviously the different permutations that are possible are mind-boggling and it wouldn't be helpful for any custom types in your project. Unfortunately, despite best efforts I couldn't figure out a way to generically specify these definitions - if anyone has ideas for how to do this let me know!
105
106
@@ -109,16 +110,147 @@ If you have 1-3 parameters being passed into the action being redirected to then
109
110
110
111
Then you can write the following test for the redirect:
If you have more than three parameters, or you are uncomfortable with that syntax then you can specify a lambda with a call to the action you want and pass in dummy values for the parameters, e.g. for the previous example:
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.
123
127
124
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.
129
+
130
+
### Redirect to action in another controller
131
+
132
+
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):
/* Assertions on the data being turned into json (data) */}
177
+
);
178
+
179
+
### Model tests
180
+
181
+
If you assert that the action returns a view of some sort there are some other methods that you can call (seen easily using intellisense). These allow you to check the model, e.g.:
.WithModel<ModelType>(m => {/* Make assertions on m */});
198
+
199
+
Note: if you use any of these model tests then it will check that the model passed through isn't null.
200
+
201
+
### Model error tests
202
+
203
+
Once you have made assertions about the model you can then make assertions that particular model errors are present for properties of that model. While it's not generally the best idea to add validation logic to controllers ([doing it unobtrusively is best](http://robdmoore.id.au/blog/2012/04/27/unobtrusive-validation-in-asp-net-mvc-3-and-4/)), sometimes it's useful.
You can also make assertions on the content of the error message(s); these methods will look for any error messages against that particular model state key that match the given criteria:
0 commit comments