public void TestDeletePeoplePostWhenOnlyOneRoleAvailable2()
        {
            #region Arrange
            SetupDataForPeopleList();
            #endregion Arrange

            #region Act
            var result = Controller.DeletePeople(3, 18, Role.Codes.AccountManager, new WorkgroupPermission(), null)
                         .AssertActionRedirect()
                         .ToAction <WorkgroupController>(a => a.People(3, Role.Codes.AccountManager));
            #endregion Act

            #region Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.RouteValues["id"]);
            Assert.AreEqual(Role.Codes.AccountManager, result.RouteValues["roleFilter"]);

            Assert.AreEqual("Person successfully removed from role.", Controller.Message);

            WorkgroupPermissionRepository.AssertWasCalled(a => a.Remove(Arg <WorkgroupPermission> .Is.Anything));
            var args = (WorkgroupPermission)WorkgroupPermissionRepository.GetArgumentsForCallsMadeOn(a => a.Remove(Arg <WorkgroupPermission> .Is.Anything))[0][0];
            Assert.IsNotNull(args);
            Assert.AreEqual(18, args.Id);

            WorkgroupService.AssertWasCalled(a => a.RemoveFromCache(WorkgroupPermissionRepository.Queryable.Single(b => b.Id == 18)));
            #endregion Assert
        }
        public void TestDeletePeoplePostWhenMultipleRolesAvailable3()
        {
            #region Arrange
            SetupDataForPeopleList();
            var rolesToRemove = new string[1];
            rolesToRemove[0] = Role.Codes.Purchaser;
            #endregion Arrange

            #region Act
            var result = Controller.DeletePeople(3, 21, Role.Codes.Purchaser, new WorkgroupPermission(), rolesToRemove)
                         .AssertActionRedirect()
                         .ToAction <WorkgroupController>(a => a.People(3, Role.Codes.Purchaser));
            #endregion Act

            #region Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.RouteValues["id"]);
            Assert.AreEqual(Role.Codes.Purchaser, result.RouteValues["roleFilter"]);

            WorkgroupPermissionRepository.AssertWasCalled(a => a.Remove(Arg <WorkgroupPermission> .Is.Anything));
            var args = (WorkgroupPermission)WorkgroupPermissionRepository.GetArgumentsForCallsMadeOn(a => a.Remove(Arg <WorkgroupPermission> .Is.Anything))[0][0];
            Assert.IsNotNull(args);
            Assert.AreEqual(21, args.Id);
            Assert.AreEqual("1 role removed from FirstName3 LastName3", Controller.Message);

            WorkgroupService.AssertWasCalled(a => a.RemoveFromCache(WorkgroupPermissionRepository.Queryable.Single(b => b.Id == 21)));
            #endregion Assert
        }
コード例 #3
0
        public void TestCreateWorkgroupPostRedirectsWhenValid()
        {
            #region Arrange
            Controller.ControllerContext.HttpContext = new MockHttpContext(0, new[] { "" }, "3");
            SetupDataForWorkgroupActions1();
            new FakeOrganizationDescendants(3, OrganizationDescendantRepository);
            var workgroup = CreateValidEntities.Workgroup(1);
            workgroup.PrimaryOrganization = OrganizationRepository.Queryable.Single(a => a.Id == "7");
            workgroup.SetIdTo(99);
            WorkgroupService.Expect(a => a.CreateWorkgroup(workgroup, null)).Return(workgroup).Repeat.Any();
            SecurityService.Expect(a => a.HasWorkgroupOrOrganizationAccess(Arg <Workgroup> .Is.Anything, Arg <Organization> .Is.Anything, out Arg <string> .Out(null).Dummy)).Return(true);
            #endregion Arrange

            #region Act
            var result = Controller.CreateWorkgroup(workgroup)
                         .AssertActionRedirect()
                         .ToAction <WizardController>(a => a.AddSubOrganizations(99));
            #endregion Act

            #region Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(99, result.RouteValues["id"]);
            Assert.AreEqual(1, Controller.ViewBag.StepNumber);

            WorkgroupService.AssertWasCalled(a => a.CreateWorkgroup(Arg <Workgroup> .Is.Anything, Arg <string[]> .Is.Anything));
            var args = WorkgroupService.GetArgumentsForCallsMadeOn(a => a.CreateWorkgroup(Arg <Workgroup> .Is.Anything, Arg <string[]> .Is.Anything))[0];
            Assert.AreEqual("Name1", ((Workgroup)args[0]).Name);
            Assert.IsNull(args[1]);
            Assert.AreEqual("Name1 workgroup was created", Controller.Message);
            #endregion Assert
        }
