예제 #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);
        }
예제 #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);
            }
        }
예제 #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());
        }
예제 #6
0
        private void SetUpData()
        {
            account          = ObjectFactory.CreateAccount();
            account.RoleId   = account.Role.Id;
            account.IsLocked = false;

            context.Set <Account>().Add(account);
            context.SaveChanges();
        }
예제 #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();
        }
예제 #8
0
        private void SetUpData()
        {
            account = ObjectFactory.CreateAccount();

            using (TestingContext testingContext = new TestingContext())
            {
                testingContext.Set <Account>().Add(account);
                testingContext.SaveChanges();
            }
        }
예제 #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));
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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;
        }
예제 #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));
        }
예제 #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));
        }
예제 #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));
        }
예제 #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;
        }
예제 #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));
        }
예제 #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);
        }
예제 #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));
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
            }
        }
예제 #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);
            }
        }