public void CanDelete_IncorrectPassword_ReturnsFalse()
        {
            ProfileDeleteView view = ObjectsFactory.CreateProfileDeleteView(account.Id + 1);

            hasher.VerifyPassword(view.Password, Arg.Any <String>()).Returns(false);

            Boolean canDelete = validator.CanDelete(view);

            Assert.False(canDelete);
            Assert.Empty(validator.Alerts);
            Assert.Single(validator.ModelState);
            Assert.Equal(Validation.For <AccountView>("IncorrectPassword"), validator.ModelState["Password"].Errors.Single().ErrorMessage);
        }
Beispiel #2
0
        public void SetUp()
        {
            account       = new AccountView();
            profileEdit   = ObjectFactory.CreateProfileEditView("Edition");
            profileDelete = ObjectFactory.CreateProfileDeleteView("Edition");

            service    = Substitute.For <IAccountService>();
            validator  = Substitute.For <IAccountValidator>();
            controller = Substitute.ForPartsOf <ProfileController>(validator, service);

            controller.When(sub => { String get = sub.CurrentAccountId; }).DoNotCallBase();
            controller.CurrentAccountId.Returns("CurrentAccount");
        }
Beispiel #3
0
        public void CanDelete_AddsErrorMessageThenCanNotDeleteWithIncorrectPassword()
        {
            ProfileDeleteView profile = ObjectFactory.CreateProfileDeleteView();

            hasher.Verify(Arg.Any <String>(), Arg.Any <String>()).Returns(false);
            profile.Password += "1";

            validator.CanDelete(profile);

            String expected = Validations.IncorrectPassword;
            String actual   = validator.ModelState["Password"].Errors[0].ErrorMessage;

            Assert.AreEqual(expected, actual);
        }
Beispiel #4
0
        public ProfileControllerTests()
        {
            validator = Substitute.For <IAccountValidator>();
            service   = Substitute.For <IAccountService>();

            profileDelete = ObjectsFactory.CreateProfileDeleteView();
            profileEdit   = ObjectsFactory.CreateProfileEditView();

            controller = Substitute.ForPartsOf <ProfileController>(validator, service);
            controller.ControllerContext.HttpContext = Substitute.For <HttpContext>();
            controller.TempData = Substitute.For <ITempDataDictionary>();
            controller.ControllerContext.RouteData = new RouteData();
            controller.Url = Substitute.For <IUrlHelper>();
            ReturnCurrentAccountId(controller, 1);
        }
        public ActionResult DeleteConfirmed([BindExcludeId] ProfileDeleteView profile)
        {
            if (!Service.IsActive(CurrentAccountId))
            {
                return(RedirectToAction("Logout", "Auth"));
            }

            if (!Validator.CanDelete(profile))
            {
                Alerts.Add(AlertType.Danger, Messages.ProfileDeleteDisclaimer, 0);

                return(View());
            }

            Service.Delete(CurrentAccountId);

            return(RedirectToAction("Logout", "Auth"));
        }
        public ActionResult DeleteConfirmed([Bind(Exclude = "Id")] ProfileDeleteView profile)
        {
            if (!Service.IsActive(CurrentAccountId))
            {
                return(RedirectIfAuthorized("Logout", "Auth"));
            }

            if (!Validator.CanDelete(profile))
            {
                Alerts.AddWarning(Messages.ProfileDeleteDisclaimer);

                return(View());
            }

            Service.Delete(CurrentAccountId);

            return(RedirectIfAuthorized("Logout", "Auth"));
        }
        public ActionResult DeleteConfirmed([Bind(Exclude = "Id")] ProfileDeleteView profile)
        {
            if (!Service.AccountExists(CurrentAccountId))
            {
                return(LogOut());
            }

            profile.Id = CurrentAccountId;
            if (!Validator.CanDelete(profile))
            {
                Alerts.Add(AlertTypes.Danger, Messages.ProfileDeleteDisclaimer, 0);
                return(View());
            }

            Service.Delete(CurrentAccountId);

            return(LogOut());
        }
Beispiel #8
0
        public ActionResult DeleteConfirmed(ProfileDeleteView profile)
        {
            if (!Service.IsActive(CurrentAccountId))
            {
                return(RedirectToAction("Logout", "Auth"));
            }

            if (!Validator.CanDelete(profile))
            {
                Alerts.AddWarning(Message.For <AccountView>("ProfileDeleteDisclaimer"));

                return(View());
            }

            Service.Delete(CurrentAccountId);

            Authorization?.Refresh();

            return(RedirectToAction("Logout", "Auth"));
        }
Beispiel #9
0
        public ActionResult DeleteConfirmed(ProfileDeleteView profile)
        {
            if (!Service.IsActive(CurrentAccountId))
            {
                return(RedirectToAction(nameof(Auth.Logout), nameof(Auth)));
            }

            if (!Validator.CanDelete(profile))
            {
                Alerts.AddWarning(Message.For <AccountView>("ProfileDeleteDisclaimer"));

                return(View());
            }

            Service.Delete(CurrentAccountId);

            Authorization.Refresh(HttpContext.RequestServices);

            return(RedirectToAction(nameof(Auth.Logout), nameof(Auth)));
        }