コード例 #4
0
        public void TestGetChildWorkgroupIdsReturnsJsonNetResult6()
        {
            #region Arrange
            var workgroups = new List <Workgroup>();
            for (int i = 0; i < 5; i++)
            {
                workgroups.Add(CreateValidEntities.Workgroup(i + 1));
                workgroups[i].IsActive       = true;
                workgroups[i].Administrative = true;
            }

            workgroups[1].Administrative = false;
            workgroups[2].IsActive       = false;
            workgroups[3].Administrative = false;
            workgroups[3].IsActive       = false;

            new FakeWorkgroups(0, RepositoryFactory.WorkgroupRepository, workgroups);
            WorkgroupService.Expect(a => a.GetChildWorkgroups(5)).Return(new List <int>()).Repeat.Any();
            #endregion Arrange

            #region Act
            var result = Controller.GetChildWorkgroupIds(5)
                         .AssertResultIs <JsonNetResult>();
            #endregion Act

            #region Assert
            dynamic data = JObject.FromObject(result.Data);
            Assert.IsTrue(data.success.Value);
            Assert.AreEqual("None", data.message.Value);
            WorkgroupService.AssertWasCalled(a => a.GetChildWorkgroups(5));
            #endregion Assert
        }
コード例 #5
0
        public void TestProcessWorkGroupReturnsJsonNetResult5()
        {
            #region Arrange
            var workgroups = new List <Workgroup>();
            for (int i = 0; i < 5; i++)
            {
                workgroups.Add(CreateValidEntities.Workgroup(i + 1));
                workgroups[i].IsActive       = true;
                workgroups[i].Administrative = true;
            }

            workgroups[1].Administrative = false;
            workgroups[2].IsActive       = false;
            workgroups[3].Administrative = false;
            workgroups[3].IsActive       = false;

            new FakeWorkgroups(0, RepositoryFactory.WorkgroupRepository, workgroups);
            #endregion Arrange

            #region Act
            var result = Controller.ProcessWorkGroup(5)
                         .AssertResultIs <JsonNetResult>();
            #endregion Act

            #region Assert
            dynamic data = JObject.FromObject(result.Data);
            Assert.IsTrue(data.success.Value);
            Assert.AreEqual("Updated", data.message.Value);
            WorkgroupService.AssertWasCalled(a => a.AddRelatedAdminUsers(RepositoryFactory.WorkgroupRepository.Queryable.Single(b => b.Id == 5)));
            #endregion Assert
        }
