Getting started

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

Unit testing

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.

using MyApp.Controllers;
using NUnit.Framework;
using TestStack.FluentMVCTesting;

namespace MyApp.Tests.Controllers
{
    [TestFixture]
    public class HomeControllerShould
    {
        private HomeController _controller;

        [SetUp]
        public void Setup()
        {
            _controller = new HomeController();
        }

        [Test]
        public void Render_default_view_for_get_to_index()
        {
            _controller.WithCallTo(c => c.Index())
                .ShouldRenderDefaultView();
        }
    }
}

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 for a broad idea of the types of things FluentMvcTesting can do. Then dive into the Usage section for a more complete picture.

Subcutaneous testing

For an example of how we use FluentMvcTesting for writing BDD-style subcutaneous tests please see Rob's blog post.

General syntax structure

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 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)!