I am using MVC2 with the MtcContrib HelpTester.
I have a problem with testing controllers that 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 is the action pointer 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 received from MbUnit:
Success
[fixture-setup] [crash] RouteTests.AdminProductShouldMapToIndex TestCase 'RouteTests.AdminProductShouldMapToIndex' failed: expected product, but there was Admin MvcContrib.TestHelper.AssertionException Message: Expected product, but there was Admin Source: Mtcestc route (44.0): in CBL.Traders.ControllerTests.RouteTests.AdminProductShouldMapToIndex ()
source share