[Fact]
public void ToValueDictionary_Given_InputIsPocoClass_Then_Output_IsAnEquivalentDictionary()
{
var valueObject = new PocoClassWithIndex
{
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);
Assert.Equal(result.Count, expectedOutput.Count);
foreach (var (key, value) in result)
{
Assert.Equal(value, expectedOutput[key]);
}
}
`
private class PocoClassWithIndex
{
public string Name { get; set; }
public object this[string name] => Name;
public int Age { get; set; }
public IEnumerable Fruits; // Field
};
`