Пример #1
0
        public async Task <IEnumerable <Person> > SearchPeople(int quantity, Province?province = null, AutonomousCommunity?region = null, Gender gender = null)
        {
            quantity.EnsureQuantityIsInValidRange();

            var names    = (await nameSearcher.Search(quantity, gender)).ToList();
            var surnames = (await surnameSearcher.Search(quantity * 2)).ToList();
            var places   = (await placeSearcher.Search(quantity, province, region)).ToList();

            var people = new List <Person>();

            foreach (var _ in Enumerable.Range(0, quantity))
            {
                var firstName = names.RandomElement(randomProvider);
                names.Remove(firstName);

                var middleName = surnames.RandomElement(randomProvider);
                surnames.Remove(middleName);

                var lastName = surnames.RandomElement(randomProvider);
                surnames.Remove(lastName);

                var place = places.RandomElement(randomProvider);
                places.Remove(place);

                var birthDate = dateProvider.GetRandomBirthDate(randomProvider);

                var idCardNumber = new IdCard(randomProvider).ToString();

                people.Add(new Person(firstName, middleName, lastName, gender ?? firstName.Gender,
                                      place, birthDate, idCardNumber));
            }
            return(people);
        }