Created
November 12, 2012 13:44
-
-
Save lfreneda/4059466 to your computer and use it in GitHub Desktop.
Base Class for Controller tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SimpleControllerTests { | |
public void EnsureActionViewName<TController>(Func<TController, ActionResult> executeAction, string viewNameExpected) | |
where TController : Controller { | |
var controller = Activator.CreateInstance<TController>(); | |
var viewResult = executeAction.Invoke(controller) as ViewResultBase; | |
AssertViewName(viewNameExpected, viewResult); | |
} | |
public void EnsureActionViewName(Func<ActionResult> executeAction, string viewNameExpected) { | |
var viewResult = executeAction.Invoke() as ViewResultBase; | |
AssertViewName(viewNameExpected, viewResult); | |
} | |
public void EnsureModelType<TController>(Func<TController, ActionResult> executeAction, Type modelTypeExpected) { | |
var controller = Activator.CreateInstance<TController>(); | |
var viewResult = executeAction.Invoke(controller) as ViewResultBase; | |
AssertType(modelTypeExpected, viewResult); | |
} | |
public void EnsureModelType(Func<ActionResult> executeAction, Type modelTypeExpected) { | |
var viewResult = executeAction.Invoke() as ViewResultBase; | |
AssertType(modelTypeExpected, viewResult); | |
} | |
private static void AssertType(Type modelTypeExpected, ViewResultBase viewResult) { | |
viewResult.Model.GetType().Should().Be.EqualTo(modelTypeExpected); | |
} | |
private static void AssertViewName(string viewNameExpected, ViewResultBase viewResult) { | |
viewResult.ViewName.Should().Be(viewNameExpected); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment