Ejemplo n.º 1
0
        private static ViewResult ProcessCompleteResetPassword(Func <UserForgotPassword> getForgotResult, Guid?reqId = null)
        {
            var ctrlMock = ControllerTestFactory.CreateMock(new ForgotPasswordController(new Mock <ISchedulerService>().Object));

            var userRepositoryMock = ctrlMock.MockRepository(uow => uow.Users);

            userRepositoryMock.Setup(repository => repository.GetForgotPasswordRequest(It.IsAny <Guid>())).Returns(getForgotResult);

            var res        = ctrlMock.Ctrl.CompleteResetPassword(reqId ?? Guid.NewGuid());
            var viewResult = (ViewResult)res;

            return(viewResult);
        }
Ejemplo n.º 2
0
        public void Retrieve_User_Not_Found()
        {
            const string password           = "******";
            var          logonMock          = new Mock <ILogonManager>();
            var          ctrlMock           = ControllerTestFactory.CreateMock(new TokenController(logonMock.Object));
            var          userRepositoryMock = ctrlMock.MockRepository(r => r.Users);

            userRepositoryMock.Setup(x => x.GetAccountByLoginOrNull(It.IsAny <string>()))
            .Returns((AccountProjection)null);

            var res = ctrlMock.Ctrl.Retrieve(new TokenRetrieveArgs {
                Password = password
            });

            Assert.AreEqual(false, res.ReturnValue.IsAuthenticated);
        }
Ejemplo n.º 3
0
        public void Index_Post_Invalid_Model_State()
        {
            var scheduleMock = new Mock <ISchedulerService>();
            var ctrlMock     = ControllerTestFactory.CreateMock(new ForgotPasswordController(scheduleMock.Object));

            ctrlMock.Ctrl.ModelState.AddModelError("Error", "Error");

            var email = "*****@*****.**";
            var forgotPasswordModel = new ForgotPasswordModel()
            {
                Email = email
            };
            var res = ctrlMock.Ctrl.Index(forgotPasswordModel);

            ctrlMock.UnitOfWork.Verify(x => x.SaveChanges(), Times.Never);
            scheduleMock.Verify(x => x.EmailSync(It.IsAny <ResetPasswordNotificationEmailModel>()), Times.Never);
            var redirRes = (ViewResult)res;

            Assert.AreEqual(forgotPasswordModel, redirRes.ViewData.Model);
        }
Ejemplo n.º 4
0
        public void Index_Post_Success()
        {
            var scheduleMock = new Mock <ISchedulerService>();
            var ctrlMock     = ControllerTestFactory.CreateMock(new ForgotPasswordController(scheduleMock.Object));

            var userRepositoryMock = ctrlMock.MockRepository(uow => uow.Users);

            userRepositoryMock.Setup(repository => repository.GetByEmailOrNull(It.IsAny <string>(), It.IsAny <bool>())).Returns(new User());

            var email = "*****@*****.**";
            var res   = ctrlMock.Ctrl.Index(new ForgotPasswordModel()
            {
                Email = email
            });

            userRepositoryMock.Verify(x => x.GetByEmailOrNull(email, false), Times.Once);
            ctrlMock.UnitOfWork.Verify(x => x.SaveChanges(), Times.Once);
            scheduleMock.Verify(x => x.EmailSync(It.IsAny <ResetPasswordNotificationEmailModel>()), Times.Once);
            var redirRes = (RedirectToActionResult)res;

            Assert.AreEqual(redirRes.ActionName, "Success");
        }
Ejemplo n.º 5
0
        public void Retrieve_Success()
        {
            const string password           = "******";
            const string token              = "sample_token";
            var          logonMock          = new Mock <ILogonManager>();
            var          ctrlMock           = ControllerTestFactory.CreateMock(new TokenController(logonMock.Object));
            var          userRepositoryMock = ctrlMock.MockRepository(r => r.Users);

            var accountProj = new AccountProjection {
                Password = PasswordHash.HashPassword(password)
            };

            userRepositoryMock.Setup(x => x.GetAccountByLoginOrNull(It.IsAny <string>()))
            .Returns(accountProj);
            logonMock.Setup(x => x.GenerateToken(It.IsAny <LoggedClaims>(), It.IsAny <DateTime>())).Returns(token);

            var res = ctrlMock.Ctrl.Retrieve(new TokenRetrieveArgs {
                Password = password
            });

            Assert.AreEqual(true, res.ReturnValue.IsAuthenticated);
            Assert.AreEqual(token, res.ReturnValue.Token);
        }
Ejemplo n.º 6
0
        public void UserProfile_Success()
        {
            var loggedUserId = 4;
            var logonMock    = new Mock <ILogonManager>();
            var ctrlMock     = ControllerTestFactory.CreateMock(new AccountController(logonMock.Object));

            ctrlMock.LoggedUserAccessor.SetupGet(x => x.Id).Returns(loggedUserId);

            var userRepositoryMock = ctrlMock.MockRepository(uow => uow.Users);

            userRepositoryMock.Setup(r => r.GetWithRolesOrNull(It.IsAny <int>())).Returns(new User());

            var userProfileModel = new UserProfileModel();

            ctrlMock.Mapper.Setup(x => x.Map <UserProfileModel>(It.IsAny <User>()))
            .Returns((User source) => userProfileModel);

            var res = ctrlMock.Ctrl.UserProfile();

            var viewRes = (ViewResult)res;

            userRepositoryMock.Verify(r => r.GetWithRolesOrNull(loggedUserId), Times.Once);
            Assert.AreEqual(userProfileModel, viewRes.ViewData.Model);
        }