Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit f0622bc

Browse files
committed
Add more ToObjectDictionary Tests
1 parent 3ee77c9 commit f0622bc

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/ServiceStack.Text.Tests/AutoMappingTests.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,34 @@ public void Can_use_ToObjectDictionary_to_Remove_Property_with_Attribute()
10111011
Assert.That(vm.Private, Is.Null);
10121012
}
10131013

1014+
class DictionaryTest
1015+
{
1016+
public string A { get; set; }
1017+
public int B { get; set; }
1018+
public bool C { get; set; }
1019+
public double D { get; set; }
1020+
}
1021+
1022+
[Test]
1023+
public void Can_convert_anonymous_object_to_ObjectDictionary()
1024+
{
1025+
var newObj = new { A = "a", B = 1, C = true, D = 2.0 };
1026+
var type = new DictionaryTest { A = "a", B = 1, C = true, D = 2.0 };
1027+
var expected = new Dictionary<string, object> {
1028+
["A"] = "a",
1029+
["B"] = 1,
1030+
["C"] = true,
1031+
["D"] = 2.0
1032+
};
1033+
1034+
var to = newObj.ToObjectDictionary();
1035+
Assert.That(to, Is.EquivalentTo(expected));
1036+
to = type.ToObjectDictionary();
1037+
Assert.That(to, Is.EquivalentTo(expected));
1038+
to = expected.ToObjectDictionary();
1039+
Assert.That(to, Is.EquivalentTo(expected));
1040+
}
1041+
10141042
[Test]
10151043
public void Can_convert_string_to_collection()
10161044
{

0 commit comments

Comments
 (0)