Beispiel #1
0
        public void AddingARowWhereTheTotalNumberOfRowsIsGreaterThanTheNumberOfHeadersThrowsAnInvalidOperationException()
        {
            var objUt = new CsvDefinition();

            objUt.AddHeaders("Column 1", "Column 2", "TOTAL");
            Assert.Throws <InvalidOperationException>(() => objUt.AddRow(10, 20, 30, 40));
        }
Beispiel #2
0
        public void CanBuildACsvDefinitionByAddingARowDirectly()
        {
            var objUt = new CsvDefinition();

            objUt.AddHeaders("Column 1", "Column 2", "TOTAL");
            objUt.AddRow(10, 20, 30);
            objUt.AddRow(11, 21, 31);

            Assert.NotEmpty(objUt.Rows);
            Assert.Equal(2, objUt.Rows.Count);

            Assert.Equal(objUt.Headers[0], objUt.Rows[0][0].Header);
            Assert.Equal(objUt.Headers[1], objUt.Rows[0][1].Header);
            Assert.Equal(objUt.Headers[2], objUt.Rows[0][2].Header);
            Assert.Equal(objUt.Headers[0], objUt.Rows[1][0].Header);
            Assert.Equal(objUt.Headers[1], objUt.Rows[1][1].Header);
            Assert.Equal(objUt.Headers[2], objUt.Rows[1][2].Header);
        }
        /// <summary>
        /// Gets the object for the provided data.
        /// </summary>
        public static CsvDefinition Get(string[] headers, params object[][] rows)
        {
            var definition = new CsvDefinition()
                             .AddHeaders(headers);

            foreach (var row in rows)
            {
                definition.AddRow(row);
            }

            return(definition);
        }