-
-
Notifications
You must be signed in to change notification settings - Fork 350
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
8 changed files
with
125 additions
and
8 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
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,9 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace MiniExcelLibs.OpenXml.SaveByTemplate | ||
{ | ||
public interface IInputValueExtractor | ||
{ | ||
IDictionary<string, object> ToValueDictionary(object valueObject); | ||
} | ||
} |
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
104 changes: 104 additions & 0 deletions
104
tests/MiniExcelTests/SaveByTemplate/InputValueExtractorTests.cs
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,104 @@ | ||
using System.Collections.Generic; | ||
using System.Data; | ||
using FluentAssertions; | ||
using MiniExcelLibs.OpenXml.SaveByTemplate; | ||
using Xunit; | ||
|
||
namespace MiniExcelTests.SaveByTemplate; | ||
|
||
public class InputValueExtractorTests | ||
{ | ||
[Fact] | ||
public void ToValueDictionary_Given_InputIsDictionaryWithoutDataReader_Then_Output_IsAnEquivalentDictionary() | ||
{ | ||
var valueDictionary = new Dictionary<string, object> | ||
{ | ||
["Name"] = "John", | ||
["Age"] = 18, | ||
["Fruits"] = new List<string> { "Apples, Oranges" }, | ||
}; | ||
|
||
var sut = new InputValueExtractor(); | ||
var result = sut.ToValueDictionary(valueDictionary); | ||
|
||
result.Should().BeEquivalentTo(valueDictionary); | ||
} | ||
|
||
[Fact] | ||
public void ToValueDictionary_Given_InputIsDictionaryWithDataReader_Then_DataReaderIsConvertedToListOfDictionaries() | ||
{ | ||
var dataTable = new DataTable(); | ||
|
||
dataTable.Columns.Add("id", typeof(int)); | ||
dataTable.Columns.Add("name", typeof(string)); | ||
dataTable.Rows.Add(1, "Jack"); | ||
dataTable.Rows.Add(2, "Mike"); | ||
|
||
var expectedOutput = new List<Dictionary<string, object>> | ||
{ | ||
new() { ["id"] = 1, ["name"] = "Jack" }, | ||
new() { ["id"] = 2, ["name"] = "Mike" } | ||
}; | ||
|
||
var valueDictionary = new Dictionary<string, object> | ||
{ | ||
["DataReader"] = dataTable.CreateDataReader() | ||
}; | ||
|
||
var sut = new InputValueExtractor(); | ||
var result = sut.ToValueDictionary(valueDictionary); | ||
|
||
result["DataReader"].Should().BeEquivalentTo(expectedOutput); | ||
} | ||
|
||
[Fact] | ||
public void ToValueDictionary_Given_InputIsPocoRecord_Then_Output_IsAnEquivalentDictionary() | ||
{ | ||
var valueObject = new PocoRecord("John", 18, new List<string> { "Apples, Oranges" }); | ||
|
||
var expectedOutput = new Dictionary<string, object>() | ||
{ | ||
["Name"] = "John", | ||
["Age"] = 18, | ||
["Fruits"] = new List<string> { "Apples, Oranges" } | ||
}; | ||
|
||
var sut = new InputValueExtractor(); | ||
var result = sut.ToValueDictionary(valueObject); | ||
|
||
result.Should().BeEquivalentTo(expectedOutput); | ||
} | ||
|
||
[Fact] | ||
public void ToValueDictionary_Given_InputIsPocoClass_Then_Output_IsAnEquivalentDictionary() | ||
{ | ||
var valueObject = new PocoClass | ||
{ | ||
Name = "John", | ||
Age = 18, | ||
Fruits = new List<string> { "Apples, Oranges" } | ||
}; | ||
|
||
var expectedOutput = new Dictionary<string, object>() | ||
{ | ||
["Name"] = "John", | ||
["Age"] = 18, | ||
["Fruits"] = new List<string> { "Apples, Oranges" } | ||
}; | ||
|
||
var sut = new InputValueExtractor(); | ||
var result = sut.ToValueDictionary(valueObject); | ||
|
||
result.Should().BeEquivalentTo(expectedOutput); | ||
} | ||
|
||
|
||
private record PocoRecord(string Name, int Age, IEnumerable<string> Fruits); | ||
|
||
private class PocoClass | ||
{ | ||
public string Name { get; set; } | ||
public int Age { get; set; } | ||
public IEnumerable<string> Fruits; // Field | ||
}; | ||
} |
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