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

            account.Id += "DifferentValue";

            Assert.IsFalse(validator.CanRegister(account));
        }
Exemplo 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));
        }
Exemplo n.º 3
0
        public void CanRegister_CanNotRegisterWithAlreadyTakenUsername()
        {
            AccountView account = ObjectFactory.CreateAccountView();

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

            Assert.IsFalse(validator.CanRegister(account));
        }
Exemplo 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);
        }
Exemplo 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);
        }
Exemplo 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();
        }
Exemplo 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);
        }
Exemplo 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);
        }
Exemplo 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);
        }
Exemplo 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>();
        }
Exemplo 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()
            };
        }
Exemplo 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);
        }
Exemplo 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);
        }
Exemplo n.º 15
0
 public void CanDelete_CanDeleteValidAccountView()
 {
     Assert.IsTrue(validator.CanDelete(ObjectFactory.CreateAccountView()));
 }
Exemplo n.º 16
0
 public void CanRegister_CanRegisterValidAccount()
 {
     Assert.IsTrue(validator.CanRegister(ObjectFactory.CreateAccountView("2")));
 }
Exemplo n.º 17
0
        public void CanRegister_CanNotRegisterWithInvalidModelState()
        {
            validator.ModelState.AddModelError("Key", "Error");

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