public static AccountController GetAccountController(MockFormsAuthenticationService mockFormsAuthenticationService, MockMembershipService mockMembershipService) { RequestContext requestContext = new RequestContext(new MockHttpContext(), new RouteData()); AccountController controller = new AccountController(mockFormsAuthenticationService, mockMembershipService) { Url = new UrlHelper(requestContext), }; controller.ControllerContext = new ControllerContext() { Controller = controller, RequestContext = requestContext }; return controller; }
public void LogOn_Post_ReturnsRedirectToHomeOnSuccess_WithExternalReturnUrl() { // Arrange var mockFormsAuthenticationService = new MockFormsAuthenticationService(); var mockMembershipService = new MockMembershipService(); AccountController controller = GetAccountController(mockFormsAuthenticationService, mockMembershipService); LogOnModel model = new LogOnModel() { UserName = "******", Password = "******", RememberMe = false }; // Act ActionResult result = controller.LogOn(model, "http://malicious.example.net"); // Assert Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult)); RedirectToRouteResult redirectResult = (RedirectToRouteResult)result; Assert.AreEqual("Home", redirectResult.RouteValues["controller"]); Assert.AreEqual("Index", redirectResult.RouteValues["action"]); Assert.IsTrue(mockFormsAuthenticationService.SignIn_WasCalled); }
public void LogOn_Post_ReturnsRedirectOnSuccess_WithLocalReturnUrl() { // Arrange var mockFormsAuthenticationService = new MockFormsAuthenticationService(); var mockMembershipService = new MockMembershipService(); AccountController controller = GetAccountController(mockFormsAuthenticationService, mockMembershipService); LogOnModel model = new LogOnModel() { UserName = "******", Password = "******", RememberMe = false }; // Act ActionResult result = controller.LogOn(model, "/someUrl"); // Assert Assert.IsInstanceOfType(result, typeof(RedirectResult)); RedirectResult redirectResult = (RedirectResult)result; Assert.AreEqual("/someUrl", redirectResult.Url); Assert.IsTrue(mockFormsAuthenticationService.SignIn_WasCalled); }
public static AccountController GetAccountController() { var mockFormsAuthenticationService = new MockFormsAuthenticationService(); var mockMembershipService = new MockMembershipService(); return GetAccountController(mockFormsAuthenticationService, mockMembershipService); }
public void LogOff_LogsOutAndRedirects() { // Arrange var mockFormsAuthenticationService = new MockFormsAuthenticationService(); var mockMembershipService = new MockMembershipService(); AccountController controller = GetAccountController(mockFormsAuthenticationService, mockMembershipService); // Act ActionResult result = controller.LogOff(); // Assert Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult)); RedirectToRouteResult redirectResult = (RedirectToRouteResult)result; Assert.AreEqual("Home", redirectResult.RouteValues["controller"]); Assert.AreEqual("Index", redirectResult.RouteValues["action"]); Assert.IsTrue(mockFormsAuthenticationService.SignOut_WasCalled); }