protected override void Test() { Application.Execute((client, context) => { // Arrange. const string Username = "******"; const string Password = "******"; // Save user to database. context.User(Username, Password); var form = new LoginForm { Username = Username, Password = Password }; var view = new CrowbarViewContext("_LoginForm").SetAnonymousPrincipal(); // Act. var response = client.Render(view, form).Submit(); // Assert. response.ShouldHaveTemporarilyRedirectTo(AppRoute.App); response.ShouldHaveCookie(FormsAuthentication.FormsCookieName); }); }
public void Can_specify_custom_route_data_values() { Execute(client => { HttpCookieCollection cookies; var context = new CrowbarViewContext("Index") { ControllerName = "Custom" }; Assert.DoesNotThrow(() => CrowbarController.ToString(context, null, out cookies)); }); }
public void Should_be_able_to_post_form_with_anti_forgery_request_token_using_render() { Execute(client => { const string username = "******"; var context = new CrowbarViewContext("~/Views/Partials/_FormAntiForgeryRequestToken.cshtml").SetFormsAuthPrincipal(username); var payload = new TextBoxPayload { Text = "text" }; var response = client.Render(context, payload).Submit(x => x.FormsAuth(username)); response.ShouldHaveStatusCode(HttpStatusCode.OK); }); }
protected override void Test() { Application.Execute((client, context) => { // Arrange. const string Username = "******"; const string Password = "******"; // Save user to database. context.User(Username, Password); var form = new LoginForm { Username = Username, Password = Password }; var view = new CrowbarViewContext("_LoginForm"); view.SetFormsAuthPrincipal("invalid"); // simulate invalid anti-forgery request token. // Act. // Obviously the MVC application should handle this more gracefully, this is just an example. var exception = Assert.Throws<CrowbarException>(() => client.Render(view, form).Submit()); // Assert. Assert.That(exception.InnerException, Is.TypeOf<HttpAntiForgeryException>()); }); }