public void TestRemoveDepartmentalReturnsView()
        {
            #region Arrange
            var users = new List <User>();
            users.Add(CreateValidEntities.User(3));
            users[0].Organizations.Add(CreateValidEntities.Organization(2));
            users[0].Organizations.Add(CreateValidEntities.Organization(3));
            users[0].SetIdTo("3");
            new FakeUsers(0, UserRepository, users, true);
            UserIdentity.Expect(a => a.IsUserInRole("3", Role.Codes.DepartmentalAdmin)).Return(true);
            #endregion Arrange

            #region Act

            var results = Controller.RemoveDepartmental("3")
                          .AssertViewRendered()
                          .WithViewData <User>();
            #endregion Act

            #region Assert
            UserIdentity.AssertWasCalled(a => a.IsUserInRole("3", Role.Codes.DepartmentalAdmin));
            Assert.IsNotNull(results);
            Assert.AreEqual("FirstName3", results.FirstName);
            Assert.AreEqual(2, results.Organizations.Count());
            Assert.AreEqual("Name2", results.Organizations[0].Name);
            Assert.AreEqual("Name3", results.Organizations[1].Name);
            #endregion Assert
        }
        public void TestRemoveDepartmentalRole()
        {
            #region Arrange
            var users = new List <User>();
            users.Add(CreateValidEntities.User(1));
            users[0].Roles.Add(CreateValidEntities.Role(1));
            users[0].Roles.Add(CreateValidEntities.Role(2));
            users[0].Roles[0].SetIdTo(Role.Codes.Admin);
            users[0].Roles[1].SetIdTo(Role.Codes.DepartmentalAdmin);
            users[0].Organizations.Add(CreateValidEntities.Organization(1));
            users[0].Organizations.Add(CreateValidEntities.Organization(2));
            new FakeUsers(0, UserRepository, users, false);
            #endregion Arrange

            #region Act
            Controller.RemoveDepartmentalRole("1")
            .AssertActionRedirect()
            .ToAction <AdminController>(a => a.Index());
            #endregion Act

            #region Assert
            UserIdentity.AssertWasCalled(a => a.RemoveUserRoleFromCache(Resources.Role_CacheId, "1"));
            Assert.AreEqual("FirstName1 LastName1 (1) was successfully removed from the departmental admin role", Controller.Message);
            UserRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <User> .Is.Anything));
            var args = (User)UserRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <User> .Is.Anything))[0][0];
            Assert.IsNotNull(args);
            Assert.AreEqual(0, args.Organizations.Count());
            Assert.AreEqual("FirstName1", args.FirstName);
            Assert.AreEqual(1, args.Roles.Count());
            Assert.AreEqual(Role.Codes.Admin, args.Roles[0].Id);
            #endregion Assert
        }
        public void TestRemoveAdminRoleRemovesRole()
        {
            #region Arrange
            //HttpContext.Current = new HttpContext(new HttpRequest(null, "http://test.org", null), new HttpResponse(null));
            var users = new List <User>();
            users.Add(CreateValidEntities.User(3));
            users[0].Roles.Add(new Role(Role.Codes.EmulationUser));
            users[0].Roles.Add(new Role(Role.Codes.Admin));
            users[0].SetIdTo("3");
            new FakeUsers(0, UserRepository, users, true);
            #endregion Arrange

            #region Act
            Controller.RemoveAdminRole("3")
            .AssertActionRedirect()
            .ToAction <AdminController>(a => a.Index());
            #endregion Act

            #region Assert
            Assert.AreEqual("FirstName3 LastName3 (3) was successfully removed from the admin role", Controller.Message);
            UserRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <User> .Is.Anything));
            var args = (User)UserRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <User> .Is.Anything))[0][0];
            Assert.IsNotNull(args);
            Assert.AreEqual("FirstName3", args.FirstName);
            Assert.AreEqual(1, args.Roles.Count());
            Assert.AreEqual(Role.Codes.EmulationUser, args.Roles[0].Id);
            UserIdentity.AssertWasCalled(a => a.RemoveUserRoleFromCache(Resources.Role_CacheId, "3"));
            #endregion Assert
        }
