/// <summary>
        /// Private Constructor which enforces use of Instance
        /// </summary>
        private RecordDatabase()
        {
            if (generateRandom)
            {
                var gen = new RecordGenerator();

                for (int i = 0; i < 10; i++)
                {
                    Add(gen.GenerateRandomRecord());
                }
                generateRandom = false;
            }
        }
Beispiel #2
0
        static private String GenerateTestFile()
        {
            try
            {
                var path = Path.Combine(Directory.GetCurrentDirectory(), "TestFile.txt");
                using (var writer = new StreamWriter(path))
                {
                    RecordGenerator generator = new RecordGenerator();
                    for (int i = 0; i < 10; i++)
                    {
                        var record = generator.GenerateRandomRecord();
                        writer.WriteLine($"{record.LastName} | {record.FirstName} | {record.Gender} | {record.FavoriteColor} | {record.DateOfBirth.ToShortDateString()}");
                    }
                }

                return(path);
            }
            catch (Exception ex)
            {
                throw new Exception(
                          "Failed to Generate a test file",
                          ex);
            }
        }