Esempio n. 1
0
        public void CanRegister_CanNotRegisterWithAlreadyUsedEmail()
        {
            AccountView account = ObjectFactory.CreateAccountView();

            account.Id += "DifferentValue";

            Assert.IsFalse(validator.CanRegister(account));
        }
Esempio n. 2
0
        public void CanDelete_CanNotDeleteWithIncorrectPassword()
        {
            hasher.Verify(Arg.Any <String>(), Arg.Any <String>()).Returns(false);
            AccountView profile = ObjectFactory.CreateAccountView();

            profile.Password += "1";

            Assert.IsFalse(validator.CanDelete(profile));
        }
Esempio n. 3
0
        public void CanRegister_CanNotRegisterWithAlreadyTakenUsername()
        {
            AccountView account = ObjectFactory.CreateAccountView();

            account.Username = account.Username.ToLower();
            account.Id      += "DifferentValue";

            Assert.IsFalse(validator.CanRegister(account));
        }
Esempio n. 4
0
        public void ToModel_ConvertsViewToModel()
        {
            AccountView view = ObjectFactory.CreateAccountView();

            Account expected = Mapper.Map <AccountView, Account>(view);
            Account actual   = unitOfWork.ToModel <AccountView, Account>(view);

            TestHelper.PropertyWiseEqual(expected, actual);
        }
Esempio n. 5
0
        public void CanRegister_AddsErrorMessageThenCanNotRegisterWithAlreadyUsedEmail()
        {
            AccountView account = ObjectFactory.CreateAccountView();

            account.Id += "DifferentValue";
            validator.CanRegister(account);

            String actual   = validator.ModelState["Email"].Errors[0].ErrorMessage;
            String expected = Validations.EmailIsAlreadyUsed;

            Assert.AreEqual(expected, actual);
        }
Esempio n. 6
0
        public AccountsControllerTests()
        {
            validator = Substitute.For <IAccountValidator>();
            service   = Substitute.For <IAccountService>();

            accountCreate = ObjectFactory.CreateAccountCreateView();
            accountEdit   = ObjectFactory.CreateAccountEditView();
            account       = ObjectFactory.CreateAccountView();

            controller = Substitute.ForPartsOf <AccountsController>(validator, service);
            controller.ActionContext.RouteData = new RouteData();
        }
Esempio n. 7
0
        public void CanDelete_AddsErrorMessageThenCanNotDeleteWithIncorrectPassword()
        {
            hasher.Verify(Arg.Any <String>(), Arg.Any <String>()).Returns(false);
            AccountView profile = ObjectFactory.CreateAccountView();

            profile.Password += "1";
            validator.CanDelete(profile);

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

            Assert.AreEqual(expected, actual);
        }
Esempio n. 8
0
        public void MapAccounts_MapsAccountViewToAccount()
        {
            AccountView expected = ObjectFactory.CreateAccountView();
            Account     actual   = Mapper.Map <AccountView, Account>(expected);

            Assert.AreEqual(expected.EntityDate, actual.EntityDate);
            Assert.AreEqual(expected.Username, actual.Username);
            Assert.AreEqual(expected.RoleId, actual.RoleId);
            Assert.AreEqual(expected.Email, actual.Email);
            Assert.AreEqual(expected.Id, actual.Id);
            Assert.IsNull(actual.Passhash);
            Assert.IsNull(actual.Role);
        }
Esempio n. 9
0
        public void CanRegister_AddsErorrMessageThenCanNotRegisterWithAlreadyTakenUsername()
        {
            AccountView account = ObjectFactory.CreateAccountView();

            account.Username = account.Username.ToLower();
            account.Id      += "DifferentValue";
            validator.CanRegister(account);

            String actual   = validator.ModelState["Username"].Errors[0].ErrorMessage;
            String expected = Validations.UsernameIsAlreadyTaken;

            Assert.AreEqual(expected, actual);
        }