コード例 #6
0
        public void TestAddPeoplePostRedirectsToPeople1()
        {
            #region Arrange
            SetupDataForPeopleList();
            string message   = "Fake Message";
            int    failCount = 2;
            SecurityService.Expect(a => a.HasWorkgroupOrOrganizationAccess(Arg <Workgroup> .Is.Anything, Arg <Organization> .Is.Anything, out Arg <string> .Out(message).Dummy)).Return(true);
            WorkgroupService.Expect(a => a.TryToAddPeople(
                                        Arg <int> .Is.Anything,
                                        Arg <Role> .Is.Anything,
                                        Arg <Workgroup> .Is.Anything,
                                        Arg <int> .Is.Anything,
                                        Arg <string> .Is.Anything,
                                        ref Arg <int> .Ref(Is.Anything(), failCount).Dummy,
                                        ref Arg <int> .Ref(Is.Anything(), failCount).Dummy,
                                        Arg <List <KeyValuePair <string, string> > > .Is.Anything)).Return(7).Repeat.Any();

            var ldapUser = new DirectoryUser();
            ldapUser.FirstName    = "Me";
            ldapUser.LastName     = "You";
            ldapUser.LoginId      = "Logger";
            ldapUser.EmailAddress = "*****@*****.**";
            SearchService.Expect(a => a.FindUser("Me")).Return(ldapUser);
            var postModel = new WorkgroupPeoplePostModel();
            postModel.Role  = RoleRepository.GetNullableById(Role.Codes.AccountManager);
            postModel.Users = new List <string>();
            postModel.Users.Add("1");
            postModel.Users.Add("Me");
            postModel.Users.Add("2");
            postModel.Users.Add("3");
            #endregion Arrange

            #region Act
            var result = Controller.AddPeople(3, postModel, null)
                         .AssertActionRedirect()
                         .ToAction <WorkgroupController>(a => a.People(3, null));
            #endregion Act

            #region Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.RouteValues["id"]);
            Assert.AreEqual(Role.Codes.AccountManager, result.RouteValues["roleFilter"]);

            WorkgroupService.AssertWasCalled(a => a.TryToAddPeople(
                                                 Arg <int> .Is.Anything,
                                                 Arg <Role> .Is.Anything,
                                                 Arg <Workgroup> .Is.Anything,
                                                 Arg <int> .Is.Anything,
                                                 Arg <string> .Is.Anything,
                                                 ref Arg <int> .Ref(Is.Anything(), failCount).Dummy,
                                                 ref Arg <int> .Ref(Is.Anything(), failCount).Dummy,
                                                 Arg <List <KeyValuePair <string, string> > > .Is.Anything), x => x.Repeat.Times(4));

            var args = WorkgroupService.GetArgumentsForCallsMadeOn(a => a.TryToAddPeople(Arg <int> .Is.Anything,
                                                                                         Arg <Role> .Is.Anything,
                                                                                         Arg <Workgroup> .Is.Anything,
                                                                                         Arg <int> .Is.Anything,
                                                                                         Arg <string> .Is.Anything,
                                                                                         ref Arg <int> .Ref(Is.Anything(), failCount).Dummy,
                                                                                         ref Arg <int> .Ref(Is.Anything(), failCount).Dummy,
                                                                                         Arg <List <KeyValuePair <string, string> > > .Is.Anything));

            Assert.AreEqual(4, args.Count());
            Assert.AreEqual(3, args[0][0]);
            Assert.AreEqual("AM", ((Role)args[0][1]).Id);
            Assert.AreEqual(3, ((Workgroup)args[0][2]).Id);
            Assert.AreEqual(0, args[0][3]);
            Assert.AreEqual(7, args[1][3]);
            Assert.AreEqual("1", args[0][4]);
            Assert.AreEqual("Me", args[1][4]);
            Assert.AreEqual("2", args[2][4]);
            Assert.AreEqual("3", args[3][4]);
            Assert.AreEqual(2, args[0][5]);


            Assert.AreEqual("Successfully added 7 people to workgroup as Account Manager. 2 not added because of duplicated role.", Controller.Message);
            #endregion Assert
        }
