Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Story: "Blog admin logs in to the system"
- As a blog writer
- I want to be able to log in to my blog
- So that I can write posts and administrate my blog
- Scenario: "Logs in from the login page"
- Given the user enters in correct credentials for a user in the system
- When the user clicks the "Login" button
- Then log the user in and redirect to the admin panel with a message
- stating that he logged in correctly
- using System;
- using Machine.Specifications;
- using Machine.Specifications.Model;
- using Moq;
- using MyBlog.Controllers;
- using System.Web.Mvc;
- using MoqIt = Moq.It;
- using ThenIt = Machine.Specifications.It;
- [Subject("User tries logging in")]
- public class When_user_enters_valid_credentials : With_user_existing_in_membership
- {
- protected static ActionResult result;
- Because of = () =>
- {
- result = loginController.Login(validUsername, validPassword);
- };
- ThenIt should_log_the_user_in;
- ThenIt should_redirect_the_user_to_the_admin_panel;
- ThenIt should_show_message_confirming_successful_login;
- }
- public abstract class With_user_existing_in_membership
- {
- protected static Mock<ISiteMembership> membershipMock;
- protected static string validUsername;
- protected static string validPassword;
- protected static LoginController loginController;
- Establish context =()=>
- {
- membershipMock = new Mock<ISiteMembership>();
- validUsername = "ValidUsername";
- validPassword = "ValidPassword";
- //make sure it's treated as valid usernames and password
- membershipMock.Setup<bool>(m => m.Validate(MoqIt.Is<string>(s => s == validUsername), MoqIt.Is<string>(s => s == validPassword)))
- .Returns(true);
- loginController = new LoginController(membershipMock.Object);
- };
- }
- // The "Subject" attribute is used as the "Scenario" in
- // in your original story, and gets rendered with your
- // MSpec report that is outputted (especially the HTML version).
- [Subject("Login Page")]
- public class When_user_enters_valid_credentials_for_existing_user
- : MembershipContext
- {
- static ActionResult result;
- static string username;
- static string password;
- // This is optional, but will inherit the MembershipContext, and
- // allow for more specific setup of your context for these
- // grouped specs only.
- Establish context = () =>
- {
- username = "ValidUsername";
- password = "ValidPassword";
- // This is context-specific: Username/password is valid
- membership.Setup<bool>(
- m => m.Validate(
- Param.Is<string>(s => s == username)
- ,Param.Is<string>(s => s == password)
- )
- ).Returns(true);
- };
- Because of = () =>
- {
- result = loginController.Login(username, password);
- };
- It should_log_the_user_in;
- It should_redirect_the_user_to_the_admin_panel;
- It should_show_message_confirming_successful_login;
- }
- public abstract class MembershipContext
- {
- protected static Mock<ISiteMembership> membership;
- protected static LoginController loginController;
- Establish context = () =>
- {
- membership = new Mock<ISiteMembership>();
- loginController = new LoginController(membershipMock.Object);
- };
- }
Add Comment
Please, Sign In to add comment