{"metadata":{"image":[],"title":"","description":""},"api":{"url":"","auth":"required","results":{"codes":[]},"params":[]},"next":{"description":"","pages":[]},"title":"Getting started","type":"basic","slug":"usage","excerpt":"","body":"This page demonstrates the basics for using FluentMvcTesting to get you up and running quickly. It assumes you have read and followed the [installation guide](doc:installation) \n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Unit testing\"\n}\n[/block]\nThe following code snippet is an example for how to set up a test class to use FluentMVCTesting using NUnit. **Note:** you can use any test framework - NUnit is purely used as an example.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"using MyApp.Controllers;\\nusing NUnit.Framework;\\nusing TestStack.FluentMVCTesting;\\n\\nnamespace MyApp.Tests.Controllers\\n{\\n    [TestFixture]\\n    public class HomeControllerShould\\n    {\\n        private HomeController _controller;\\n\\n        [SetUp]\\n        public void Setup()\\n        {\\n            _controller = new HomeController();\\n        }\\n\\n        [Test]\\n        public void Render_default_view_for_get_to_index()\\n        {\\n            _controller.WithCallTo(c => c.Index())\\n                .ShouldRenderDefaultView();\\n        }\\n    }\\n}\",\n      \"language\": \"csharp\"\n    }\n  ]\n}\n[/block]\nThis 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?\n\nFrom here we recommend you check out the [Examples](doc:examples) for a broad idea of the types of things FluentMvcTesting can do. Then dive into the Usage section for a more complete picture.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Subcutaneous testing\"\n}\n[/block]\nFor an example of how we use FluentMvcTesting for writing BDD-style subcutaneous tests please [see 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\": \"General syntax structure\"\n}\n[/block]\nAs you might have gathered from the above code snippet, the entry point to the library is the `WithCallTo` extension method on the MVC Controller class (or alternatively the [`WithCallToChild`](doc:child-actions) extension method). Inside of that method call you simply pass in a lambda expression indicates the action call you are trying to test. From there you can use intellisense to guide the rest (or check out our Usage section)!","updates":[],"order":2,"isReference":false,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"54cfc714bba1a023008741f1","createdAt":"2015-02-02T18:51:00.086Z","version":{"version":"1.0","version_clean":"1.0.0","codename":"","is_stable":true,"is_beta":false,"is_hidden":false,"is_deprecated":false,"categories":["54cfb737bba1a023008741a2","54cfc6f75ff7e617002bbdae","54cfcbaebba1a023008741fc","54cfd0295ff7e617002bbdd9","54cfd05b3995cf0d0006f741"],"_id":"54cfb736bba1a023008741a1","releaseDate":"2015-02-02T17:43:18.560Z","__v":5,"createdAt":"2015-02-02T17:43:18.560Z","project":"54cfb736bba1a0230087419e"},"githubsync":"","project":"54cfb736bba1a0230087419e","user":"54c4ca54686bce0d00efe1b9","category":{"sync":{"isSync":false,"url":""},"pages":["54cfb737bba1a023008741a4","54cfba45bba1a023008741bd"],"title":"Introduction","slug":"introduction","order":0,"from_sync":false,"reference":false,"_id":"54cfb737bba1a023008741a2","__v":2,"createdAt":"2015-02-02T17:43:19.055Z","project":"54cfb736bba1a0230087419e","version":"54cfb736bba1a023008741a1"},"__v":7}
This page demonstrates the basics for using FluentMvcTesting to get you up and running quickly. It assumes you have read and followed the [installation guide](doc:installation) [block:api-header] { "type": "basic", "title": "Unit testing" } [/block] The following code snippet is an example for how to set up a test class to use FluentMVCTesting using NUnit. **Note:** you can use any test framework - NUnit is purely used as an example. [block:code] { "codes": [ { "code": "using MyApp.Controllers;\nusing NUnit.Framework;\nusing TestStack.FluentMVCTesting;\n\nnamespace MyApp.Tests.Controllers\n{\n [TestFixture]\n public class HomeControllerShould\n {\n private HomeController _controller;\n\n [SetUp]\n public void Setup()\n {\n _controller = new HomeController();\n }\n\n [Test]\n public void Render_default_view_for_get_to_index()\n {\n _controller.WithCallTo(c => c.Index())\n .ShouldRenderDefaultView();\n }\n }\n}", "language": "csharp" } ] } [/block] 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? From here we recommend you check out the [Examples](doc:examples) for a broad idea of the types of things FluentMvcTesting can do. Then dive into the Usage section for a more complete picture. [block:api-header] { "type": "basic", "title": "Subcutaneous testing" } [/block] For an example of how we use FluentMvcTesting for writing BDD-style subcutaneous tests please [see Rob's blog post](http://robdmoore.id.au/blog/2015/01/26/review-of-jimmy-bogard-holistic-testing/). [block:api-header] { "type": "basic", "title": "General syntax structure" } [/block] As you might have gathered from the above code snippet, the entry point to the library is the `WithCallTo` extension method on the MVC Controller class (or alternatively the [`WithCallToChild`](doc:child-actions) extension method). Inside of that method call you simply pass in a lambda expression indicates the action call you are trying to test. From there you can use intellisense to guide the rest (or check out our Usage section)!