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

Commit d5987e2

Browse files
committed
Update AutoMappingTests.cs
1 parent b7f2b36 commit d5987e2

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

tests/ServiceStack.Text.Tests/AutoMappingTests.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,5 +1476,57 @@ Company Create()
14761476
Assert.That(original.Address.City, Is.EqualTo(defaults.Address.City));
14771477
Assert.That(original.Address.PostCode, Is.EqualTo("4321"));
14781478
}
1479+
1480+
public class NavItem : IMeta
1481+
{
1482+
public string Label { get; set; }
1483+
public string Path { get; set; }
1484+
1485+
/// <summary>
1486+
/// Whether Active class should only be added when paths are exact match
1487+
/// otherwise checks if ActivePath starts with Path
1488+
/// </summary>
1489+
public bool Exact { get; set; }
1490+
1491+
public string Id { get; set; } // Emit id="{Id}"
1492+
public string Class { get; set; } // Override class="{Class}"
1493+
1494+
public List<NavItem> Children { get; set; } = new List<NavItem>();
1495+
1496+
public Dictionary<string, string> Meta { get; set; } = new Dictionary<string, string>();
1497+
}
1498+
1499+
[Test]
1500+
public void Does_convert_nested_collections()
1501+
{
1502+
var to = new[] {
1503+
new Dictionary<string,object> {
1504+
["id"] = "A1",
1505+
["children"] = new List<object>
1506+
{
1507+
new Dictionary<string,object>
1508+
{
1509+
["id"] = "B1",
1510+
},
1511+
new Dictionary<string,object>
1512+
{
1513+
["id"] = "B2",
1514+
["children"] = new List<object> {
1515+
new Dictionary<string,object>
1516+
{
1517+
["id"] = "C1",
1518+
},
1519+
}
1520+
},
1521+
}
1522+
}
1523+
};
1524+
1525+
var navItems = to.ConvertTo<List<NavItem>>();
1526+
Assert.That(navItems[0].Id, Is.EqualTo("A1"));
1527+
Assert.That(navItems[0].Children[0].Id, Is.EqualTo("B1"));
1528+
Assert.That(navItems[0].Children[1].Id, Is.EqualTo("B2"));
1529+
Assert.That(navItems[0].Children[1].Children[0].Id, Is.EqualTo("C1"));
1530+
}
14791531
}
14801532
}

0 commit comments

Comments
 (0)