/// <summary> /// Executes a Read and tests whether it outputs the expected records. /// </summary> /// <typeparam name="T"> /// Type of the output elements. /// </typeparam> /// <param name="testInput"> /// String representing the contents of the file or StreamReader. This string is fed to the Read method /// as though it came from a file or StreamReader. /// </param> /// <param name="fileDescription"> /// Passed to Read. /// </param> /// <param name="expected"> /// Expected output. /// </param> public void AssertRead <T>(string filePath, string sheetName, ExcelFileDescription fileDescription, IEnumerable <T> expected) where T : class, IAssertable <T>, new() { IEnumerable <T> actual = TestRead <T>(filePath, sheetName, fileDescription); AssertCollectionsEqual <T>(actual, expected); }
public void GoodFileCommaDelimitedNamesInFirstLineNLnl() { // Arrange List <ProductData> dataRows_Test = new List <ProductData>(); dataRows_Test.Add(new ProductData { retailPrice = 4.59M, name = "Wooden toy", startDate = new DateTime(2008, 2, 1), nbrAvailable = 67 }); dataRows_Test.Add(new ProductData { onsale = true, weight = 4.03, shopsAvailable = "Ashfield", description = "" }); dataRows_Test.Add(new ProductData { name = "Metal box", launchTime = new DateTime(2009, 11, 5, 4, 50, 0), description = "Great\nproduct" }); ExcelFileDescription fileDescription_namesNl2 = new ExcelFileDescription { FirstLineHasColumnNames = true, EnforceCsvColumnAttribute = false, TextEncoding = Encoding.Unicode, FileCultureName = "nl-Nl" // default is the current culture }; string filePath = @"TestData\GoodFileCommaDelimitedNamesInFirstLineNLnl.xlsx"; string sheetName = "Sheet1"; // Act and Assert AssertWrite(dataRows_Test, filePath, sheetName, fileDescription_namesNl2); }
public void GoodFileNoSeparatorCharUseOutputFormatForParsingUSEnglish() { // Arrange ExcelFileDescription fileDescription_namesUs = new ExcelFileDescription { UseOutputFormatForParsingCsvValue = true, FirstLineHasColumnNames = false, EnforceCsvColumnAttribute = true, // default is false FileCultureName = "en-US" // default is the current culture }; var expected = new[] { new ProductDataCharLength() { name = "AAAAAAAA", weight = 34.184, startDate = new DateTime(2008, 5, 23), }, new ProductDataCharLength { name = "BBBBBBBB", weight = 10.311, startDate = new DateTime(2012, 5, 12), }, new ProductDataCharLength { name = "CCCCCCCC", weight = 12.000, startDate = new DateTime(2008, 12, 23), } }; string filePath = @"TestData\GoodFileNoSeparatorCharUseOutputFormatForParsingUSEnglish.xlsx"; String sheetName = "Sheet1"; // Act and Assert AssertRead(filePath, sheetName, fileDescription_namesUs, expected); }
public void GoodFileCommaDelimitedUseFieldIndexForReadingDataCharUSEnglish() { // Arrange ExcelFileDescription fileDescription_namesUs = new ExcelFileDescription { IgnoreUnknownColumns = true, UseFieldIndexForReadingData = true, FirstLineHasColumnNames = false, EnforceCsvColumnAttribute = true, // default is false FileCultureName = "en-US" // default is the current culture }; var expected = new[] { new ProductDataSpecificFieldIndex() { name = "AAAAAAAA", weight = 34.184, startDate = new DateTime(2008, 5, 23), }, new ProductDataSpecificFieldIndex { name = "BBBBBBBB", weight = 10.311, startDate = new DateTime(2012, 5, 12), }, new ProductDataSpecificFieldIndex { name = "CCCCCCCC", weight = 12.000, startDate = new DateTime(2008, 12, 23), } }; string filePath = @"TestData\GoodFileCommaDelimitedUseFieldIndexForReadingDataCharUSEnglish.xlsx"; String sheetName = "Sheet1"; // Act and Assert try { AssertRead(filePath, sheetName, fileDescription_namesUs, expected); } catch (Exception ex) { throw; } }
/// <summary> /// Used to test the Write method /// </summary> /// <typeparam name="T"> /// The type of the input elements. /// </typeparam> /// <param name="values"> /// The collection of input elements. /// </param> /// <param name="fileDescription"> /// Passed directly to write. /// </param> /// <returns> /// Returns a string with the content that the Write method writes to a file or TextWriter. /// </returns> public void TestWrite <T>(IEnumerable <T> values, string filePath, string sheetName, ExcelFileDescription fileDescription) where T : class { ExcelContext cc = new ExcelContext(); cc.Write(values, filePath, sheetName, fileDescription); }
/// <summary> /// Used to test the Read method. /// </summary> /// <typeparam name="T"> /// Type of the output elements. /// </typeparam> /// <param name="testInput"> /// String representing the contents of the file or StreamReader. This string is fed to the Read method /// as though it came from a file or StreamReader. /// </param> /// <param name="fileDescription"> /// Passed to Read. /// </param> /// <returns> /// Output of Read. /// </returns> public IEnumerable <T> TestRead <T>(string filePath, string sheetName, ExcelFileDescription fileDescription) where T : class, new() { ExcelContext cc = new ExcelContext(); return(cc.Read <T>(filePath, sheetName, fileDescription)); }
/// <summary> /// Executes a Write and tests whether it outputs the expected records. /// </summary> /// <typeparam name="T"> /// The type of the input elements. /// </typeparam> /// <param name="values"> /// The collection of input elements. /// </param> /// <param name="fileDescription"> /// Passed directly to write. /// </param> /// <param name="expected"> /// Expected output. /// </param> public void AssertWrite <T>(IEnumerable <T> values, string filePath, string sheetName, ExcelFileDescription fileDescription) where T : class { TestWrite <T>(values, filePath, sheetName, fileDescription); }