MVCContrib Route Tracing with Areas

I am using MVC 2 with scopes. To check the routing, I use MvcContrib.

This is the testing code:

[Test] public void Home() { MvcApplication.RegisterRoutes(RouteTable.Routes); "~/".ShouldMapTo<HomeController>(x => x.Login("Nps")); } 

I am not sure how to call the routing definition that is stored in the zones. Calling AreaRegistration.RegisterAllAreas () is not an option as it gives an exception.

Thanks Revin

+4
source share
3 answers

I do what works for me

 [Test] public void VerifyRouteMapFor_Test_Area_TestController() { RouteTable.Routes.Clear(); var testAreaRegistration = new testAreaRegistration(); testAreaRegistration.RegisterArea(new AreaRegistrationContext(testAreaRegistration.AreaName, RouteTable.Routes)); "~/test/index".ShouldMapTo<testController>(x => x.Index()); } 
+5
source

Instead of calling RegisterAllAreas, you should call the regional registration for the area you are testing. RegisterAllAreas scans all loaded assemblies and as a result does too much for the test. I would manually configure the test. If it still passes, and the exception sends it here or to the mvccontrib mailing list. I am sure there are some cases where TestHelper needs to be updated in order to better support areas. We have not added support for a specific area to test assistants.

+1
source

For unit test, it might be best to do one area. But for the integration test, you want to test all routes in context, imo.

0
source

Source: https://habr.com/ru/post/1307406/


All Articles