|
@@ -26,11 +26,11 @@ public class WriterTests
|
|
testFile = Path.ChangeExtension(testFile, "xlsx");
|
|
testFile = Path.ChangeExtension(testFile, "xlsx");
|
|
|
|
|
|
const string worksheetName = "Test";
|
|
const string worksheetName = "Test";
|
|
- var writer = new ExcelWriter(testFile);
|
|
|
|
|
|
+ using var writer = new ExcelWriter(testFile);
|
|
writer.Write(arrayOfThree, worksheetName);
|
|
writer.Write(arrayOfThree, worksheetName);
|
|
writer.SaveAs(testFile);
|
|
writer.SaveAs(testFile);
|
|
|
|
|
|
- var reader = new ExcelReader(testFile);
|
|
|
|
|
|
+ using var reader = new ExcelReader(testFile);
|
|
var readArray = reader.Read<Test>(worksheetName).ToArray();
|
|
var readArray = reader.Read<Test>(worksheetName).ToArray();
|
|
Assert.Equal(3, readArray.Length);
|
|
Assert.Equal(3, readArray.Length);
|
|
|
|
|
|
@@ -40,8 +40,8 @@ public class WriterTests
|
|
writer.Write(listOfTwo, worksheetName, true);
|
|
writer.Write(listOfTwo, worksheetName, true);
|
|
writer.SaveAs(testFile);
|
|
writer.SaveAs(testFile);
|
|
|
|
|
|
- reader = new ExcelReader(testFile);
|
|
|
|
- Assert.Equal(5, reader.Read<Test>(worksheetName).Count());
|
|
|
|
|
|
+ using var newReader = new ExcelReader(testFile);
|
|
|
|
+ Assert.Equal(5, newReader.Read<Test>(worksheetName).Count());
|
|
File.Delete(testFile);
|
|
File.Delete(testFile);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -51,18 +51,18 @@ public class WriterTests
|
|
var testFile = Path.GetRandomFileName();
|
|
var testFile = Path.GetRandomFileName();
|
|
testFile = Path.ChangeExtension(testFile, "xlsx");
|
|
testFile = Path.ChangeExtension(testFile, "xlsx");
|
|
|
|
|
|
- var writer = new ExcelWriter(testFile);
|
|
|
|
|
|
+ using var writer = new ExcelWriter(testFile);
|
|
writer.Write(arrayOfThree);
|
|
writer.Write(arrayOfThree);
|
|
writer.SaveAs(testFile);
|
|
writer.SaveAs(testFile);
|
|
|
|
|
|
- var reader = new ExcelReader(testFile);
|
|
|
|
|
|
+ using var reader = new ExcelReader(testFile);
|
|
Assert.Equal(arrayOfThree.Length, reader.Read<Test>().Count());
|
|
Assert.Equal(arrayOfThree.Length, reader.Read<Test>().Count());
|
|
|
|
|
|
writer.Write(listOfTwo, append: true);
|
|
writer.Write(listOfTwo, append: true);
|
|
writer.SaveAs(testFile);
|
|
writer.SaveAs(testFile);
|
|
|
|
|
|
- reader = new ExcelReader(testFile);
|
|
|
|
- Assert.Equal(5, reader.Read<Test>().Count());
|
|
|
|
|
|
+ using var newReader = new ExcelReader(testFile);
|
|
|
|
+ Assert.Equal(5, newReader.Read<Test>().Count());
|
|
File.Delete(testFile);
|
|
File.Delete(testFile);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -76,11 +76,11 @@ public class WriterTests
|
|
File.Copy(ForAppend, testFile);
|
|
File.Copy(ForAppend, testFile);
|
|
|
|
|
|
uint headerRowIndex = 3;
|
|
uint headerRowIndex = 3;
|
|
- var writer = new ExcelWriter(testFile);
|
|
|
|
|
|
+ using var writer = new ExcelWriter(testFile);
|
|
writer.Write(arrayOfThree, append: true, headerRowIndex: headerRowIndex);
|
|
writer.Write(arrayOfThree, append: true, headerRowIndex: headerRowIndex);
|
|
writer.SaveAs(testFile);
|
|
writer.SaveAs(testFile);
|
|
|
|
|
|
- var reader = new ExcelReader(testFile);
|
|
|
|
|
|
+ using var reader = new ExcelReader(testFile);
|
|
var readArray = reader.Read<Test>(startFrom: headerRowIndex).ToArray();
|
|
var readArray = reader.Read<Test>(startFrom: headerRowIndex).ToArray();
|
|
Assert.Equal(6, readArray.Length);
|
|
Assert.Equal(6, readArray.Length);
|
|
|
|
|
|
@@ -99,11 +99,11 @@ public class WriterTests
|
|
testFile = Path.ChangeExtension(testFile, "xlsx");
|
|
testFile = Path.ChangeExtension(testFile, "xlsx");
|
|
File.Copy(ForAppendHeaderFirst, testFile);
|
|
File.Copy(ForAppendHeaderFirst, testFile);
|
|
|
|
|
|
- var writer = new ExcelWriter(testFile);
|
|
|
|
|
|
+ using var writer = new ExcelWriter(testFile);
|
|
writer.Write(arrayOfThree, append: true);
|
|
writer.Write(arrayOfThree, append: true);
|
|
writer.SaveAs(testFile);
|
|
writer.SaveAs(testFile);
|
|
|
|
|
|
- var reader = new ExcelReader(testFile);
|
|
|
|
|
|
+ using var reader = new ExcelReader(testFile);
|
|
var readArray = reader.Read<Test>().ToArray();
|
|
var readArray = reader.Read<Test>().ToArray();
|
|
Assert.Equal(6, readArray.Length);
|
|
Assert.Equal(6, readArray.Length);
|
|
|
|
|
|
@@ -130,11 +130,11 @@ public class WriterTests
|
|
|
|
|
|
var list = new List<TestTypes>{ expected };
|
|
var list = new List<TestTypes>{ expected };
|
|
|
|
|
|
- var writer = new ExcelWriter(testFile);
|
|
|
|
|
|
+ using var writer = new ExcelWriter(testFile);
|
|
writer.Write(list);
|
|
writer.Write(list);
|
|
writer.SaveAs(testFile);
|
|
writer.SaveAs(testFile);
|
|
|
|
|
|
- var reader = new ExcelReader(testFile);
|
|
|
|
|
|
+ using var reader = new ExcelReader(testFile);
|
|
var result = reader.Read<TestTypes>().ToList();
|
|
var result = reader.Read<TestTypes>().ToList();
|
|
Assert.Single(result);
|
|
Assert.Single(result);
|
|
var first = result.First();
|
|
var first = result.First();
|
|
@@ -161,11 +161,11 @@ public class WriterTests
|
|
testFile = Path.ChangeExtension(testFile, "xlsx");
|
|
testFile = Path.ChangeExtension(testFile, "xlsx");
|
|
|
|
|
|
const string worksheetName = "Test";
|
|
const string worksheetName = "Test";
|
|
- var writer = new ExcelWriter(testFile);
|
|
|
|
|
|
+ using var writer = new ExcelWriter(testFile);
|
|
writer.Write(arrayWithSkip, worksheetName);
|
|
writer.Write(arrayWithSkip, worksheetName);
|
|
writer.SaveAs(testFile);
|
|
writer.SaveAs(testFile);
|
|
|
|
|
|
- var reader = new ExcelReader(testFile);
|
|
|
|
|
|
+ using var reader = new ExcelReader(testFile);
|
|
var readArray = reader.Read<TestSkip>(worksheetName).ToArray();
|
|
var readArray = reader.Read<TestSkip>(worksheetName).ToArray();
|
|
Assert.Equal(arrayWithSkip.Length, readArray.Length);
|
|
Assert.Equal(arrayWithSkip.Length, readArray.Length);
|
|
|
|
|
|
@@ -192,11 +192,11 @@ public class WriterTests
|
|
testFile = Path.ChangeExtension(testFile, "xlsx");
|
|
testFile = Path.ChangeExtension(testFile, "xlsx");
|
|
|
|
|
|
const string worksheetName = "Test";
|
|
const string worksheetName = "Test";
|
|
- var writer = new ExcelWriter(testFile);
|
|
|
|
|
|
+ using var writer = new ExcelWriter(testFile);
|
|
writer.Write(arrayWithSkipMiddle, worksheetName);
|
|
writer.Write(arrayWithSkipMiddle, worksheetName);
|
|
writer.SaveAs(testFile);
|
|
writer.SaveAs(testFile);
|
|
|
|
|
|
- var reader = new ExcelReader(testFile);
|
|
|
|
|
|
+ using var reader = new ExcelReader(testFile);
|
|
var readArray = reader.Read<TestSkipMiddle>(worksheetName).ToArray();
|
|
var readArray = reader.Read<TestSkipMiddle>(worksheetName).ToArray();
|
|
Assert.Equal(arrayWithSkipMiddle.Length, readArray.Length);
|
|
Assert.Equal(arrayWithSkipMiddle.Length, readArray.Length);
|
|
|
|
|
|
@@ -223,11 +223,11 @@ public class WriterTests
|
|
var testFile = Path.GetRandomFileName();
|
|
var testFile = Path.GetRandomFileName();
|
|
testFile = Path.ChangeExtension(testFile, "xlsx");
|
|
testFile = Path.ChangeExtension(testFile, "xlsx");
|
|
|
|
|
|
- var writer = new ExcelWriter(testFile);
|
|
|
|
|
|
+ using var writer = new ExcelWriter(testFile);
|
|
writer.Write(arrayWithFormulas);
|
|
writer.Write(arrayWithFormulas);
|
|
writer.SaveAs(testFile);
|
|
writer.SaveAs(testFile);
|
|
|
|
|
|
- var reader = new ExcelReader(testFile);
|
|
|
|
|
|
+ using var reader = new ExcelReader(testFile);
|
|
var readArray = reader.Read<TestWithFormula>().ToArray();
|
|
var readArray = reader.Read<TestWithFormula>().ToArray();
|
|
Assert.Equal(arrayWithFormulas.Length, readArray.Length);
|
|
Assert.Equal(arrayWithFormulas.Length, readArray.Length);
|
|
|
|
|
|
@@ -252,11 +252,11 @@ public class WriterTests
|
|
var testFile = Path.GetRandomFileName();
|
|
var testFile = Path.GetRandomFileName();
|
|
testFile = Path.ChangeExtension(testFile, "xlsx");
|
|
testFile = Path.ChangeExtension(testFile, "xlsx");
|
|
|
|
|
|
- var writer = new ExcelWriter(testFile);
|
|
|
|
|
|
+ using var writer = new ExcelWriter(testFile);
|
|
writer.Write(arrayNumbersWithFormulas);
|
|
writer.Write(arrayNumbersWithFormulas);
|
|
writer.SaveAs(testFile);
|
|
writer.SaveAs(testFile);
|
|
|
|
|
|
- var reader = new ExcelReader(testFile);
|
|
|
|
|
|
+ using var reader = new ExcelReader(testFile);
|
|
var readArray = reader.Read<TestNumbersWithFormula>().ToArray();
|
|
var readArray = reader.Read<TestNumbersWithFormula>().ToArray();
|
|
Assert.Equal(arrayNumbersWithFormulas.Length, readArray.Length);
|
|
Assert.Equal(arrayNumbersWithFormulas.Length, readArray.Length);
|
|
|
|
|
|
@@ -282,11 +282,11 @@ public class WriterTests
|
|
var testFile = Path.GetRandomFileName();
|
|
var testFile = Path.GetRandomFileName();
|
|
testFile = Path.ChangeExtension(testFile, "xlsx");
|
|
testFile = Path.ChangeExtension(testFile, "xlsx");
|
|
|
|
|
|
- var writer = new ExcelWriter(testFile);
|
|
|
|
|
|
+ using var writer = new ExcelWriter(testFile);
|
|
writer.Write(arrayWithHyperlinks);
|
|
writer.Write(arrayWithHyperlinks);
|
|
writer.SaveAs(testFile);
|
|
writer.SaveAs(testFile);
|
|
|
|
|
|
- var reader = new ExcelReader(testFile);
|
|
|
|
|
|
+ using var reader = new ExcelReader(testFile);
|
|
var readArray = reader.Read<TestWithHyperlink>().ToArray();
|
|
var readArray = reader.Read<TestWithHyperlink>().ToArray();
|
|
Assert.Equal(arrayWithFormulas.Length, readArray.Length);
|
|
Assert.Equal(arrayWithFormulas.Length, readArray.Length);
|
|
|
|
|
|
@@ -300,4 +300,20 @@ public class WriterTests
|
|
|
|
|
|
File.Delete(testFile);
|
|
File.Delete(testFile);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ [Fact]
|
|
|
|
+ public void WriteReadInMemory()
|
|
|
|
+ {
|
|
|
|
+ using var workbook = new XLWorkbook();
|
|
|
|
+ const string worksheetName = "Test";
|
|
|
|
+ using var writer = new ExcelWriter(workbook);
|
|
|
|
+ writer.Write(arrayOfThree, worksheetName);
|
|
|
|
+
|
|
|
|
+ using var reader = new ExcelReader(workbook);
|
|
|
|
+ var readArray = reader.Read<Test>(worksheetName).ToArray();
|
|
|
|
+ Assert.Equal(3, readArray.Length);
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < readArray.Length; i++)
|
|
|
|
+ Assert.Equal(arrayOfThree[i], readArray[i]);
|
|
|
|
+ }
|
|
}
|
|
}
|