Exemple #4
0
        public void TestApproveWhenExistingUser3()
        {
            #region Arrange
            new FakeDepartmentalAdminRequests(9, DepartmentalAdminRequestRepository);
            var daRequest = new DepartmentalAdminRequestViewModel();
            daRequest.DepartmentalAdminRequest = CreateValidEntities.DepartmentalAdminRequest(9);
            daRequest.DepartmentalAdminRequest.SetIdTo("3");
            daRequest.MergeExistingOrgs = true; //Merge Them
            new FakeOrganizations(10, OrganizationRepository);
            var users = new List <User>();
            users.Add(CreateValidEntities.User(3));
            users[0].SetIdTo("3");
            users[0].Roles.Add(RoleRepository.GetById(Role.Codes.DepartmentalAdmin));
            users[0].Organizations.Add(OrganizationRepository.Queryable.Single(a => a.Id == "1"));
            users[0].Organizations.Add(OrganizationRepository.Queryable.Single(a => a.Id == "2"));
            new FakeUsers(0, UserRepository, users, true);
            #endregion Arrange

            #region Act
            Controller.Approve(daRequest, new List <string> {
                "1", "5"
            }, new List <string> {
                "1", "2"
            })
            .AssertActionRedirect()
            .ToAction <DepartmentalAdminRequestController>(a => a.Index(null));
            #endregion Act

            #region Assert
            Assert.AreEqual("FirstName3 LastName3 (3) Updated Departmental Admin Access", Controller.Message);
            UserRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <User> .Is.Anything));
            var userArgs = (User)UserRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <User> .Is.Anything))[0][0];
            Assert.IsNotNull(userArgs);
            Assert.AreEqual("3", userArgs.Id);
            Assert.AreEqual("FirstName3", userArgs.FirstName);
            Assert.AreEqual("LastName3", userArgs.LastName);
            Assert.AreEqual("*****@*****.**", userArgs.Email);
            Assert.AreEqual(1, userArgs.Roles.Count);
            Assert.AreEqual(Role.Codes.DepartmentalAdmin, userArgs.Roles[0].Id);

            Assert.AreEqual(3, userArgs.Organizations.Count());
            Assert.AreEqual("1", userArgs.Organizations[0].Id);
            Assert.AreEqual("5", userArgs.Organizations[1].Id);
            Assert.AreEqual("2", userArgs.Organizations[2].Id);

            DepartmentalAdminRequestRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <DepartmentalAdminRequest> .Is.Anything));
            var darArgs = (DepartmentalAdminRequest)DepartmentalAdminRequestRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <DepartmentalAdminRequest> .Is.Anything))[0][0];
            Assert.IsNotNull(darArgs);
            Assert.IsTrue(darArgs.Complete);
            UserIdentity.AssertWasCalled(a => a.RemoveUserRoleFromCache(Resources.Role_CacheId, "3"));
            #endregion Assert
        }
        public void TestModifyAdminWhenUserFound1()
        {
            #region Arrange
            //HttpContext.Current = new HttpContext(new HttpRequest(null, "http://test.org", null), new HttpResponse(null));

            var roles = new List <Role>();
            roles.Add(CreateValidEntities.Role(99));
            roles[0].SetIdTo(Role.Codes.DepartmentalAdmin);
            roles.Add(CreateValidEntities.Role(88));
            roles[1].SetIdTo(Role.Codes.Admin);
            roles.Add(CreateValidEntities.Role(77));
            roles[2].SetIdTo(Role.Codes.EmulationUser);
            new FakeRoles(0, RoleRepository, roles, true);

            var users = new List <User>();
            users.Add(CreateValidEntities.User(3));
            users[0].Organizations.Add(CreateValidEntities.Organization(1));
            users[0].Organizations.Add(CreateValidEntities.Organization(2));
            users[0].Roles.Add(RoleRepository.Queryable.Single(a => a.Id == Role.Codes.EmulationUser));
            users[0].SetIdTo("3");

            new FakeUsers(0, UserRepository, users, true);
            var user = CreateValidEntities.User(3);
            #endregion Arrange

            #region Act
            Controller.ModifyAdmin(user)
            .AssertActionRedirect()
            .ToAction <AdminController>(a => a.Index());
            #endregion Act

            #region Assert
            Assert.AreEqual("FirstName3 LastName3 (3) was edited under the administrator role", Controller.Message);
            UserRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <User> .Is.Anything));
            var userArgs = (User)UserRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <User> .Is.Anything))[0][0];
            Assert.IsNotNull(userArgs);
            Assert.AreEqual("FirstName3 LastName3 (3)", userArgs.FullNameAndId);
            Assert.AreEqual(2, userArgs.Roles.Count());
            Assert.AreEqual(Role.Codes.EmulationUser, userArgs.Roles[0].Id);
            Assert.AreEqual(Role.Codes.Admin, userArgs.Roles[1].Id);
            Assert.AreEqual(2, userArgs.Organizations.Count());
            Assert.AreEqual("*****@*****.**", userArgs.Email);
            Assert.IsTrue(userArgs.IsActive);

            EmailPreferencesRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <EmailPreferences> .Is.Anything));
            var epArgs = (EmailPreferences)EmailPreferencesRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <EmailPreferences> .Is.Anything))[0][0];
            Assert.IsNotNull(epArgs);
            Assert.AreEqual("3", epArgs.Id);
            UserIdentity.AssertWasCalled(a => a.RemoveUserRoleFromCache(Resources.Role_CacheId, "3"));
            #endregion Assert
        }
        public void TestRemoveAdminRedirectsWhenUserNotInRole()
        {
            #region Arrange
            new FakeUsers(3, UserRepository);
            UserIdentity.Expect(a => a.IsUserInRole("3", Role.Codes.Admin)).Return(false);
            #endregion Arrange

            #region Act
            Controller.RemoveAdmin("3")
            .AssertActionRedirect()
            .ToAction <AdminController>(a => a.Index());
            #endregion Act

            #region Assert
            Assert.AreEqual("3 is not an admin", Controller.Message);
            UserIdentity.AssertWasCalled(a => a.IsUserInRole("3", Role.Codes.Admin));
            #endregion Assert
        }
        public void TestRemoveAdminRedirectsWhenUserInRole()
        {
            #region Arrange
            new FakeUsers(3, UserRepository);
            UserIdentity.Expect(a => a.IsUserInRole("3", Role.Codes.Admin)).Return(true);
            #endregion Arrange

            #region Act
            var result = Controller.RemoveAdmin("3")
                         .AssertViewRendered()
                         .WithViewData <User>();
            #endregion Act

            #region Assert
            UserIdentity.AssertWasCalled(a => a.IsUserInRole("3", Role.Codes.Admin));
            Assert.IsNotNull(result);
            Assert.AreEqual("FirstName3 LastName3 (3)", result.FullNameAndId);
            #endregion Assert
        }
