Exemplo n.º 1
0
 private static FakeIdentityServiceBase Identity(FakeUserStore userStore           = null,
                                                 FakeUserValidators userValidators = null,
                                                 FakeClaimsAuthenticationService1 claimsAuthenticationService = null,
                                                 FakeClaimsConverter claimsConverter = null) =>
 new FakeIdentityServiceBase(userStore ?? UserStore(),
                             userValidators ?? UserValidators(),
                             claimsAuthenticationService ?? ClaimsAuthenticationService(),
                             claimsConverter ?? ClaimsConverter());
Exemplo n.º 2
0
        public void Login_Success_Returns_Account(string username, string password, bool remember)
        {
            var mockAuthenticator = new Mock <IAuthenticator>();
            var fakeUserStore     = new FakeUserStore();
            var controller        = new AccountController(fakeUserStore, mockAuthenticator.Object);

            mockAuthenticator.Setup(auth => auth.SetAuthCookie(username, remember)).Verifiable();
            controller.SignIn(username, password, null, remember);
            mockAuthenticator.Verify();
        }
Exemplo n.º 3
0
        public void Login_Works_With_Supplied_ReturnUrl()
        {
            var mockAuthenticator = new Mock <IAuthenticator>();
            var fakeUserStore     = new FakeUserStore();
            var controller        = new AccountController(fakeUserStore, mockAuthenticator.Object);
            var result            = controller.SignIn("/foo/bar", null) as ViewResult;

            result.ShouldNotBe(null);
            mockAuthenticator.Verify();
            ((SignInViewModel)result.Model).ReturnUrl.ShouldBe("/foo/bar");
        }
        public void FindAsync_ShouldReturnNullIfNoUserFound()
        {
            // Setup dependencies
            var userStore = new FakeUserStore().Build();

            // Call FindAsync
            var returnedUser = _userManager
                               .WithUserStore(userStore.Object).Build()
                               .FindAsync("IDontExist", "password").Result;

            // Verify result
            Assert.IsNull(returnedUser);
        }
Exemplo n.º 5
0
        public void Login_Incorrect_Password_Returns_View(string username, string password, bool remember)
        {
            var mockAuthenticator = new Mock <IAuthenticator>();
            var fakeUserStore     = new FakeUserStore();
            var controller        = new AccountController(fakeUserStore, mockAuthenticator.Object);

            mockAuthenticator.Setup(auth => auth.SetAuthCookie(It.IsAny <string>(), It.IsAny <bool>()))
            .Callback(() => Assert.Fail("Incorrect password should not set auth cookie"));
            var result = controller.SignIn(username, password, null, remember) as ViewResult;

            result.ShouldNotBe(null);
            mockAuthenticator.Verify();
            ((SignInViewModel)result.Model).Message.ShouldBe("Incorrect password");
        }
        public void FindAsync_ShouldReturnCorrectUser()
        {
            // Setup dependencies
            var user = new User {
                UserName = "******"
            };

            var userStore = new FakeUserStore()
                            .WithUser(user).Build();

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

            // Call FindAsync
            var returnedUser = _userManager
                               .WithUserStore(userStore.Object)
                               .WithPasswordHasher(passwordHasher.Object).Build()
                               .FindAsync("TestUser", "TestPassword").Result;

            Assert.AreEqual(user, returnedUser);
        }
Exemplo n.º 7
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");
        }
        public void FindAsync_ShouldReturnNullForIncorrectPassword()
        {
            // Setup dependencies
            var user = new User {
                UserName = "******"
            };

            var userStore = new FakeUserStore()
                            .WithUser(user).Build();

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

            // Call FindAsync
            var returnedUser = _userManager
                               .WithUserStore(userStore.Object)
                               .WithPasswordHasher(passwordHasher.Object).Build()
                               .FindAsync("TestUser", "TestPassword").Result;

            // Verify result
            Assert.IsNull(returnedUser);
        }
        public void CreateAsync_ShouldCreateUser()
        {
            // Setup dependencies
            var userStore = new FakeUserStore()
                            .WithAbilityToCreateUser().Build();

            var passwordHasher = new FakePasswordHasher()
                                 .WithPasswordSalt("TestSalt").Build();

            var user = new User {
                UserName = "******", PasswordHash = "TestPasswordHash"
            };

            // Call CreateAsync
            var returnedUser = _userManager
                               .WithUserStore(userStore.Object)
                               .WithPasswordHasher(passwordHasher.Object).Build()
                               .CreateAsync(user).Result;

            // Verify Result
            passwordHasher.Verify(ph => ph.HashPassword("TestPasswordHash"), Times.Once);
            userStore.Verify(us => us.CreateAsync(It.Is <User>(u => u.UserName == "TestUser")), Times.Once);
        }
 private static FakeClaimsAuthenticationServiceBase Authentication(
     FakeUserStore userStore = null, ClaimOptions options = null,
     FakeSystemClock clock   = null) =>
 new FakeClaimsAuthenticationServiceBase(userStore ?? UserStore(),
                                         options ?? Options(), clock ?? Clock());
 private static FakeClaimsAuthenticationService2 Authentication(
     FakeHttpContextAccessor httpContextAccessor = null,
     FakeUserStore userStore = null, ClaimOptions options = null,
     FakeSystemClock clock   = null) =>
 new FakeClaimsAuthenticationService2(httpContextAccessor ?? HttpContextAccessor(),
                                      userStore ?? UserStore(), options ?? Options(), clock ?? Clock());