Пример #1
0
        public static List <DirectoryUser> GetUsersFromResponse(SearchResponse sResponse)
        {
            var users = new List <DirectoryUser>();

            foreach (SearchResultEntry result in sResponse.Entries)
            {
                var user = new DirectoryUser();

                //Grab out the first response entry

                foreach (DirectoryAttribute attr in result.Attributes.Values)
                {
                    switch (attr.Name)
                    {
                    case STR_UID:
                        user.LoginId = attr[0].ToString();
                        break;

                    case STR_GivenName:
                        user.FirstName = attr[0].ToString();
                        break;

                    case STR_SN:
                        user.LastName = attr[0].ToString();
                        break;

                    case STR_Mail:
                        user.EmailAddress = attr[0].ToString();
                        break;

                    case STR_EmployeeNumber:
                        user.EmployeeId = attr[0].ToString();
                        break;

                    case STR_CN:
                        user.FullName = attr[0].ToString();
                        break;

                    case STR_Telephone:
                        user.PhoneNumber = attr[0].ToString();
                        break;

                    default:
                        break;
                    }
                }

                users.Add(user);
            }

            return(users);
        }
Пример #2
0
        public void TestTryToAddPeopleWhenUserIsFoundWithLdap2()
        {
            #region Arrange
            //HttpContext.Current = new HttpContext(new HttpRequest(null, "http://test.org", null), new HttpResponse(null));
            //new FakeUsers(3, UserRepository);
            UserRepository.Expect(a => a.GetNullableById("LDAP")).Return(null).Repeat.Twice();
            UserRepository.Expect(a => a.GetNullableById("LDAP")).Return(CreateValidEntities.User(3)).Repeat.Once();

            new FakeWorkgroupPermissions(0, WorkgroupPermissionRepository);
            var failCount = 0;
            var dupCount = 0;
            var notAdded = new List<KeyValuePair<string, string>>();
            new FakeRoles(3, RepositoryFactory.RoleRepository);
            new FakeWorkgroups(3, WorkgroupRepository);
            var directoryUser = new DirectoryUser();
            directoryUser.LoginId = "LDAP";
            directoryUser.EmailAddress = "*****@*****.**";
            directoryUser.FirstName = "F3";
            directoryUser.LastName = "Last3";
            SearchService.Expect(a => a.FindUser("LDAP")).Return(directoryUser);
            #endregion Arrange

            #region Act
            var result = WorkgroupService.TryToAddPeople(1, RepositoryFactory.RoleRepository.Queryable.Single(a => a.Id == "2"), new Workgroup(), 0, "LDAP", ref failCount, ref dupCount, notAdded);
            #endregion Act

            #region Assert
            Assert.AreEqual(1, result);
            Assert.AreEqual(0, failCount);
            Assert.AreEqual(0, dupCount);
            Assert.AreEqual(0, notAdded.Count());
            UserRepository.AssertWasCalled(a => a.EnsurePersistent(Arg<User>.Is.Anything));
            EmailPreferencesRepository.AssertWasCalled(a => a.EnsurePersistent(Arg<EmailPreferences>.Is.Anything));
            WorkgroupPermissionRepository.AssertWasCalled(a => a.EnsurePersistent(Arg<WorkgroupPermission>.Is.Anything));
            var args = (WorkgroupPermission)WorkgroupPermissionRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg<WorkgroupPermission>.Is.Anything))[0][0];
            Assert.IsNotNull(args);
            Assert.AreEqual("2", args.Role.Id);
            Assert.AreEqual("3", args.User.Id);
            Assert.AreEqual(1, args.Workgroup.Id);
            #endregion Assert
        }
        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
        }
        public void TestAddPeoplePostReturnsViewWhenInvalid3()
        {
            #region Arrange
            SetupDataForPeopleList();
            var ldapUser = new DirectoryUser();
            ldapUser.FirstName = "Me";
            ldapUser.LastName = "You";
            ldapUser.LoginId = "Logger";
            SearchService.Expect(a => a.FindUser("Me")).Return(ldapUser);
            var postModel = new WorkgroupPeoplePostModel();
            postModel.Role = new Role();
            postModel.Role.SetIdTo(Role.Codes.DepartmentalAdmin);
            postModel.Role.Level = 1;
            postModel.Users = new List<string>();
            postModel.Users.Add("1");
            postModel.Users.Add("Me");
            postModel.Users.Add("2");
            #endregion Arrange

            #region Act
            var result = Controller.AddPeople(3, postModel, null)
                .AssertViewRendered()
                .WithViewData<WorgroupPeopleCreateModel>();

            #endregion Act

            #region Assert
            SearchService.AssertWasCalled(a => a.FindUser("Me"));

            Controller.ModelState.AssertErrorsAre("Invalid Role Selected");
            Assert.IsNotNull(result);
            Assert.AreEqual(Role.Codes.DepartmentalAdmin, result.Role.Id);
            Assert.AreEqual(4, result.Roles.Count());
            Assert.AreEqual(Role.Codes.Requester, result.Roles[0].Id);
            Assert.AreEqual(Role.Codes.Approver, result.Roles[1].Id);
            Assert.AreEqual(Role.Codes.AccountManager, result.Roles[2].Id);
            Assert.AreEqual(Role.Codes.Purchaser, result.Roles[3].Id);
            Assert.AreEqual(3, result.Users.Count());
            Assert.AreEqual("FirstName1 LastName1 (1)", result.Users[0].DisplayNameAndId);
            Assert.AreEqual("Me You (Logger)", result.Users[1].DisplayNameAndId);
            Assert.AreEqual("FirstName2 LastName2 (2)", result.Users[2].DisplayNameAndId);

            Assert.AreEqual("Name3", result.Workgroup.Name);

            #endregion Assert
        }
Пример #5
0
        public static List<DirectoryUser> GetUsersFromResponse(SearchResponse sResponse)
        {
            var users = new List<DirectoryUser>();

            foreach (SearchResultEntry result in sResponse.Entries)
            {
                var user = new DirectoryUser();

                //Grab out the first response entry

                foreach (DirectoryAttribute attr in result.Attributes.Values)
                {
                    switch (attr.Name)
                    {
                        case STR_UID:
                            user.LoginId = attr[0].ToString();
                            break;
                        case STR_GivenName:
                            user.FirstName = attr[0].ToString();
                            break;
                        case STR_SN:
                            user.LastName = attr[0].ToString();
                            break;
                        case STR_Mail:
                            user.EmailAddress = attr[0].ToString();
                            break;
                        case STR_EmployeeNumber:
                            user.EmployeeId = attr[0].ToString();
                            break;
                        case STR_CN:
                            user.FullName = attr[0].ToString();
                            break;
                        case STR_Telephone:
                            user.PhoneNumber = attr[0].ToString();
                            break;
                        default:
                            break;
                    }
                }

                users.Add(user);
            }

            return users;
        }