コード例 #7
0
        public void TestValidateChildWorkgroupsReturnsView2()
        {
            #region Arrange
            new FakeUsers(4, UserRepository);
            SetupRoles();

            var workgroups = new List <Workgroup>();
            for (int i = 0; i < 3; i++)
            {
                workgroups.Add(CreateValidEntities.Workgroup(i + 1));
                workgroups[i].Administrative = true; //no child workgroups
            }
            workgroups[1].Administrative = false;
            new FakeWorkgroups(0, RepositoryFactory.WorkgroupRepository, workgroups);

            WorkgroupService.Expect(a => a.GetParentWorkgroups(2)).Return(new List <int>()
            {
                1
            }).Repeat.Any();

            var workgroupPermissions = new List <WorkgroupPermission>();
            for (int i = 0; i < 7; i++)
            {
                workgroupPermissions.Add(CreateValidEntities.WorkgroupPermission(i + 1));
            }

            //Parent Permissions
            workgroupPermissions[0].Workgroup = RepositoryFactory.WorkgroupRepository.Queryable.Single(a => a.Id == 1);
            workgroupPermissions[1].Workgroup = RepositoryFactory.WorkgroupRepository.Queryable.Single(a => a.Id == 1);
            workgroupPermissions[2].Workgroup = RepositoryFactory.WorkgroupRepository.Queryable.Single(a => a.Id == 1);

            workgroupPermissions[0].User = UserRepository.Queryable.Single(a => a.Id == "1");
            workgroupPermissions[1].User = UserRepository.Queryable.Single(a => a.Id == "2");
            workgroupPermissions[2].User = UserRepository.Queryable.Single(a => a.Id == "3");

            workgroupPermissions[0].Role = RoleRepository.Queryable.Single(a => a.Id == Role.Codes.Approver);
            workgroupPermissions[1].Role = RoleRepository.Queryable.Single(a => a.Id == Role.Codes.AccountManager);
            workgroupPermissions[2].Role = RoleRepository.Queryable.Single(a => a.Id == Role.Codes.Purchaser);

            //Child Permissions
            workgroupPermissions[3].Workgroup = RepositoryFactory.WorkgroupRepository.Queryable.Single(a => a.Id == 2);
            workgroupPermissions[4].Workgroup = RepositoryFactory.WorkgroupRepository.Queryable.Single(a => a.Id == 2);
            workgroupPermissions[5].Workgroup = RepositoryFactory.WorkgroupRepository.Queryable.Single(a => a.Id == 2);
            workgroupPermissions[6].Workgroup = RepositoryFactory.WorkgroupRepository.Queryable.Single(a => a.Id == 2);

            //Non Admin permission
            workgroupPermissions[3].User = UserRepository.Queryable.Single(a => a.Id == "4");
            workgroupPermissions[3].Role = RoleRepository.Queryable.Single(a => a.Id == Role.Codes.Requester);

            workgroupPermissions[4].User            = UserRepository.Queryable.Single(a => a.Id == "1");
            workgroupPermissions[4].Role            = RoleRepository.Queryable.Single(a => a.Id == Role.Codes.Approver);
            workgroupPermissions[4].ParentWorkgroup = RepositoryFactory.WorkgroupRepository.Queryable.Single(a => a.Id == 1);
            workgroupPermissions[4].IsAdmin         = true;

            workgroupPermissions[5].User            = UserRepository.Queryable.Single(a => a.Id == "3");
            workgroupPermissions[5].Role            = RoleRepository.Queryable.Single(a => a.Id == Role.Codes.Purchaser);
            workgroupPermissions[5].ParentWorkgroup = RepositoryFactory.WorkgroupRepository.Queryable.Single(a => a.Id == 1);
            workgroupPermissions[5].IsAdmin         = true;

            workgroupPermissions[6].User            = UserRepository.Queryable.Single(a => a.Id == "2");
            workgroupPermissions[6].Role            = RoleRepository.Queryable.Single(a => a.Id == Role.Codes.AccountManager);
            workgroupPermissions[6].ParentWorkgroup = RepositoryFactory.WorkgroupRepository.Queryable.Single(a => a.Id == 1);
            workgroupPermissions[6].IsAdmin         = true;

            new FakeWorkgroupPermissions(0, RepositoryFactory.WorkgroupPermissionRepository, workgroupPermissions);
            #endregion Arrange

            #region Act
            var result = Controller.ValidateChildWorkgroups()
                         .AssertViewRendered()
                         .WithViewData <List <ValidateChildWorkgroupsViewModel> >();
            #endregion Act

            #region Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(0, result.Count);
            WorkgroupService.AssertWasCalled(a => a.GetParentWorkgroups(2));
            #endregion Assert
        }