Esempio n. 10
0
        public void Register_LowersEmailValue()
        {
            AccountView view     = ObjectFactory.CreateAccountView(2);
            String      expected = view.Email.ToLower();

            view.Email = view.Email.ToUpper();

            service.Register(view);

            Account model = context.Set <Account>().SingleOrDefault(account => account.Id == view.Id);

            Assert.AreEqual(expected, model.Email);
            Assert.AreEqual(expected, view.Email);
        }
        public AccountsControllerTests()
        {
            validator = Substitute.For <IAccountValidator>();
            service   = Substitute.For <IAccountService>();

            accountCreate = ObjectFactory.CreateAccountCreateView();
            accountEdit   = ObjectFactory.CreateAccountEditView();
            account       = ObjectFactory.CreateAccountView();

            controller = Substitute.ForPartsOf <AccountsController>(validator, service);
            controller.ControllerContext.HttpContext = Substitute.For <HttpContext>();
            controller.TempData = Substitute.For <ITempDataDictionary>();
            controller.ControllerContext.RouteData = new RouteData();
            controller.Url = Substitute.For <IUrlHelper>();
        }
Esempio n. 12
0
        public AccountsControllerTests()
        {
            validator = Substitute.For <IAccountValidator>();
            service   = Substitute.For <IAccountService>();

            accountCreate = ObjectFactory.CreateAccountCreateView();
            accountEdit   = ObjectFactory.CreateAccountEditView();
            account       = ObjectFactory.CreateAccountView();

            Authorization.Provider       = Substitute.For <IAuthorizationProvider>();
            controller                   = Substitute.ForPartsOf <AccountsController>(validator, service);
            controller.ControllerContext = new ControllerContext {
                RouteData = new RouteData()
            };
        }
Esempio n. 13
0
        public void Register_CreatesAccount()
        {
            AccountView expected = ObjectFactory.CreateAccountView(2);

            service.Register(expected);

            Account actual = context.Set <Account>().SingleOrDefault(model => model.Id == expected.Id);

            Assert.AreEqual(hasher.HashPassword(expected.Password), actual.Passhash);
            Assert.AreEqual(expected.EntityDate, actual.EntityDate);
            Assert.AreEqual(expected.Username, actual.Username);
            Assert.IsNull(actual.RecoveryTokenExpirationDate);
            Assert.AreEqual(expected.Email, actual.Email);
            Assert.AreEqual(expected.Id, actual.Id);
            Assert.IsNull(actual.RecoveryToken);
            Assert.IsNull(actual.RoleId);
        }
Esempio n. 14
0
        public void Register_CreatesAccount()
        {
            AccountView account = ObjectFactory.CreateAccountView("2");

            service.Register(account);

            Account     actual   = context.Set <Account>().AsNoTracking().Single(model => model.Id == account.Id);
            AccountView expected = account;

            Assert.AreEqual(hasher.HashPassword(expected.Password), actual.Passhash);
            Assert.AreEqual(expected.CreationDate, actual.CreationDate);
            Assert.AreEqual(expected.Username, actual.Username);
            Assert.IsNull(actual.RecoveryTokenExpirationDate);
            Assert.AreEqual(expected.Email, actual.Email);
            Assert.AreEqual(expected.Id, actual.Id);
            Assert.IsNull(actual.RecoveryToken);
            Assert.IsNull(actual.RoleId);
            Assert.IsNull(actual.Role);
        }
Esempio n. 15
0
 public void CanDelete_CanDeleteValidAccountView()
 {
     Assert.IsTrue(validator.CanDelete(ObjectFactory.CreateAccountView()));
 }
Esempio n. 16
0
 public void CanRegister_CanRegisterValidAccount()
 {
     Assert.IsTrue(validator.CanRegister(ObjectFactory.CreateAccountView("2")));
 }
Esempio n. 17
0
        public void CanRegister_CanNotRegisterWithInvalidModelState()
        {
            validator.ModelState.AddModelError("Key", "Error");

            Assert.IsFalse(validator.CanRegister(ObjectFactory.CreateAccountView()));
        }