[Fact]
public void ToTreeOrderBy_Test()
{
var regions = new List<Regin>
{
new Regin
{
Id = 1,
Name = "b北京"
},
new Regin
{
Id = 2,
Name = "b东城区",
ParentId = 1
},
new Regin
{
Id = 3,
Name = "a西城区",
ParentId = 1
},
new Regin
{
Id = 4,
Name = "a河北"
},
new Regin
{
Id = 5,
Name = "b石家庄",
ParentId = 4
},
new Regin
{
Id = 6,
Name = "a承德",
ParentId = 4
},
new Regin
{
Id = 7,
Name = "b双桥区",
ParentId = 6
},
new Regin
{
Id = 8,
Name = "a双滦区",
ParentId = 6
}
};
var tree = regions.ToTreeOrderBy<Regin, long, string>(x => x.Name).ToList();
tree.First().Name.ShouldBe("a河北");
tree.First().Children.First().Name.ShouldBe("a承德");
tree.First().Children.First().Children.First().Name.ShouldBe("a双滦区");
}