-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ Added Validate<> method + tests + ExcelTableConvertExceptionArgs now holds exact cell address + Prepared for release 1.1
- Loading branch information
Showing
9 changed files
with
198 additions
and
30 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
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 |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using System; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using OfficeOpenXml; | ||
using System.IO; | ||
using System.Reflection; | ||
using EPPlus.Extensions; | ||
using System.Linq; | ||
|
||
namespace TESTS | ||
{ | ||
[TestClass] | ||
public class TableValidateTests | ||
{ | ||
private TestContext testContextInstance; | ||
private static ExcelPackage excelPackage; | ||
|
||
/// <summary> | ||
///Gets or sets the test context which provides | ||
///information about and functionality for the current test run. | ||
///</summary> | ||
public TestContext TestContext | ||
{ | ||
get | ||
{ | ||
return testContextInstance; | ||
} | ||
set | ||
{ | ||
testContextInstance = value; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Initializes EPPLus excelPackage with the embedded content | ||
/// </summary> | ||
[ClassInitialize()] | ||
public static void MyClassInitialize(TestContext testContext) | ||
{ | ||
var assembly = Assembly.GetExecutingAssembly(); | ||
var resourceName = "TESTS.Resources.testsheets.xlsx"; | ||
|
||
using (Stream stream = assembly.GetManifestResourceStream(resourceName)) | ||
{ | ||
excelPackage = new ExcelPackage(stream); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Frees up excelPackage | ||
/// </summary> | ||
[ClassCleanup()] | ||
public static void MyClassCleanup() | ||
{ | ||
excelPackage.Dispose(); | ||
} | ||
|
||
enum Manufacturers { Opel = 1, Ford, Mercedes}; | ||
class WrongCars | ||
{ | ||
[ExcelTableColumn(ColumnName = "License plate")] | ||
public string licensePlate { get; set; } | ||
|
||
[ExcelTableColumn] | ||
public Manufacturers manufacturer { get; set; } | ||
|
||
[ExcelTableColumn(ColumnName = "Manufacturing date")] | ||
public DateTime manufacturingDate { get; set; } | ||
|
||
[ExcelTableColumn(ColumnName = "Is ready for traffic?")] | ||
public bool ready { get; set; } | ||
} | ||
|
||
[TestMethod] | ||
public void Test_TableValidation() | ||
{ | ||
var table = excelPackage.GetTable("TEST3"); | ||
|
||
Assert.IsNotNull(table, "We have TEST3 table"); | ||
|
||
var validation = table.Validate<WrongCars>().ToList(); | ||
|
||
Assert.IsNotNull(validation, "we have errors here"); | ||
Assert.AreEqual(2, validation.Count, "We have 2 errors"); | ||
Assert.IsTrue(validation.Exists(x => x.cellAddress.Address.Equals("C6", StringComparison.InvariantCultureIgnoreCase)), "Toyota is not in the enumeration"); | ||
Assert.IsTrue(validation.Exists(x => x.cellAddress.Address.Equals("D7", StringComparison.InvariantCultureIgnoreCase)), "Date is null"); | ||
} | ||
} | ||
} |
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
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
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