예제 #1
0
        public List <Crate> GetExcelFileDescriptionCrates(byte[] fileAsByteArray, string selectedFilePath, string sheetName = null, bool isRunTime = false)
        {
            var          ext    = Path.GetExtension(selectedFilePath);
            List <Crate> crates = new List <Crate>();

            // Read file from repository
            // Fetch column headers in Excel file
            var headersArray = ExcelUtils.GetColumnHeaders(fileAsByteArray, ext, sheetName);

            var isFirstRowAsColumnNames = true;
            var hasFirstRowHeader       = ExcelUtils.DetectContainsHeader(fileAsByteArray, ext, sheetName);

            // Fetch rows in Excel file
            var rowsDictionary = ExcelUtils.GetTabularData(fileAsByteArray, ext, isFirstRowAsColumnNames, sheetName);

            Crate tableCrate = Crate.FromContent(RunTimeCrateLabel, new StandardTableDataCM(isFirstRowAsColumnNames, new TableRowDTO[0])); // default one

            if (rowsDictionary != null && rowsDictionary.Count > 0)
            {
                var rows = ExcelUtils.CreateTableCellPayloadObjects(rowsDictionary, headersArray, isFirstRowAsColumnNames);
                if (rows != null && rows.Count > 0)
                {
                    tableCrate = Crate.FromContent(RunTimeCrateLabel, new StandardTableDataCM(hasFirstRowHeader, rows));
                    var fieldsCrate = TabularUtilities.PrepareFieldsForOneRowTable(isFirstRowAsColumnNames, rows, headersArray);
                    if (fieldsCrate != null)
                    {
                        crates.Add(fieldsCrate);
                    }
                }
            }
            crates.Add(tableCrate);
            return(crates);
        }
예제 #2
0
        public void OneRowTable_ShouldReturnCrate_When_OneRow_RunTime()
        {
            var crate = TabularUtilities.PrepareFieldsForOneRowTable(false, FixtureData.TestStandardTableData_NoHeader().Table, FixtureData.TestStandardTableData_HeadersOnly());

            Assert.NotNull(crate, "TabularUtilities#PrepareFieldsForOneRowTable should not return null with provided with one-row table");
            Assert.IsInstanceOf <StandardPayloadDataCM>(crate.Get());
            Assert.AreEqual(6, crate.Get <StandardPayloadDataCM>().PayloadObjects[0].PayloadObject.Count);
        }
예제 #3
0
        public void OneRowTable_ShouldReturnNull_When_FirstRowHeaders_MultipleRows()
        {
            var crate = TabularUtilities.PrepareFieldsForOneRowTable(true, FixtureData.TestStandardTableData_TwoRows().Table);

            Assert.Null(crate, "TabularUtilities#PrepareFieldsForOneRowTable should return null with provided with a table containing multiple rows");
        }
예제 #4
0
 public void OneRowTable_ShouldThrow_When_HeadersNotProvided()
 {
     var crate = TabularUtilities.PrepareFieldsForOneRowTable(false, FixtureData.TestStandardTableData_NoHeader().Table, null);
 }