-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
189 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
using System; | ||
using System.IO; | ||
using System.Reflection; | ||
using OfficeOpenXml; | ||
using Shouldly; | ||
|
||
namespace EPPlus.Extensions.Tests | ||
{ | ||
public class ExtensionTests | ||
{ | ||
public void ToDataSetSimple_ShouldHandleHeaderRows_WhenSpecified() | ||
{ | ||
var package = GetMarvelPackage(); | ||
|
||
var result = package.ToDataSet(true); | ||
|
||
result.Tables[0].Rows.Count.ShouldBe(10); | ||
} | ||
|
||
public void ToDataSetSimple_ShouldHandleHeaderRows_WhenNotSpecified() | ||
{ | ||
var package = GetMarvelPackage(); | ||
|
||
var result = package.ToDataSet(false); | ||
|
||
result.Tables[0].Rows.Count.ShouldBe(11); | ||
} | ||
|
||
public void ToDataSet_ShouldThrowException_WhenHeaderRowIsLessThanZero() | ||
{ | ||
var package = new ExcelPackage(); | ||
|
||
var exception = Should.Throw<ArgumentOutOfRangeException>(() => package.ToDataSet(-1)); | ||
exception.ParamName.ShouldBe("headerRow"); | ||
} | ||
|
||
public void ToDataSet_ShouldReturnOneTable_WhenOneSheet() | ||
{ | ||
var package = GetStatesPackage(); | ||
|
||
var result = package.ToDataSet(0); | ||
|
||
result.Tables.Count.ShouldBe(1); | ||
} | ||
|
||
public void ToDataSet_ShouldReturnTwoTables_WhenTwoSheets() | ||
{ | ||
var package = GetMarvelPackage(); | ||
|
||
var result = package.ToDataSet(0); | ||
|
||
result.Tables.Count.ShouldBe(2); | ||
} | ||
|
||
public void ToDataSet_ShouldHandleHeaderRows_WhenSetToZero() | ||
{ | ||
var package = GetStatesPackage(); | ||
|
||
var result = package.ToDataSet(0); | ||
|
||
result.Tables[0].Rows.Count.ShouldBe(50); | ||
} | ||
|
||
public void ToDataSet_ShouldHandleHeaderRows_WhenSetToOne() | ||
{ | ||
var package = GetStatesPackage(); | ||
|
||
var result = package.ToDataSet(1); | ||
|
||
result.Tables[0].Rows.Count.ShouldBe(49); | ||
} | ||
|
||
public void ToDataSet_ShouldHandleHeaderRows_WhenSetToTen() | ||
{ | ||
var package = GetStatesPackage(); | ||
|
||
var result = package.ToDataSet(10); | ||
|
||
result.Tables[0].Rows.Count.ShouldBe(40); | ||
} | ||
|
||
public void ToDataSet_ShouldNameColumnsWithHeaderValues_WhenHeaderValuesExist() | ||
{ | ||
var package = GetMarvelPackage(); | ||
|
||
var result = package.ToDataSet(1); | ||
|
||
result.Tables[0].Columns[0].ColumnName.ShouldBe("First Name"); | ||
result.Tables[0].Columns[1].ColumnName.ShouldBe("Last Name"); | ||
result.Tables[0].Columns[2].ColumnName.ShouldBe("Alter Ego"); | ||
} | ||
|
||
public void ToDataSet_ShouldUseGenericColumnNames_WhenHeaderValuesDoNotExist() | ||
{ | ||
var package = GetStatesPackage(); | ||
|
||
var result = package.ToDataSet(0); | ||
|
||
result.Tables[0].Columns[0].ColumnName.ShouldBe("Column 1"); | ||
} | ||
|
||
public void ToDataSet_ShouldAddColumns_ForEachSourceColumn() | ||
{ | ||
var package = GetMarvelPackage(); | ||
|
||
var result = package.ToDataSet(0); | ||
|
||
result.Tables[0].Columns.Count.ShouldBe(3); | ||
} | ||
|
||
public void ToDataSet_ShouldAddRows_ForEachSourceRow() | ||
{ | ||
var package = GetStatesPackage(); | ||
|
||
var result = package.ToDataSet(0); | ||
|
||
result.Tables[0].Rows.Count.ShouldBe(50); | ||
result.Tables[0].Rows[0][0].ToString().ShouldBe("Alabama"); | ||
result.Tables[0].Rows[49][0].ToString().ShouldBe("Wyoming"); | ||
} | ||
|
||
private static ExcelPackage GetMarvelPackage() | ||
{ | ||
var path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"Marvel.xlsx"); | ||
var file = new FileInfo(path); | ||
var package = new ExcelPackage(file); | ||
return package; | ||
} | ||
|
||
private static ExcelPackage GetStatesPackage() | ||
{ | ||
var path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"States.xlsx"); | ||
var file = new FileInfo(path); | ||
var package = new ExcelPackage(file); | ||
return package; | ||
} | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="EPPlus" version="3.1.3.3" targetFramework="net452" /> | ||
<package id="Fixie" version="1.0.2" targetFramework="net452" /> | ||
<package id="Shouldly" version="2.8.2" targetFramework="net452" /> | ||
</packages> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters