Пример #1
0
 public ActionResult ChangePassword(ChangePasswordModel model)
 {
     try
     {
         customerAccountService.ChangePassword(model.Email, model.OldPassword, model.NewPassword);
         return Json(new OporationWithoutReturnValueJsonModel());
     }
     catch (Exception ex)
     {
         return Json(new OporationWithoutReturnValueJsonModel(true, ex.Message));
     }
 }
        public void ChangePassword_ShouldTryToChangeThePassword()
        {
            //Arrange
            var model = new ChangePasswordModel();

            var customerAccountService = MockRepository.GenerateMock<ICustomerAccountService>();
            customerAccountService.Expect(x => x.ChangePassword(
                Arg<string>.Is.Equal(model.Email),
                Arg<string>.Is.Equal(model.OldPassword),
                Arg<string>.Is.Equal(model.NewPassword)
                )).Repeat.Once();

            //Act
            var controller = CreateDefaultMyAccountControllerWithCustomCustomerAccountService(customerAccountService);
            //Assert
            controller.ChangePassword(model);

            customerAccountService.VerifyAllExpectations();
        }
        public void ChangePassword_ShouldReturnHasErrorTrueIfExceptionWasThrowm()
        {
            //Arrange
            var model = new ChangePasswordModel();

            var customerAccountService = MockRepository.GenerateStub<ICustomerAccountService>();
            customerAccountService.Stub(x => x.ChangePassword(
                Arg<string>.Is.Equal(model.Email),
                Arg<string>.Is.Equal(model.OldPassword),
                Arg<string>.Is.Equal(model.NewPassword)
            )).Repeat.Once().Throw(new Exception("exception"));

            //Act
            var controller = CreateDefaultMyAccountControllerWithCustomCustomerAccountService(customerAccountService);
            //Assert
            var json = controller.ChangePassword(model) as JsonResult;

            var jsonResult = json.Data as OporationWithoutReturnValueJsonModel;

            jsonResult.HasError.Should().Be(true);
        }