コード例 #1
0
        public void TestPasswordAndConfirmPasswordDoNotMatch()
        {
            MockStoreContexts    mocks = new MockStoreContexts();
            Change_PasswordModel cpm   = new Change_PasswordModel(mocks.UserManager.Object, mocks.SignInManager.Object)
            {
                Password        = "******",
                ConfirmPassword = "******"
            };

            var result = cpm.OnPostAsync().Result;

            Assert.IsType <PageResult>(result);
        }
コード例 #2
0
        public void TestPasswordAndConfirmPasswordDoMatchButInvalidModel()
        {
            MockStoreContexts    mocks = new MockStoreContexts();
            Change_PasswordModel cpm   = new Change_PasswordModel(mocks.UserManager.Object, mocks.SignInManager.Object)
            {
                Password        = "******",
                ConfirmPassword = "******"
            };

            MockValidation.CheckValidation(cpm);
            var result = cpm.OnPostAsync().Result;

            Assert.IsType <PageResult>(result);
        }
コード例 #3
0
        public void TestPasswordMatchingAndValidModelStateButNoUserIsFound()
        {
            MockStoreContexts    mocks = new MockStoreContexts();
            Change_PasswordModel cpm   = new Change_PasswordModel(mocks.UserManager.Object, mocks.SignInManager.Object)
            {
                Name            = "*****@*****.**",
                Password        = "******",
                ConfirmPassword = "******"
            };

            mocks.UserManager.Setup(x => x.FindByNameAsync(It.IsAny <string>()))
            .ReturnsAsync((ApplicationUser)null);

            MockValidation.CheckValidation(cpm);
            var result = cpm.OnPostAsync().Result;

            Assert.IsType <PageResult>(result);
        }
コード例 #4
0
        public void TestPasswordMatchingAndValidModelStateAndUserButFailedToUpdate()
        {
            MockStoreContexts    mocks = new MockStoreContexts();
            Change_PasswordModel cpm   = new Change_PasswordModel(mocks.UserManager.Object, mocks.SignInManager.Object)
            {
                Name            = "*****@*****.**",
                Password        = "******",
                ConfirmPassword = "******"
            };

            mocks.UserManager.Setup(x => x.FindByNameAsync(It.IsAny <string>()))
            .ReturnsAsync(new ApplicationUser {
                PasswordHash = "abcdefg"
            });
            mocks.UserManager.Setup(x => x.UpdateAsync(It.IsAny <ApplicationUser>()))
            .ReturnsAsync(IdentityResult.Failed());

            MockValidation.CheckValidation(cpm);
            var result = cpm.OnPostAsync().Result;

            Assert.IsType <PageResult>(result);
        }
コード例 #5
0
        public void TestPasswordMatchingAndValidModelStateAndUserAndUpdates()
        {
            MockStoreContexts    mocks = new MockStoreContexts();
            Change_PasswordModel cpm   = new Change_PasswordModel(mocks.UserManager.Object, mocks.SignInManager.Object)
            {
                Name            = "*****@*****.**",
                Password        = "******",
                ConfirmPassword = "******"
            };

            mocks.UserManager.Setup(x => x.FindByNameAsync(It.IsAny <string>()))
            .ReturnsAsync(new ApplicationUser {
                PasswordHash = "abcdefg"
            });
            mocks.UserManager.Setup(x => x.UpdateAsync(It.IsAny <ApplicationUser>()))
            .ReturnsAsync(IdentityResult.Success);

            MockValidation.CheckValidation(cpm);
            var result = cpm.OnPostAsync().Result;
            RedirectToPageResult check = (RedirectToPageResult)result;

            Assert.Equal("/Dashboard", check.PageName);
        }