public void User_Not_Authorized_When_Company__Doesnt_Belong_To_User_Jobsearch()
        {
            // Setup
            var user   = new User();
            var user2  = new User();
            var search = new JobSearch {
                User = user
            };
            var company = new Company {
                JobSearch = search
            };
            var company2 = new Company {
                JobSearch = new JobSearch {
                    User = user2
                }
            };

            _context.Companies.Add(company);
            _context.Users.Add(user2);
            _context.SaveChanges();

            IProcess <CompanyQueryAuthorizationParams, AuthorizationResultViewModel> process = new AuthorizationProcesses(_context);

            // Act
            AuthorizationResultViewModel result = process.Execute(new CompanyQueryAuthorizationParams
            {
                CompanyId        = company.Id,
                RequestingUserId = user2.Id
            });

            // Verify
            Assert.IsNotNull(result, "Result was null");
            Assert.IsFalse(result.UserAuthorized, "User was incorrectly authorized");
        }
Ejemplo n.º 2
0
        public void User_Authorized_When_Position_Belongs_To_User_Jobsearch()
        {
            // Setup
            var user     = new User();
            var position = new Position {
                Company = new Company {
                    JobSearch = new JobSearch {
                        User = user
                    }
                }
            };

            _context.Positions.Add(position);
            _context.SaveChanges();

            IProcess <PositionAuthorizationParams, AuthorizationResultViewModel> process = new AuthorizationProcesses(_context);

            // Act
            AuthorizationResultViewModel result = process.Execute(new PositionAuthorizationParams
            {
                PositionId       = position.Id,
                RequestingUserId = user.Id
            });

            // Verify
            Assert.IsNotNull(result, "Result was null");
            Assert.IsTrue(result.UserAuthorized, "User was not authorized");
        }
        public void User_Not_Authorized_When_Contact_Doesnt_Belong_To_User_Jobsearch()
        {
            // Setup
            var user = new User();
            var user2 = new User();
            var search = new JobSearch { User = user };
            var company = new Company { JobSearch = search };
            var contact = new Contact { Company = company };

            _context.Contacts.Add(contact);
            _context.Users.Add(user2);
            _context.SaveChanges();

            IProcess<ContactAutorizationParams, AuthorizationResultViewModel> process = new AuthorizationProcesses(_context);

            // Act
            AuthorizationResultViewModel result = process.Execute(new ContactAutorizationParams
            {
                ContactId = contact.Id,
                RequestingUserId = user2.Id
            });

            // Verify
            Assert.IsNotNull(result, "Result was null");
            Assert.IsFalse(result.UserAuthorized, "User was incorrectly authorized");
        }
Ejemplo n.º 4
0
        public void User_Authorized_When_Contact_Belongs_To_User_Jobsearch()
        {
            // Setup
            var user   = new User();
            var search = new JobSearch {
                User = user
            };
            var company = new Company {
                JobSearch = search
            };
            var contact = new Contact {
                Company = company
            };

            _context.Contacts.Add(contact);
            _context.SaveChanges();

            IProcess <ContactAutorizationParams, AuthorizationResultViewModel> process = new AuthorizationProcesses(_context);

            // Act
            AuthorizationResultViewModel result = process.Execute(new ContactAutorizationParams
            {
                ContactId        = contact.Id,
                RequestingUserId = user.Id
            });

            // Verify
            Assert.IsNotNull(result, "Result was null");
            Assert.IsTrue(result.UserAuthorized, "User was not authorized");
        }
        public void Authorization_Fails_For_NonExistant_User()
        {
            // Setup
            var user = new User {
                IsSiteAdmin = true
            };

            _context.Users.Add(user);
            _context.SaveChanges();

            IProcess <SiteAdminAuthorizationParams, AuthorizationResultViewModel> process = new AuthorizationProcesses(_context);

            // Act
            var result = process.Execute(new SiteAdminAuthorizationParams {
                UserId = user.Id + 1
            });

            // Verify
            Assert.IsNotNull(result, "Process returned a null result");
            Assert.IsFalse(result.UserAuthorized, "User was incorrectly authorized");
        }
        public void Authorization_Passes_For_Site_Admin()
        {
            // Setup
            var user = new User {
                IsSiteAdmin = true
            };

            _context.Users.Add(user);
            _context.SaveChanges();

            IProcess <SiteAdminAuthorizationParams, AuthorizationResultViewModel> process = new AuthorizationProcesses(_context);

            // Act
            var result = process.Execute(new SiteAdminAuthorizationParams {
                UserId = user.Id
            });

            // Verify
            Assert.IsNotNull(result, "Process returned a null result");
            Assert.IsTrue(result.UserAuthorized, "User was not authorized");
        }
        public void Returns_Unsuccessful_Authorization_When_User_Id_Doesnt_Exist()
        {
            // Setup
            var org  = new Organization();
            var user = new User {
                Organization = org, IsOrganizationAdmin = true
            };

            _context.Users.Add(user);
            _context.SaveChanges();

            IProcess <OrganizationAdminAuthorizationParams, AuthorizationResultViewModel> process = new AuthorizationProcesses(_context);

            // Act
            var result = process.Execute(new OrganizationAdminAuthorizationParams {
                OrganizationId = org.Id, UserId = user.Id + 5
            });

            // Verify
            Assert.IsNotNull(result, "Process returned a null result");
            Assert.IsFalse(result.UserAuthorized, "User was incorrectly authorized");
        }
        public void Returns_Successful_Authorization_When_User_Is_Admin_For_Specified_Organization()
        {
            // Setup
            var org  = new Organization();
            var user = new User {
                Organization = org, IsOrganizationAdmin = true
            };

            _context.Users.Add(user);
            _context.SaveChanges();

            IProcess <OrganizationAdminAuthorizationParams, AuthorizationResultViewModel> process = new AuthorizationProcesses(_context);

            // Act
            var result = process.Execute(new OrganizationAdminAuthorizationParams {
                OrganizationId = org.Id, UserId = user.Id
            });

            // Verify
            Assert.IsNotNull(result, "Process returned a null result");
            Assert.IsTrue(result.UserAuthorized, "User was not authorized");
        }
Ejemplo n.º 9
0
        public void User_Not_Authorized_When_Task__Doesnt_Belong_To_User_Jobsearch()
        {
            // Setup
            var user  = new User();
            var user2 = new User();
            var task  = new Task {
                Company = new Company {
                    JobSearch = new JobSearch {
                        User = user
                    }
                }
            };
            var task2 = new Task {
                Company = new Company {
                    JobSearch = new JobSearch {
                        User = user2
                    }
                }
            };

            _context.Tasks.Add(task);
            _context.Tasks.Add(task2);
            _context.SaveChanges();

            IProcess <TaskAuthorizationParams, AuthorizationResultViewModel> process = new AuthorizationProcesses(_context);

            // Act
            AuthorizationResultViewModel result = process.Execute(new TaskAuthorizationParams
            {
                TaskId           = task.Id,
                RequestingUserId = user2.Id
            });

            // Verify
            Assert.IsNotNull(result, "Result was null");
            Assert.IsFalse(result.UserAuthorized, "User was incorrectly authorized");
        }