public void Records(int count, IRepositoryWithTypedId <T, string> repository, List <T> specificRecords, bool bypassSetIdTo)
        {
            var records = new List <T>();
            var specificRecordsCount = 0;

            if (specificRecords != null)
            {
                specificRecordsCount = specificRecords.Count;
                for (int i = 0; i < specificRecordsCount; i++)
                {
                    records.Add(specificRecords[i]);
                }
            }

            for (int i = 0; i < count; i++)
            {
                records.Add(CreateValid(i + specificRecordsCount + 1));
            }

            var totalCount = records.Count;

            for (int i = 0; i < totalCount; i++)
            {
                if (!bypassSetIdTo)
                {
                    var stringId = (i + 1).ToString();
                    records[i].SetIdTo(stringId);
                    repository.Expect(a => a.GetNullableById(stringId))
                    .Return(records[i])
                    .Repeat
                    .Any();
                    repository.Expect(a => a.GetById(stringId))
                    .Return(records[i])
                    .Repeat
                    .Any();
                }
                else
                {
                    var i1 = i;
                    repository.Expect(a => a.GetNullableById(records[i1].Id))
                    .Return(records[i])
                    .Repeat
                    .Any();
                    repository.Expect(a => a.GetById(records[i1].Id))
                    .Return(records[i])
                    .Repeat
                    .Any();
                }
            }
            repository.Expect(a => a.GetNullableById((totalCount + 1).ToString())).Return(null).Repeat.Any();
            repository.Expect(a => a.GetById((totalCount + 1).ToString())).Return(null).Repeat.Any();
            repository.Expect(a => a.Queryable).Return(records.AsQueryable()).Repeat.Any();
            repository.Expect(a => a.GetAll()).Return(records).Repeat.Any();
        }
        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 static void FakeCollege(int count, IRepositoryWithTypedId<College, string> repository, List<College> specificColleges)
        {
            var colleges = new List<College>();
            var specificTransactionsCount = 0;
            if (specificColleges != null)
            {
                specificTransactionsCount = specificColleges.Count;
                for (int i = 0; i < specificTransactionsCount; i++)
                {
                    colleges.Add(specificColleges[i]);
                }
            }

            for (int i = 0; i < count; i++)
            {
                colleges.Add(CreateValidEntities.College(i + specificTransactionsCount + 1));
            }

            var totalCount = colleges.Count;
            for (int i = 0; i < totalCount; i++)
            {
                colleges[i].SetIdTo((i + 1).ToString());
                int i1 = i;
                repository
                    .Expect(a => a.GetNullableById((i1 + 1).ToString()))
                    .Return(colleges[i])
                    .Repeat
                    .Any();
            }
            repository.Expect(a => a.GetNullableById((totalCount + 1).ToString())).Return(null).Repeat.Any();
            repository.Expect(a => a.Queryable).Return(colleges.AsQueryable()).Repeat.Any();
            repository.Expect(a => a.GetAll()).Return(colleges).Repeat.Any();
        }
        /// <summary>
        /// Fakes the student. Note: Using more than 20 will not be reliable
        /// because the Guids will be random
        /// </summary>
        /// <param name="count">The count.</param>
        /// <param name="studentRepository">The student repository.</param>
        /// <param name="specificStudents">The specific students.</param>
        /// <param name="studentRepository2">The student repository2.</param>
        public static void FakeStudent(int count, IRepositoryWithTypedId<Student, Guid> studentRepository, List<Student> specificStudents, IRepository<Student> studentRepository2)
        {
            var students = new List<Student>();
            var specificStudentsCount = 0;
            if (specificStudents != null)
            {
                specificStudentsCount = specificStudents.Count;
                for (int i = 0; i < specificStudentsCount; i++)
                {
                    students.Add(specificStudents[i]);
                }
            }

            for (int i = 0; i < count; i++)
            {
                students.Add(CreateValidEntities.Student(i + specificStudentsCount + 1));
            }

            var totalCount = students.Count;
            for (int i = 0; i < totalCount; i++)
            {
                students[i].SetIdTo(SpecificGuid.GetGuid(i+1));
                int i1 = i;
                studentRepository
                    .Expect(a => a.GetNullableById(students[i1].Id))
                    .Return(students[i])
                    .Repeat
                    .Any();
            }
            studentRepository.Expect(a => a.GetNullableById(SpecificGuid.GetGuid(totalCount + 1))).Return(null).Repeat.Any();
            studentRepository.Expect(a => a.Queryable).Return(students.AsQueryable()).Repeat.Any();
            studentRepository.Expect(a => a.GetAll()).Return(students).Repeat.Any();
            if(studentRepository2 != null)
            {
                studentRepository2.Expect(a => a.Queryable).Return(students.AsQueryable()).Repeat.Any();
                studentRepository2.Expect(a => a.GetAll()).Return(students).Repeat.Any();
            }
        }
        public static void FakeMajors(int count, IRepositoryWithTypedId<MajorCode, string> majorRepository, List<MajorCode> specificMajorCodes)
        {
            var majorCodes = new List<MajorCode>();
            var specificMajorCodesCount = 0;
            if (specificMajorCodes != null)
            {
                specificMajorCodesCount = specificMajorCodes.Count;
                for (int i = 0; i < specificMajorCodesCount; i++)
                {
                    majorCodes.Add(specificMajorCodes[i]);
                }
            }

            for (int i = 0; i < count; i++)
            {
                majorCodes.Add(CreateValidEntities.MajorCode(i + specificMajorCodesCount + 1));
            }

            var totalCount = majorCodes.Count;
            for (int i = 0; i < totalCount; i++)
            {
                majorCodes[i].SetIdTo((i + 1).ToString());
                int i1 = i;
                majorRepository
                    .Expect(a => a.GetNullableById((i1 + 1).ToString()))
                    .Return(majorCodes[i])
                    .Repeat
                    .Any();
            }
            majorRepository.Expect(a => a.GetNullableById((totalCount + 1).ToString())).Return(null).Repeat.Any();
            majorRepository.Expect(a => a.Queryable).Return(majorCodes.AsQueryable()).Repeat.Any();
            majorRepository.Expect(a => a.GetAll()).Return(majorCodes).Repeat.Any();
        }