Exemple #8
0
        public void TestModifyDepartmentalSetsExpectedValues1()
        {
            #region Arrange
            //HttpContext.Current = new HttpContext(new HttpRequest(null, "http://test.org", null), new HttpResponse(null));
            new FakeUsers(3, UserRepository);
            new FakeOrganizations(6, OrganizationRepository);

            var roles = new List <Role>();
            roles.Add(CreateValidEntities.Role(99));
            roles[0].SetIdTo(Role.Codes.DepartmentalAdmin);
            new FakeRoles(0, RoleRepository, roles, true);

            var depUser = new DepartmentalAdminModel();
            depUser.User = CreateValidEntities.User(4);
            var orgs = new List <string> {
                "2", "4"
            };
            #endregion Arrange

            #region Act
            Controller.ModifyDepartmental(depUser, orgs)
            .AssertActionRedirect()
            .ToAction <AdminController>(a => a.Index());
            #endregion Act

            #region Assert
            UserRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <User> .Is.Anything));
            var args = (User)UserRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <User> .Is.Anything))[0][0];
            Assert.IsNotNull(args);
            Assert.AreEqual("4", args.Id);
            Assert.AreEqual("FirstName4 LastName4", args.FullName);
            Assert.AreEqual("*****@*****.**", args.Email);
            Assert.IsTrue(args.IsActive);
            Assert.AreEqual(1, args.Roles.Count());
            Assert.AreEqual(Role.Codes.DepartmentalAdmin, args.Roles[0].Id);
            Assert.AreEqual(2, args.Organizations.Count());
            Assert.AreEqual("2", args.Organizations[0].Id);
            Assert.AreEqual("4", args.Organizations[1].Id);

            Assert.AreEqual("FirstName4 LastName4 (4) was added as a departmental admin to the specified organization(s)", Controller.Message);
            UserIdentity.AssertWasCalled(a => a.RemoveUserRoleFromCache(Resources.Role_CacheId, "4"));
            #endregion Assert
        }
Exemple #9
0
        public void TestApproveWhenNewUser()
        {
            #region Arrange
            new FakeDepartmentalAdminRequests(9, DepartmentalAdminRequestRepository);
            var daRequest = new DepartmentalAdminRequestViewModel();
            daRequest.DepartmentalAdminRequest = CreateValidEntities.DepartmentalAdminRequest(9);
            daRequest.DepartmentalAdminRequest.SetIdTo("9");
            new FakeUsers(3, UserRepository);
            new FakeOrganizations(10, OrganizationRepository);
            #endregion Arrange

            #region Act
            Controller.Approve(daRequest, new List <string> {
                "1", "5"
            }, null)
            .AssertActionRedirect()
            .ToAction <DepartmentalAdminRequestController>(a => a.Index(null));
            #endregion Act

            #region Assert
            Assert.AreEqual("FirstName9 LastName9 (9) Granted Departmental Admin Access", Controller.Message);
            UserRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <User> .Is.Anything));
            var userArgs = (User)UserRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <User> .Is.Anything))[0][0];
            Assert.IsNotNull(userArgs);
            Assert.AreEqual("9", userArgs.Id);
            Assert.AreEqual("FirstName9", userArgs.FirstName);
            Assert.AreEqual("LastName9", userArgs.LastName);
            Assert.AreEqual("*****@*****.**", userArgs.Email);
            Assert.AreEqual(1, userArgs.Roles.Count);
            Assert.AreEqual(Role.Codes.DepartmentalAdmin, userArgs.Roles[0].Id);

            DepartmentalAdminRequestRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <DepartmentalAdminRequest> .Is.Anything));
            var darArgs = (DepartmentalAdminRequest)DepartmentalAdminRequestRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <DepartmentalAdminRequest> .Is.Anything))[0][0];
            Assert.IsNotNull(darArgs);
            Assert.IsTrue(darArgs.Complete);
            UserIdentity.AssertWasCalled(a => a.RemoveUserRoleFromCache(Resources.Role_CacheId, "9"));
            #endregion Assert
        }