Exemplo n.º 1
0
        private Account CreateAccountWithPrivilegeFor(String area, String controller, String action)
        {
            Account account = ObjectFactory.CreateAccount();
            Role    role    = ObjectFactory.CreateRole();

            account.RoleId = role.Id;

            context.Set <Account>().Add(account);

            role.RolePrivileges = new List <RolePrivilege>();
            RolePrivilege rolePrivilege = ObjectFactory.CreateRolePrivilege();
            Privilege     privilege     = ObjectFactory.CreatePrivilege();

            rolePrivilege.PrivilegeId = privilege.Id;
            rolePrivilege.Privilege   = privilege;
            rolePrivilege.RoleId      = role.Id;
            rolePrivilege.Role        = role;

            privilege.Area       = area;
            privilege.Controller = controller;
            privilege.Action     = action;

            role.RolePrivileges.Add(rolePrivilege);

            context.Set <Role>().Add(role);
            context.SaveChanges();
            provider.Refresh();

            return(account);
        }
Exemplo n.º 2
0
        private void SetUpData()
        {
            account = ObjectFactory.CreateAccount();

            context.Set <Account>().Add(account);
            context.SaveChanges();
        }
        private Account CreateAccountWithPrivilegeFor(String area, String controller, String action, Boolean isLocked = false)
        {
            using (TestingContext context = new TestingContext())
            {
                Account account = ObjectFactory.CreateAccount();
                Role    role    = ObjectFactory.CreateRole();
                account.IsLocked = isLocked;
                account.RoleId   = role.Id;
                account.Role     = role;

                role.RolePrivileges = new List <RolePrivilege>();
                RolePrivilege rolePrivilege = ObjectFactory.CreateRolePrivilege();
                Privilege     privilege     = ObjectFactory.CreatePrivilege();
                rolePrivilege.PrivilegeId = privilege.Id;
                rolePrivilege.Privilege   = privilege;
                rolePrivilege.RoleId      = role.Id;
                rolePrivilege.Role        = role;

                privilege.Controller = controller;
                privilege.Action     = action;
                privilege.Area       = area;

                role.RolePrivileges.Add(rolePrivilege);

                context.Set <Account>().Add(account);
                context.SaveChanges();

                SetUpDependencyResolver();
                provider.Refresh();

                return(account);
            }
        }
Exemplo n.º 4
0
        private void SetUpData()
        {
            Account account = ObjectFactory.CreateAccount();

            role           = ObjectFactory.CreateRole();
            account.RoleId = role.Id;

            context.Set <Account>().Add(account);

            role.RolePrivileges = new List <RolePrivilege>();

            Int32 privilegeNumber            = 1;
            IEnumerable <String> controllers = new[] { "Accounts", "Roles" };
            IEnumerable <String> actions     = new[] { "Index", "Create", "Details", "Edit", "Delete" };

            foreach (String controller in controllers)
            {
                foreach (String action in actions)
                {
                    RolePrivilege rolePrivilege = ObjectFactory.CreateRolePrivilege(privilegeNumber++);
                    rolePrivilege.Privilege = new Privilege {
                        Area = "Administration", Controller = controller, Action = action
                    };
                    rolePrivilege.Privilege.Id = rolePrivilege.Id;
                    rolePrivilege.PrivilegeId  = rolePrivilege.Id;
                    rolePrivilege.RoleId       = role.Id;
                    rolePrivilege.Role         = role;

                    role.RolePrivileges.Add(rolePrivilege);
                }
            }

            context.Set <Role>().Add(role);
            context.SaveChanges();
        }
        private Account CreateAccountWithPermissionFor(String area, String controller, String action, Boolean isLocked = false)
        {
            using (TestingContext context = new TestingContext())
            {
                RolePermission rolePermission = ObjectFactory.CreateRolePermission();
                Account        account        = ObjectFactory.CreateAccount();
                account.RoleId   = rolePermission.RoleId;
                account.IsLocked = isLocked;

                rolePermission.Permission.Controller = controller;
                rolePermission.Permission.Action     = action;
                rolePermission.Permission.Area       = area;

                context.Add(rolePermission.Permission);
                context.Add(rolePermission);
                context.Add(account.Role);
                context.Add(account);

                context.SaveChanges();
            }

            provider.Refresh();

            return(ObjectFactory.CreateAccount());
        }
