jeudi 29 octobre 2020

Unit Test (Fixie) for csv parser

I need to test quantity of headers in csv. I am able to count quantity of headers in csv, but I need to test what will happen when headers names are duplicated. Here is what I have so far:

public static int CountCsvHeaders()
        {
            using (var reader = new System.IO.StreamReader(@"csv file", Encoding.Default))
            {
                Char quotingCharacter = '\0'; // no quoting-character;
                Char escapeCharacter = quotingCharacter;
                Char delimiter = ',';
                int count = 0;
                using (var csv = new CsvReader(reader, true, delimiter, quotingCharacter, escapeCharacter, '\0', ValueTrimmingOptions.All))
                {
                    //while (csv.ReadNextRecord())
                    //{
                    string[] headers = csv.GetFieldHeaders();

                    //}
                    foreach (string head in headers)
                    {
                        //Console.WriteLine(head);
                        count = count + 1;
                    }
                }
                return count;

            }

        }

Aucun commentaire:

Enregistrer un commentaire