public void SerializeAsArrayGivenMultipleValueArrayWithClassAttribute() { var values = new SingleOrList <string> { "Hello", "world", "!!!" }; var serialized = JsonConvert.SerializeObject(values, new JsonConverter[] { new SingleOrArrayJsonConverter <bool>() }); var expected = JsonConvert.SerializeObject(new List <string>(values)); Assert.AreEqual(expected, serialized); }
public void SerializeAsSingleValueGivenSingleValueArrayWithClassAttribute() { var values = new SingleOrList <string> { "Hi" }; var serialized = JsonConvert.SerializeObject(values, new JsonConverter[] { new SingleOrArrayJsonConverter <bool>() }); var expected = JsonConvert.SerializeObject(values.First()); Assert.AreEqual(expected, serialized); }
public void DeserializeInheritedListGivenClassAttributionAndMultipleItems() { var oddList = new SingleOrList <string> { "1", "3", "5" }; var serialized = JsonConvert.SerializeObject(oddList); var deserialized = JsonConvert.DeserializeObject <SingleOrList <string> >(serialized); deserialized.Should().BeEquivalentTo(oddList); }