in DarabonbaUnitTests/ModelTest.cs [25:75]
public void TestToMap()
{
Model modelNull = null;
Assert.Null(modelNull.ToMap());
TestRegModel model = new TestRegModel
{
RequestId = "requestID",
Items = new List<TestRegSubModel> { new TestRegSubModel { RequestId = "sub" }, null },
NextMarker = "next",
testNoAttr = "noAttr",
subModel = new TestRegSubModel(),
testListStr = new List<string> { "str" },
bytes = Encoding.UTF8.GetBytes("test")
};
TestRegSubModel dicSubModel = new TestRegSubModel
{
RequestId = "requestDic"
};
Dictionary<string, TestRegSubModel> dicSub = new Dictionary<string, TestRegSubModel>
{
{ "subDic", dicSubModel },
{ "subNull", null }
};
var dicMap = new Dictionary<string, Dictionary<string, TestRegSubModel>>
{
{ "map", dicSub }
};
Dictionary<string, string> map = new Dictionary<string, string>
{
{ "test", "test" }
};
List<IDictionary> list = new List<IDictionary>();
list.Add(map);
List<List<IDictionary>> listNestedList = new List<List<IDictionary>>();
listNestedList.Add(list);
model.dicNestDic = dicMap;
model.listIDic = listNestedList;
Dictionary<string, object> dic = model.ToMap();
Assert.NotNull(dic);
var from = Model.ToObject<TestRegModel>(dic);
Assert.Equal("test", from.listIDic[0][0]["test"]);
Assert.Equal("requestDic", from.dicNestDic["map"]["subDic"].RequestId);
TestRegModel modelEmpty = new TestRegModel();
modelEmpty.RequestId = "1";
Dictionary<string, object> dicEmpty = modelEmpty.ToMap();
Assert.Null(dicEmpty["items"]);
Assert.Null(dicEmpty["subModel"]);
}