Пример #1
0
        private static IEnumerable <FileCabinetRecordSerializable> Generate(int startId, int amount)
        {
            var validation = ValidatorBuilder.CreateDefault();
            int id         = 0;

            var random = new Random();

            for (int i = startId; i <= startId + amount; i++)
            {
                var  data = new ValidateParametersData();
                bool isValid;

                do
                {
                    try
                    {
                        id = i;

                        var day   = random.Next(1, 30);
                        var month = random.Next(1, 12);
                        var year  = random.Next(1950, 2020);
                        var date  = new DateTime(year, month, day);

                        data = new ValidateParametersData
                        {
                            FirstName   = RandomString(random.Next(2, 60)),
                            LastName    = RandomString(random.Next(2, 60)),
                            DateOfBirth = date,
                            Bonuses     = Convert.ToInt16(random.Next(0, 30_000)),
                            Salary      = random.Next(3_000, 10_000),
                            AccountType = (char)random.Next('a', 'z'),
                        };

                        validation.ValidateParameters(data);
                        isValid = true;
                    }
                    catch (ArgumentException)
                    {
                        isValid = false;
                    }
                }while (!isValid);

                yield return(new FileCabinetRecordSerializable
                {
                    Id = id,
                    Name = new Name()
                    {
                        FirstName = data.FirstName,
                        LastName = data.LastName
                    },
                    DateOfBirth = data.DateOfBirth,
                    Bonuses = data.Bonuses,
                    Salary = data.Salary,
                    AccountType = data.AccountType,
                });
            }
        }