예제 #1
0
        public void Register_ShouldReturnViewIfUserCannotBeCreated()
        {
            // Setup dependencies
            var request     = ConstructDefaultRegisterViewModel();
            var userManager = new MockUserManager()
                              .WithUserCreationResult(IdentityResult.Failed());

            // Call register
            var result = _controller
                         .WithUserManager(userManager).Build()
                         .Register(request).Result;

            // Verify result
            result.AssertIsView("Register");
        }
예제 #2
0
        public void Login_ShouldAddModelErrorOnSignInFailure()
        {
            // Setup sign in manager
            var userManager           = new MockUserManager();
            var authenticationManager = new FakeAuthenticationManager().Build();
            var signInManager         = new MockSignInManager(userManager, authenticationManager.Object);

            AccountController controller = _controller
                                           .WithSignInManager(signInManager).Build();

            // Call Login method
            var request = new LoginViewModel {
                Email = "*****@*****.**", Password = "******"
            };
            ActionResult result = controller.Login(request).Result;

            // Verify result
            result.AssertIsStatus(HttpStatusCode.Forbidden);
        }
예제 #3
0
        public void Register_ShouldCreateUser()
        {
            // Setup dependencies
            var request = ConstructDefaultRegisterViewModel();

            var userStore = new FakeUserStore()
                            .WithAbilityToCreateUser().Build();

            var passwordHasher = new FakePasswordHasher()
                                 .WithResult(PasswordVerificationResult.Success).Build();

            var userManager = new MockUserManager(userStore.Object, passwordHasher.Object)
                              .WithUserCreationResult(IdentityResult.Success);

            // Call register
            var result = _controller
                         .WithUserManager(userManager).Build()
                         .Register(request).Result;

            // Verify result
            result.AssertIsRedirect("Home", "Index");
        }
예제 #4
0
        public void Register_ShouldSignInUserIfCreated()
        {
            // Setup dependencies
            var request = ConstructDefaultRegisterViewModel();

            var userManager = new MockUserManager()
                              .WithUserCreationResult(IdentityResult.Success);

            var authenticationManager = new FakeAuthenticationManager().Build();
            var signInManager         = new MockSignInManager(userManager, authenticationManager.Object);

            // Call register
            var result = _controller
                         .WithUserManager(userManager)
                         .WithSignInManager(signInManager).Build()
                         .Register(request).Result;

            // Verify result
            authenticationManager.Verify(
                a => a.SignIn(It.IsAny <AuthenticationProperties>(), It.IsAny <ClaimsIdentity[]>()), Times.Once);

            result.AssertIsRedirect("Home", "Index");
        }