public void Test_All_Methods() { var obj1 = new FormatModel { Age = 18, Name = "老九" }; var formatter = new WebApiClient.Defaults.JsonFormatter(); var json = formatter.Serialize(obj1, null); var obj2 = formatter.Deserialize(json, typeof(FormatModel)); Assert.True(obj1.Equals(obj2)); }
public void Test_All_Methods() { var obj1 = new FormatModel { Age = 18, Name = "老九" }; var formatter = new WebApiClient.Defaults.XmlFormatter(); var xml = formatter.Serialize(obj1, Encoding.UTF8); var obj2 = formatter.Deserialize(xml, typeof(FormatModel)); Assert.True(obj1.Equals(obj2)); }
public void SerializeTest() { var obj1 = new FormatModel { Age = 18, Name = "老九" }; var formatter = new WebApiClient.Defaults.KeyValueFormatter(); var kvs = formatter.Serialize("pName", obj1, null) .ToDictionary(item => item.Key, item => item.Value); Assert.True(kvs.Count == 2); Assert.True(kvs["Name"] == "老九"); Assert.True(kvs["Age"] == "18"); kvs = formatter.Serialize("pName", 30, null) .ToDictionary(item => item.Key, item => item.Value); Assert.True(kvs.Count == 1); Assert.True(kvs["pName"] == "30"); }
public void SerializeTest() { var obj1 = new FormatModel { Age = 18, Name = "老九" }; var formatter = new WebApiClient.Defaults.KeyValueFormatter(); var kvs = formatter.Serialize("pName", obj1, null) .ToDictionary(item => item.Key, item => item.Value); Assert.True(kvs.Count == 2); Assert.True(kvs["Name"] == "老九"); Assert.True(kvs["Age"] == "18"); kvs = formatter.Serialize("pName", 30, null) .ToDictionary(item => item.Key, item => item.Value); Assert.True(kvs.Count == 1); Assert.True(kvs["pName"] == "30"); var dic = new System.Collections.Concurrent.ConcurrentDictionary <string, object>(); dic.TryAdd("Key", "Value"); var formatter2 = new WebApiClient.Defaults.KeyValueFormatter(); var kvs2 = formatter2.Serialize("dic", dic, new FormatOptions { UseCamelCase = true }); var kvs3 = formatter2.Serialize("dic", dic.ToArray(), new FormatOptions { UseCamelCase = true }); Assert.True(kvs2.First().Key == "key"); Assert.True(kvs3.First().Key == "key"); Assert.True(formatter2.Serialize("null", null, null).Any()); }
public void Test_All_Methods() { var obj1 = new FormatModel { Age = 18, Name = "老九" }; var formatter = new WebApiClient.Defaults.JsonFormatter(); var json = formatter.Serialize(obj1, null); var obj2 = formatter.Deserialize(json, typeof(FormatModel)); Assert.True(obj1.Equals(obj2)); var dic = new System.Collections.Concurrent.ConcurrentDictionary <string, object>(); dic.TryAdd("Key", "Value"); var formatter2 = new WebApiClient.Defaults.JsonFormatter(); var json2 = formatter2.Serialize(dic, new FormatOptions { UseCamelCase = true }); Assert.Contains("key", json2); }