public void NegativeEnumTest() { var expected = new NegativeEnumClass { Value = NegativeEnum.A }; var actual = Roundtrip(expected, new[] { (byte)0xff, (byte)0xff }); Assert.AreEqual(expected.Value, actual.Value); }
public void DeserializeNegativeEnum() { string json = @"{ ""Value1"": ""Negative"", ""Value2"": -2147483648 }"; NegativeEnumClass negativeEnumClass = JsonConvert.DeserializeObject <NegativeEnumClass>(json, new StringEnumConverter()); Assert.AreEqual(NegativeEnum.Negative, negativeEnumClass.Value1); Assert.AreEqual((NegativeEnum)int.MinValue, negativeEnumClass.Value2); }
public void SerializeNegativeEnum() { NegativeEnumClass negativeEnumClass = new NegativeEnumClass(); negativeEnumClass.Value1 = NegativeEnum.Negative; negativeEnumClass.Value2 = (NegativeEnum)int.MinValue; string json = JsonConvert.SerializeObject(negativeEnumClass, Formatting.Indented, new StringEnumConverter()); StringAssert.AreEqual(@"{ ""Value1"": ""Negative"", ""Value2"": -2147483648 }", json); }
public void SerializeNegativeEnum() { NegativeEnumClass negativeEnumClass = new NegativeEnumClass(); negativeEnumClass.Value1 = NegativeEnum.Negative; negativeEnumClass.Value2 = (NegativeEnum) int.MinValue; string json = JsonConvert.SerializeObject(negativeEnumClass, Formatting.Indented, new StringEnumConverter()); Assert.AreEqual(@"{ ""Value1"": ""Negative"", ""Value2"": -2147483648 }", json); }