{"__v":4,"_id":"54cfb737bba1a023008741a4","category":{"__v":2,"_id":"54cfb737bba1a023008741a2","pages":["54cfb737bba1a023008741a4","54cfba45bba1a023008741bd"],"project":"54cfb736bba1a0230087419e","version":"54cfb736bba1a023008741a1","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-02-02T17:43:19.055Z","from_sync":false,"order":0,"slug":"introduction","title":"Introduction"},"project":"54cfb736bba1a0230087419e","user":"54c4ca54686bce0d00efe1b9","version":{"__v":5,"_id":"54cfb736bba1a023008741a1","project":"54cfb736bba1a0230087419e","createdAt":"2015-02-02T17:43:18.560Z","releaseDate":"2015-02-02T17:43:18.560Z","categories":["54cfb737bba1a023008741a2","54cfc6f75ff7e617002bbdae","54cfcbaebba1a023008741fc","54cfd0295ff7e617002bbdd9","54cfd05b3995cf0d0006f741"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-02-02T17:43:19.769Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":0,"body":"This library provides a fluent interface for creating terse, expressive and (where possible) type-safe tests against ASP.NET MVC controllers.\n\nThere are two types of tests you might want to use it for:\n\n* Unit tests against the MVC Controllers (e.g. with dependencies mocked out)\n* [Subcutaneous tests](http://lostechies.com/jimmybogard/2010/08/25/an-effective-testing-strategy/) against the MVC Controllers (e.g. with real dependencies)\n\nThis library is testing framework agnostic, so you can combine it with the testing library of your choice (e.g. NUnit, xUnit, etc.).\n\nThe library is compatible with the AAA testing methodology, although it combines the Act and Assert parts together depending on how you use it. See the [code examples](doc:examples) for an idea of what the syntax looks like.\n\nThis library was originally inspired by the [MVCContrib.TestHelper](http://mvccontrib.codeplex.com/wikipage?title=TestHelper) library.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Using FluentMvcTesting for unit tests\"\n}\n[/block]\nIn general we recommend that you keep your MVC controllers really lean (2 or 3 lines) in which case the controller probably doesn't need a test since it will be clear at a glance that it's correct or not and it will be unlikely to have regressions. This library is great for those situations where you have to have a meaty controller, which in turn warrants test coverage.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Using FluentMvcTesting for subcutaneous tests\"\n}\n[/block]\nThis library works really well when writing subcutaneous tests against a controller. More specifically, if you are writing your tests in a BDD style then the types of assertions that you can easily and quickly perform with this library are quite helpful. For instance, you may want to assert that after the user performs an action that they get shown a success page - this can easily be achieved by ensuring the `ActionResult` returned by the MVC action is a redirect to the `Success` action. For a more complete explanation of this technique including a real-world code sample please see the \"Subcutaneous testing\" section of [Rob's blog post](http://robdmoore.id.au/blog/2015/01/26/review-of-jimmy-bogard-holistic-testing/).\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Motivation\"\n}\n[/block]\nThe motivation behind this library is to provide a way to test MVC actions quickly, tersely and maintainably.\n\nMost examples we find on MVC controller testing are incredibly verbose, repetitive and time-consuming to write and maintain and we've also noticed most examples of controller testing having a lot of magic strings being used to test view and action names.\n\nThis library aims to make the time to implement controller tests really small for those situations where you find yourself needing to write them and it also aims to (where possible) utilize the type system to resolve a lot of those nasty magic strings thus ensuring your tests are more maintainable and require less re-work when you perform major refactoring of your code.","excerpt":"","slug":"getting-started","type":"basic","title":"Introduction to FluentMvcTesting"}

Introduction to FluentMvcTesting


This library provides a fluent interface for creating terse, expressive and (where possible) type-safe tests against ASP.NET MVC controllers. There are two types of tests you might want to use it for: * Unit tests against the MVC Controllers (e.g. with dependencies mocked out) * [Subcutaneous tests](http://lostechies.com/jimmybogard/2010/08/25/an-effective-testing-strategy/) against the MVC Controllers (e.g. with real dependencies) This library is testing framework agnostic, so you can combine it with the testing library of your choice (e.g. NUnit, xUnit, etc.). The library is compatible with the AAA testing methodology, although it combines the Act and Assert parts together depending on how you use it. See the [code examples](doc:examples) for an idea of what the syntax looks like. This library was originally inspired by the [MVCContrib.TestHelper](http://mvccontrib.codeplex.com/wikipage?title=TestHelper) library. [block:api-header] { "type": "basic", "title": "Using FluentMvcTesting for unit tests" } [/block] In general we recommend that you keep your MVC controllers really lean (2 or 3 lines) in which case the controller probably doesn't need a test since it will be clear at a glance that it's correct or not and it will be unlikely to have regressions. This library is great for those situations where you have to have a meaty controller, which in turn warrants test coverage. [block:api-header] { "type": "basic", "title": "Using FluentMvcTesting for subcutaneous tests" } [/block] This library works really well when writing subcutaneous tests against a controller. More specifically, if you are writing your tests in a BDD style then the types of assertions that you can easily and quickly perform with this library are quite helpful. For instance, you may want to assert that after the user performs an action that they get shown a success page - this can easily be achieved by ensuring the `ActionResult` returned by the MVC action is a redirect to the `Success` action. For a more complete explanation of this technique including a real-world code sample please see the "Subcutaneous testing" section of [Rob's blog post](http://robdmoore.id.au/blog/2015/01/26/review-of-jimmy-bogard-holistic-testing/). [block:api-header] { "type": "basic", "title": "Motivation" } [/block] The motivation behind this library is to provide a way to test MVC actions quickly, tersely and maintainably. Most examples we find on MVC controller testing are incredibly verbose, repetitive and time-consuming to write and maintain and we've also noticed most examples of controller testing having a lot of magic strings being used to test view and action names. This library aims to make the time to implement controller tests really small for those situations where you find yourself needing to write them and it also aims to (where possible) utilize the type system to resolve a lot of those nasty magic strings thus ensuring your tests are more maintainable and require less re-work when you perform major refactoring of your code.