public void ImmutableList_SerializeAndDeserialize_CorrectResult()
        {
            // ARRANGE
            var objectUnderTest = new Test();

            objectUnderTest.List = objectUnderTest.List.Add(1);
            objectUnderTest.List = objectUnderTest.List.Add(2);
            objectUnderTest.List = objectUnderTest.List.Add(3);

            // ACT
            var serialized = DataContractHelper.Serialize <Test>(objectUnderTest);
            var result     = DataContractHelper.Deserialize <Test>(serialized);

            // ASSERT
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.List);
            Assert.IsInstanceOfType(result.List, typeof(ImmutableList <int>));
            CollectionAssert.AreEqual(new int[] { 1, 2, 3 }, result.List);
        }
        public void ImmutableDictionary_SerializeAndDeserialize_CorrectResult()
        {
            // ARRANGE
            var objectUnderTest = new Test();

            objectUnderTest.Dictionary = objectUnderTest.Dictionary.Add(1, "one");
            objectUnderTest.Dictionary = objectUnderTest.Dictionary.Add(2, "two");
            objectUnderTest.Dictionary = objectUnderTest.Dictionary.Add(3, "three");

            // ACT
            var serialized = DataContractHelper.Serialize <Test>(objectUnderTest);
            var result     = DataContractHelper.Deserialize <Test>(serialized);

            // ASSERT
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Dictionary);
            Assert.IsInstanceOfType(result.Dictionary, typeof(ImmutableDictionary <int, string>));
            Assert.AreEqual("one", result.Dictionary[1]);
            Assert.AreEqual("two", result.Dictionary[2]);
            Assert.AreEqual("three", result.Dictionary[3]);
        }
 public static void WriteXml(this XmlWriter?xmlWriter, Type type, object?value) =>
 DataContractHelper.Serialize(type, xmlWriter, value);
 public static void WriteXml <TValue>(this XmlWriter?xmlWriter, TValue?value) =>
 DataContractHelper.Serialize(xmlWriter, value);
Exemplo n.º 5
0
 public static void Serialize(this object?value, Type type, XmlWriter?xmlWriter) =>
 DataContractHelper.Serialize(type, xmlWriter, value);
Exemplo n.º 6
0
 public static void Serialize <TValue>(this TValue?value, XmlWriter?xmlWriter) =>
 DataContractHelper.Serialize(xmlWriter, value);