public void DictionaryModelTest() { var mutableDictionaryModel = new MutableDictionaryTestModel(); mutableDictionaryModel.Dict.Add("test1", "test1"); mutableDictionaryModel.Dict.Add("test2", null); mutableDictionaryModel.Dict.Add("test3", ""); mutableDictionaryModel.Dict.Add("", "test4"); string json = JsonSerializer.SerializeDataContract(mutableDictionaryModel, false); Assert.AreEqual("{\"Dict\": {\"test1\": \"test1\", \"test2\": null, \"test3\": \"\", \"\": \"test4\"}}", json); var newMutableDictionaryModel = JsonSerializer.DeserializeDataContract <MutableDictionaryTestModel>(json); Assert.AreEqual(4, newMutableDictionaryModel.Dict.Count); Assert.IsTrue(newMutableDictionaryModel.Dict.ContainsKey("test1")); Assert.IsTrue(newMutableDictionaryModel.Dict.ContainsKey("test2")); Assert.IsTrue(newMutableDictionaryModel.Dict.ContainsKey("test3")); Assert.IsTrue(newMutableDictionaryModel.Dict.ContainsKey("")); Assert.AreEqual("test1", newMutableDictionaryModel.Dict["test1"]); Assert.AreEqual(null, newMutableDictionaryModel.Dict["test2"]); Assert.AreEqual("", newMutableDictionaryModel.Dict["test3"]); Assert.AreEqual("test4", newMutableDictionaryModel.Dict[""]); }
public void DictionaryModelTest() { var mutableDictionaryModel = new MutableDictionaryTestModel(); mutableDictionaryModel.Dict.Add("test1", "test1"); mutableDictionaryModel.Dict.Add("test2", null); mutableDictionaryModel.Dict.Add("test3", ""); mutableDictionaryModel.Dict.Add("", "test4"); string json = JsonSerializer.SerializeDataContract(mutableDictionaryModel, false); Assert.AreEqual("{\"Dict\": {\"test1\": \"test1\", \"test2\": null, \"test3\": \"\", \"\": \"test4\"}}", json); var newMutableDictionaryModel = JsonSerializer.DeserializeDataContract<MutableDictionaryTestModel>(json); Assert.AreEqual(4, newMutableDictionaryModel.Dict.Count); Assert.IsTrue(newMutableDictionaryModel.Dict.ContainsKey("test1")); Assert.IsTrue(newMutableDictionaryModel.Dict.ContainsKey("test2")); Assert.IsTrue(newMutableDictionaryModel.Dict.ContainsKey("test3")); Assert.IsTrue(newMutableDictionaryModel.Dict.ContainsKey("")); Assert.AreEqual("test1", newMutableDictionaryModel.Dict["test1"]); Assert.AreEqual(null, newMutableDictionaryModel.Dict["test2"]); Assert.AreEqual("", newMutableDictionaryModel.Dict["test3"]); Assert.AreEqual("test4", newMutableDictionaryModel.Dict[""]); }