Exemplo n.º 6
0
        private void SetUpData()
        {
            account          = ObjectFactory.CreateAccount();
            account.RoleId   = account.Role.Id;
            account.IsLocked = false;

            context.Set <Account>().Add(account);
            context.SaveChanges();
        }
Exemplo n.º 7
0
        private void SetUpData()
        {
            Account account = ObjectFactory.CreateAccount();

            account.Role   = ObjectFactory.CreateRole();
            account.RoleId = account.Role.Id;

            context.Set <Account>().Add(account);
            context.SaveChanges();
        }
Exemplo n.º 8
0
        private void SetUpData()
        {
            account = ObjectFactory.CreateAccount();

            using (TestingContext testingContext = new TestingContext())
            {
                testingContext.Set <Account>().Add(account);
                testingContext.SaveChanges();
            }
        }
Exemplo n.º 9
0
        public void RollBack_RollbacksChanges()
        {
            Account model = ObjectFactory.CreateAccount();

            context.Set <Account>().Add(model);

            unitOfWork.Rollback();
            unitOfWork.Commit();

            Assert.IsNull(unitOfWork.Repository <Account>().GetById(model.Id));
        }
Exemplo n.º 10
0
        public void ToView_ConvertsModelToView()
        {
            Account model = ObjectFactory.CreateAccount();

            model.Role   = ObjectFactory.CreateRole();
            model.RoleId = model.Role.Id;

            AccountView actual   = unitOfWork.ToView <Account, AccountView>(model);
            AccountView expected = Mapper.Map <Account, AccountView>(model);

            TestHelper.PropertyWiseEqual(expected, actual);
        }
Exemplo n.º 11
0
        public void MapAccounts_MapsAccountToProfileEditView()
        {
            Account         expected = ObjectFactory.CreateAccount();
            ProfileEditView actual   = Mapper.Map <ProfileEditView>(expected);

            Assert.AreEqual(expected.CreationDate, actual.CreationDate);
            Assert.AreEqual(expected.Username, actual.Username);
            Assert.AreEqual(expected.Email, actual.Email);
            Assert.AreEqual(expected.Id, actual.Id);
            Assert.IsNull(actual.NewPassword);
            Assert.IsNull(actual.Password);
        }
Exemplo n.º 12
0
        public void MapAccounts_MapsAccountToAccountEditView()
        {
            Account         expected = ObjectFactory.CreateAccount();
            AccountEditView actual   = Mapper.Map <AccountEditView>(expected);

            Assert.Equal(expected.CreationDate, actual.CreationDate);
            Assert.Equal(expected.IsLocked, actual.IsLocked);
            Assert.Equal(expected.Username, actual.Username);
            Assert.Equal(expected.RoleId, actual.RoleId);
            Assert.Equal(expected.Email, actual.Email);
            Assert.Equal(expected.Id, actual.Id);
        }
Exemplo n.º 13
0
        public AccountServiceTests()
        {
            context = new TestingContext();
            hasher  = Substitute.For <IHasher>();
            account = ObjectFactory.CreateAccount();
            service = new AccountService(new UnitOfWork(context), hasher);
            hasher.HashPassword(Arg.Any <String>()).Returns(info => info.Arg <String>() + "Hashed");

            context.Add(account);
            context.SaveChanges();

            service.CurrentAccountId = account.Id;
        }
Exemplo n.º 14
0
        public void CanEdit_CanNotEditToAlreadyUsedEmail()
        {
            Account takenEmailAccount = ObjectFactory.CreateAccount(2);

            context.Set <Account>().Add(takenEmailAccount);
            context.SaveChanges();

            ProfileEditView profile = ObjectFactory.CreateProfileEditView();

            profile.Email = takenEmailAccount.Email;

            Assert.IsFalse(validator.CanEdit(profile));
        }
Exemplo n.º 15
0
        public void CanEdit_CanNotEditToAlreadyTakenUsername()
        {
            Account takenAccount = ObjectFactory.CreateAccount(2);

            context.Set <Account>().Add(takenAccount);
            context.SaveChanges();

            ProfileEditView view = ObjectFactory.CreateProfileEditView();

            view.Username = takenAccount.Username;

            Assert.False(validator.CanEdit(view));
        }
