public static void Test_that_pipe_is_associated_delimiter_for_pipe_files( )
        {
            var fileInfo = new FileInfo("something.pIpE");
            var actual   = PreferencesHelpers.AssociatedDelimiter(fileInfo);

            Assert.Equal('|', actual);
        }
        public static void Test_that_blank_is_associated_delimiter_for_txt_files( )
        {
            var fileInfo = new FileInfo("something.tXt");
            var actual   = PreferencesHelpers.AssociatedDelimiter(fileInfo);

            Assert.Equal(' ', actual);
        }
        public static void Test_that_comma_is_associated_delimiter_for_csv_files( )
        {
            var fileInfo = new FileInfo("something.csv");
            var actual   = PreferencesHelpers.AssociatedDelimiter(fileInfo);

            Assert.Equal(',', actual);
        }
        public static void Test_that_an_unknown_file_is_associated_with_char_minValue( )
        {
            var fileInfo = new FileInfo("something.bin");
            var actual   = PreferencesHelpers.AssociatedDelimiter(fileInfo);

            Assert.Equal(char.MinValue, actual);
        }
Exemple #5
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( );
            }
        }