Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class AccountController : Controller
- {
- public IMembershipService MembershipService { get; set; }
- protected override void Initialize(RequestContext requestContext)
- {
- if (MembershipService == null) { MembershipService = new AccountMembershipService(); }
- base.Initialize(requestContext);
- }
- public AccountController(IMembershipService membership)
- {
- MembershipService = membership;
- }
- [HttpPost]
- public ActionResult Login(LoginModel model, string ReturnUrl)
- {
- if (ModelState.IsValid)
- {
- if (MembershipService.ValidateUser(model.EmailorUserName, model.Password))
- {
- .....
- }
- }
- }
- public class AccountControllerTest2
- {
- [Test]
- public void Login_UserCanLogin()
- {
- string returnUrl = "/Home/Index";
- string userName = "user1";
- string password = "password1";
- Mock<AccountMembershipService> Membership = new Mock<AccountMembershipService>();
- AccountController Controller = new AccountController(Membership.Object);
- var model = new LoginModel
- {
- EmailorUserName = userName,
- Password = password
- };
- var result = Controller.Login(model, returnUrl) as RedirectResult;
- Assert.NotNull(result);
- Assert.AreEqual(returnUrl, result.Url);
- }
- }
- <membership defaultProvider="CustomMembershipProvider">
- <providers>
- <clear />
- <add name="CustomMembershipProvider" type="QUBBasketballMVC.Infrastructure.CustomMembershipProvider" connectionStringName="UsersContext" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
- </providers>
- </membership>
- Mock<IMembershipService> Membership = new Mock<IMembershipService>();
- if (MembershipService == null)
- MembershipService = new AccountMembershipService();
Add Comment
Please, Sign In to add comment