Skip to content

Commit

Permalink
#1058, #969 - added testclass
Browse files Browse the repository at this point in the history
  • Loading branch information
swmal committed Nov 22, 2023
1 parent 64a52a0 commit 16812e0
Showing 1 changed file with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FakeItEasy;

namespace EPPlusTest.LoadFunctions
{
Expand All @@ -29,6 +30,16 @@ public class TestClass2 : TestClass
public Dictionary<string, object> Columns2 { get; set; }
}

[EpplusTable]
public class TestClass3
{
[EpplusTableColumn(Order = 1)]
public string Name { get; set; }

[EPPlusDictionaryColumn(Order = 2)]
public Dictionary<string, object> Columns { get; set; }
}


[TestMethod]
public void ShouldReadColumnsAndValuesFromDictionaryProperty()
Expand Down Expand Up @@ -134,5 +145,34 @@ public void ShouldReadColumnsAndValuesFromDictionaryProperty3()
Assert.AreEqual("test 1", sheet.Cells["G2"].Value);
}
}

[TestMethod]
public void ShouldUseDefaultKeys()
{
var item1 = new TestClass3
{
Name = "test 1",
Columns = new Dictionary<string, object> { { "A", 3 }, { "B", 2 } }
};
var keys1 = new string[] { "C", "B", "A" };
var items = new List<TestClass3> { item1 };
using (var package = new ExcelPackage())
{
var sheet = package.Workbook.Worksheets.Add("test");
sheet.Cells["A1"].LoadFromCollection(items, c =>
{
c.PrintHeaders = true;
c.RegisterDictionaryKeys(keys1);
});
Assert.AreEqual("Name", sheet.Cells["A1"].Value);
Assert.AreEqual("C", sheet.Cells["B1"].Value);
Assert.AreEqual("B", sheet.Cells["C1"].Value);
Assert.AreEqual("A", sheet.Cells["D1"].Value);
Assert.AreEqual("test 1", sheet.Cells["A2"].Value);
Assert.IsNull(sheet.Cells["B2"].Value);
Assert.AreEqual(2, sheet.Cells["C2"].Value);
Assert.AreEqual(3, sheet.Cells["D2"].Value);
}
}
}
}

0 comments on commit 16812e0

Please sign in to comment.