views:

121

answers:

0

I am using MVC2 with MvcContrib HelpTester.

I have problem with testing Controllers which are in Areas.

Here is my Test class :

[TestFixture]
    public class RouteTests
    {


        [TestFixtureSetUp]
        public void Setup()
        {
            RouteTable.Routes.Clear();
            MvcApplication.RegisterRoutes(RouteTable.Routes);
        }

        [Test]
        public void RootMatchesHome()
        {
            "~/".ShouldMapTo<TradersSite.Controllers.HomeController>(x => x.Index());

        }


        [Test]
        public void AdminProductShouldMapToIndex()
        {
            "~/Admin/Produit/".ShouldMapTo<TradersSite.Areas.Admin.Controllers.ProductController>(x => x.Index());

        }

Here's the action Index from my ProductController in the Admin Area :

public ActionResult Index(int? page)
        {
            int pageSize = 10;
            int startIndex = page.GetValueOrDefault() * pageSize; 

            var products = _productRepository.GetAllProducts()
                                             .Skip(startIndex)
                                             .Take(pageSize);

            return View("Index", products);
        }

Here is the route map in my AdminAreaRefistration :

public override void RegisterArea(AreaRegistrationContext context)
        {
            context.MapRoute(
                "Admin_default",
                "Admin/{controller}/{action}/{id}",
                new { action = "Index", id = UrlParameter.Optional }
            );
        }

Finally here is the message I get back from MbUnit :

[fixture-setup] success [failure] RouteTests.AdminProductShouldMapToIndex TestCase 'RouteTests.AdminProductShouldMapToIndex' failed: Expected Product but was Admin MvcContrib.TestHelper.AssertionException Message: Expected Product but was Admin Source: MvcContrib.TestHelper StackTrace: RouteTests.cs(44,0): at CBL.Traders.ControllerTests.RouteTests.AdminProductShouldMapToIndex()