Featured post
asp.net - How to unit test for turning off request validation? -
i'm new @ tdd thing making serious effort, i'm hoping feedback here.
i created little web service minify javascript, , nice, tests passing. noticed bug: if tried minify alert('<script>');
, throw httprequestvalidationexception
.
so that's easy enough fix. i'll add [allowhtml]
controller. way unit test doesn't happen in future?
the following first thought:
[testmethod] public void minify_doesntchokeonhtml() { try { using (var controller = servicelocator.current.getinstance<minifycontroller>()) { return controller.minify("alert('<script></script>');"); } } catch (httprequestvalidationexception) { assert.fail("request validation prevented html existing inside javascript."); } }
however, doesn't work since getting controller instance , running methods on it, instead of firing whole asp.net pipeline.
what unit test this? maybe reflector on controller method see if [allowhtml]
attribute present? seems structural, , unlikely survive refactoring; functional might make more sense. ideas?
you have 2 options:
first
write integration test hosts mvc in-proc or runs using browser (using watin instance) cover scenario.
second
write unit test check method marked needed attribute.
i go first option.
- Get link
- X
- Other Apps
Comments
Post a Comment