public void YesNoArrayConverterTest() { JsonYandexApiSerializer serializer = new JsonYandexApiSerializer(); Assert.AreEqual("{\"Value\":[\"Yes\"]}", serializer.Serialize(new YesNoObjectStub { Value = true })); Assert.AreEqual("{\"Value\":[\"No\"]}", serializer.Serialize(new YesNoObjectStub { Value = false })); Assert.AreEqual("{}", serializer.Serialize(new YesNoObjectStub { Value = null })); }
public void YesNoSerializationTest() { JsonYandexApiSerializer serializer = new JsonYandexApiSerializer(); Assert.AreEqual("\"Yes\"", serializer.Serialize(YesNo.Yes)); Assert.AreEqual(YesNo.Yes, serializer.Deserialize <YesNo>("\"Yes\"")); Assert.AreEqual(YesNo.Yes, serializer.Deserialize <YesNo?>("\"Yes\"")); Assert.AreEqual(null, serializer.Deserialize <YesNo?>(string.Empty)); }
public void YesNoSerializationTest() { JsonYandexApiSerializer serializer = new JsonYandexApiSerializer(); Assert.AreEqual("\"Yes\"", serializer.Serialize(YesNo.Yes)); Assert.AreEqual(YesNo.Yes, serializer.Deserialize<YesNo>("\"Yes\"")); Assert.AreEqual(YesNo.Yes, serializer.Deserialize<YesNo?>("\"Yes\"")); Assert.AreEqual(null, serializer.Deserialize<YesNo?>(string.Empty)); }
private string SerializeRequestMessage(Dictionary <string, object> messageParams) { var serializedParams = messageParams.Where(param => param.Value != null).Select(param => { string serializedValue = _serializer.Serialize(param.Value); return(string.Format("\"{0}\": {1}", param.Key, serializedValue)); }); return(string.Format("{{{0}}}", string.Join(", ", serializedParams))); }
public void SerializationTest() { JsonYandexApiSerializer serializer = new JsonYandexApiSerializer(); Assert.AreEqual("{\"Param1\":\"Value1\",\"Param2\":100}", serializer.Serialize(new { Param1 = "Value1", Param2 = 100, Param3 = (string)null })); Assert.AreEqual("{\"Param1\":\"2001-11-22\"}", serializer.Serialize(new { Param1 = new DateTime(2001, 11, 22) })); Assert.AreEqual("10", serializer.Serialize(10)); Assert.AreEqual("0", serializer.Serialize(0)); Assert.AreEqual("123.456", serializer.Serialize(123.456)); Assert.AreEqual("\"Value1\"", serializer.Serialize("Value1")); Assert.AreEqual("[\"Value1\",\"Value2\",\"Value3\"]", serializer.Serialize(new[] { "Value1", "Value2", "Value3" })); Assert.AreEqual("null", serializer.Serialize(null)); }