Exemplo n.º 16
0
        public void CanEdit_CanNotEditToAlreadyUsedEmail()
        {
            Account usedEmailAccount = ObjectFactory.CreateAccount(2);

            context.Set <Account>().Add(usedEmailAccount);
            context.SaveChanges();

            ProfileEditView view = ObjectFactory.CreateProfileEditView();

            view.Email = usedEmailAccount.Email;

            Assert.False(validator.CanEdit(view));
        }
Exemplo n.º 17
0
        public AccountValidatorTests()
        {
            context   = new TestingContext();
            hasher    = Substitute.For <IHasher>();
            account   = ObjectFactory.CreateAccount();
            validator = new AccountValidator(new UnitOfWork(context), hasher);
            hasher.VerifyPassword(Arg.Any <String>(), Arg.Any <String>()).Returns(true);

            context.Add(account);
            context.SaveChanges();

            validator.CurrentAccountId = account.Id;
        }
Exemplo n.º 18
0
        public void Delete_NullsAccountRoles()
        {
            Account account = ObjectFactory.CreateAccount();

            account.RoleId = role.Id;
            account.Role   = null;

            context.Set <Account>().Add(account);
            context.SaveChanges();

            service.Delete(role.Id);

            Assert.NotEmpty(context.Set <Account>().Where(model => model.Id == account.Id && model.RoleId == null));
        }
Exemplo n.º 19
0
        public void Commit_SavesChanges()
        {
            Account expected = ObjectFactory.CreateAccount(2);

            unitOfWork.Repository <Account>().Insert(expected);
            unitOfWork.Commit();

            Account actual = unitOfWork.Repository <Account>().GetById(expected.Id);

            unitOfWork.Repository <Account>().Delete(expected.Id);
            unitOfWork.Commit();

            TestHelper.PropertyWiseEqual(expected, actual);
        }
Exemplo n.º 20
0
        public void Delete_NullifiesDeletedRoleInAccounts()
        {
            Account account = ObjectFactory.CreateAccount();
            Role    role    = ObjectFactory.CreateRole();

            account.RoleId = role.Id;
            account.Role   = role;

            context.Set <Account>().Add(account);
            context.SaveChanges();

            service.Delete(role.Id);

            Assert.NotEmpty(context.Set <Account>().Where(acc => acc.Id == account.Id && acc.RoleId == null));
        }
Exemplo n.º 21
0
        public void MapAccounts_MapsAccountToAccountEditView()
        {
            Account model = ObjectFactory.CreateAccount();

            model.Role   = ObjectFactory.CreateRole();
            model.RoleId = model.Role.Id;

            AccountEditView actual   = Mapper.Map <AccountEditView>(model);
            Account         expected = model;

            Assert.AreEqual(expected.CreationDate, actual.CreationDate);
            Assert.AreEqual(expected.Role.Name, actual.RoleName);
            Assert.AreEqual(expected.Username, actual.Username);
            Assert.AreEqual(expected.RoleId, actual.RoleId);
            Assert.AreEqual(expected.Id, actual.Id);
        }
Exemplo n.º 22
0
        public void MapAccounts_MapsAccountToAccountView()
        {
            Account model = ObjectFactory.CreateAccount();

            model.Role     = ObjectFactory.CreateRole();
            model.IsLocked = true;

            AccountView actual   = Mapper.Map <AccountView>(model);
            Account     expected = model;

            Assert.Equal(expected.CreationDate, actual.CreationDate);
            Assert.Equal(expected.Role.Title, actual.RoleTitle);
            Assert.Equal(expected.IsLocked, actual.IsLocked);
            Assert.Equal(expected.Username, actual.Username);
            Assert.Equal(expected.Email, actual.Email);
            Assert.Equal(expected.Id, actual.Id);
        }
        public void CanEdit_UsedUsername_ReturnsFalse()
        {
            Account takenAccount = ObjectFactory.CreateAccount(2);

            context.Add(takenAccount);
            context.SaveChanges();

            ProfileEditView view = ObjectFactory.CreateProfileEditView();

            view.Username = takenAccount.Username.ToLower();

            Boolean canEdit = validator.CanEdit(view);

            Assert.False(canEdit);
            Assert.Single(validator.ModelState);
            Assert.Equal(Validations.UniqueUsername, validator.ModelState["Username"].Errors.Single().ErrorMessage);
        }
