コード例 #1
0
        public void CanGenerateAStringRepresentationOfACsvFileWithNoRows(string headers)
        {
            var definition = CsvDefinitionProvider.Get(headers.Split(','));
            var result     = definition.GenerateString();

            Assert.Equal($"{headers}\r\n", result);
        }
コード例 #2
0
        public void CanGenerateACsvDefinitionWhereCommasAreEscaped(string headers, string rows)
        {
            var definition = CsvDefinitionProvider.Get(headers.Split(','),
                                                       rows.Split('|').Select(row => SplitWithEscape(row, ',', '"')).ToArray());
            var testInput = definition.GenerateString();

            var result = CsvGenerator.FromString(testInput);

            Assert.Equal(definition.Headers.Count, result.Headers.Count);
            Assert.Equal(definition.Rows.Count, result.Rows.Count);

            foreach (var header in definition.Headers)
            {
                Assert.Contains(header, result.Headers);
            }

            for (var i = 0; i < definition.Rows.Count; i++)
            {
                var definitionRow = definition.Rows[i];
                var resultRow     = result.Rows[i];
                for (var ci = 0; ci < definitionRow.Count; ci++)
                {
                    Assert.Equal(definitionRow[ci].ToString(), resultRow[ci].ToString());
                }
            }
        }
コード例 #3
0
        public void CanGenerateAStringRepresentationOfACsvFile(string headers, string rows)
        {
            var definition = CsvDefinitionProvider.Get(headers.Split(','),
                                                       rows.Split('|').Select(row => row.Split(',')).ToArray());
            var result = definition.GenerateString();

            Assert.Equal($"{headers}\r\n{rows.Replace("|","\r\n")}\r\n", result);
        }
コード例 #4
0
ファイル: CsvRowTests.cs プロジェクト: ministryotech/csv
        public void HeaderDeterminationIsCaseInsensitive(string headers, string rows)
        {
            var headersArray = headers.Split(',');
            var definition   = CsvDefinitionProvider.Get(headersArray,
                                                         rows.Split('|').Select(row => row.Split(',')).ToArray());
            var testInput = definition.GenerateString();

            var result  = CsvGenerator.FromString(testInput);
            var testRow = result.Rows.First();

            foreach (var header in headersArray)
            {
                var cell = testRow.Cell(header);
                Assert.True(cell != null, "The header was not found at all.");
                cell = testRow.Cell(header.ToLower());
                Assert.True(cell != null, "The header does not match when lower cased.");
                cell = testRow.Cell(header.ToUpper());
                Assert.True(cell != null, "The header does not match when upper cased.");
            }
        }