public static void Test_generation_of_random_records( )
        {
            var records      = PreferencesHelpers.GenerateRandomRecords(10, new Random( ), 7);
            var asDictionary = records.ToDictionary(r => r.ToString( ), r => r);

            Assert.Equal(10, asDictionary.Count);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Initializes static members of the <see cref="RecordsApiModel" /> class.
        /// </summary>
        /// <autogeneratedoc />
        /// TODO Edit XML Comment Template for #ctor
        static RecordsApiModel( )
        {
            CurrentModel = new PreferencesModel( );

            // Add some random records
            var generatedRecords = PreferencesHelpers.GenerateRandomRecords(10, new Random( ), 7);

            CurrentModel.Add(generatedRecords);
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Initializes static members of the <see cref="RecordsModel" /> class.
        /// </summary>
        /// <autogeneratedoc />
        /// TODO Edit XML Comment Template for #ctor
        static RecordsModel( )
        {
            // we are not persisting data for now, otherwise this would use a connection
            CurrentModel = new PreferencesModel( );

            // Add some random records
            var generatedRecords = PreferencesHelpers.GenerateRandomRecords(10, new Random( ), 7);

            CurrentModel.Add(generatedRecords);
        }
Exemplo n.º 4
0
        /// <summary>
        ///     Defines the entry point of the application.
        /// </summary>
        /// <param name="args">The arguments.</param>
        static void Main([NotNull][ItemNotNull] string [] args)
        {
            var programName = Process.GetCurrentProcess( ).ProcessName;

            if (args.Length == 1)
            {
                var fileName = args [0];
                var fileInfo = new FileInfo(fileName);

                if (!fileInfo.Exists)
                {
                    Console.WriteLine($"File '{fileInfo.FullName} does not exist");
                }

                var preferencesModel = new PreferencesModel( );
                PreferencesHelpers.Load(preferencesModel, fileInfo);

                var byGender = preferencesModel.ByGenderLastName( );
                WriteRecords("By gender, then last name ascending", byGender);

                var byBirthDate = preferencesModel.ByBirthDate( );
                WriteRecords("By birth date", byBirthDate);

                var byLastNameDescending = preferencesModel.ByLastNameDescending( );
                WriteRecords("By last name descending", byLastNameDescending);

                var byName = preferencesModel.ByName( );
                WriteRecords("By name", byName);
            }
            else if (args.Length == 2)
            {
                if (!int.TryParse(args [1], out var recordsToGenerate))
                {
                    throw new InvalidOperationException( );
                }
                var fileName = args [0];
                var fileInfo = new FileInfo(fileName);
                var format   = fileInfo.Extension.ToUpperInvariant( );

                if (fileInfo.Exists)
                {
                    Console.WriteLine($"File '{fileInfo.FullName} already exists, you must remove it manually");
                }

                var randomRecords = PreferencesHelpers.GenerateRandomRecords(recordsToGenerate, new Random( ), 7);
                using (var writer = new StreamWriter(fileInfo.FullName, false))
                {
                    var delimiterChar   = PreferencesHelpers.AssociatedDelimiter(fileInfo);
                    var delimiterString = delimiterChar.ToString( );
                    randomRecords.ForEach(r =>
                    {
                        var strings = new []
                        {
                            r.LastName,
                            r.FirstName,
                            r.Gender,
                            r.FavoriteColor,
                            r.DateOfBirth
                        }.ToList( );
                        var line = string.Join(delimiterString, strings);
                        writer.WriteLine(line);
                    });
                }
            }
            else
            {
                WriteUsageInfo( );
            }
        }