Exemplo n.º 24
0
        public void CanEdit_AddsErorrMessageThenCanNotEditToAlreadyUsedEmail()
        {
            Account takenEmailAccount = ObjectFactory.CreateAccount(2);

            context.Set <Account>().Add(takenEmailAccount);
            context.SaveChanges();

            ProfileEditView profile = ObjectFactory.CreateProfileEditView();

            profile.Email = takenEmailAccount.Email;
            validator.CanEdit(profile);

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

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 25
0
        public void CanEdit_AddsErrorMessageThenCanNotEditToAlreadyTakenUsername()
        {
            Account takenAccount = ObjectFactory.CreateAccount("2");

            context.Set <Account>().Add(takenAccount);
            context.SaveChanges();

            ProfileEditView profile = ObjectFactory.CreateProfileEditView();

            profile.Username = takenAccount.Username;
            validator.CanEdit(profile);

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

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 26
0
        public void CanEdit_Account_UsedUsername_ReturnsFalse()
        {
            Account usedAccount = ObjectFactory.CreateAccount(1);

            context.Set <Account>().Add(usedAccount);
            context.SaveChanges();

            AccountEditView view = ObjectFactory.CreateAccountEditView(account.Id);

            view.Username = usedAccount.Username.ToLower();

            Boolean canEdit = validator.CanEdit(view);

            Assert.False(canEdit);
            Assert.Single(validator.ModelState);
            Assert.Equal(Validations.UniqueUsername, validator.ModelState["Username"].Errors.Single().ErrorMessage);
        }
Exemplo n.º 27
0
        public void CanEdit_Profile_UsedEmail_ReturnsFalse()
        {
            Account usedAccount = ObjectFactory.CreateAccount(1);

            context.Set <Account>().Add(usedAccount);
            context.SaveChanges();

            ProfileEditView view = ObjectFactory.CreateProfileEditView();

            view.Email = usedAccount.Email;

            Boolean canEdit = validator.CanEdit(view);

            Assert.False(canEdit);
            Assert.Single(validator.ModelState);
            Assert.Equal(Validations.UniqueEmail, validator.ModelState["Email"].Errors.Single().ErrorMessage);
        }
Exemplo n.º 28
0
        public void MapAccounts_MapsAccountToAccountView()
        {
            Account model = ObjectFactory.CreateAccount();

            model.Role   = ObjectFactory.CreateRole();
            model.RoleId = model.Role.Id;

            AccountView actual   = Mapper.Map <Account, AccountView>(model);
            Account     expected = model;

            Assert.AreEqual(expected.EntityDate, actual.EntityDate);
            Assert.AreEqual(expected.Role.Name, actual.RoleName);
            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.Password);
        }
        private Int32 CreateAccountWithPermissionFor(String area, String controller, String action, Boolean isLocked = false)
        {
            using (TestingContext testingContext = new TestingContext(context.DatabaseName))
            {
                RolePermission rolePermission = ObjectFactory.CreateRolePermission();
                Account        account        = ObjectFactory.CreateAccount();
                account.Role.Permissions.Add(rolePermission);
                rolePermission.Role = account.Role;
                account.IsLocked    = isLocked;

                rolePermission.Permission.Controller = controller;
                rolePermission.Permission.Action     = action;
                rolePermission.Permission.Area       = area;

                testingContext.Add(account);
                testingContext.SaveChanges();

                authorization.Refresh();

                return(account.Id);
            }
        }
Exemplo n.º 30
0
        private Int32 CreateAccountWithPermissionFor(String area, String controller, String action, Boolean isLocked = false)
        {
            using (TestingContext context = new TestingContext())
            {
                RolePermission rolePermission = ObjectFactory.CreateRolePermission();
                Account        account        = ObjectFactory.CreateAccount();
                account.RoleId   = rolePermission.RoleId;
                account.IsLocked = isLocked;
                account.Role     = null;

                rolePermission.Permission.Controller = controller;
                rolePermission.Permission.Action     = action;
                rolePermission.Permission.Area       = area;

                context.Set <RolePermission>().Add(rolePermission);
                context.Set <Account>().Add(account);
                context.SaveChanges();

                SetUpDependencyResolver();
                authorization.Refresh();

                return(account.Id);
            }
        }