private static void Test(A refObject, bool shouldBeEqual) { Console.WriteLine(string.Format("refObject and A.Empty are {0}.", object.ReferenceEquals(refObject, A.Empty) ? "identical" : "different")); var binary = BinaryFormatterHelper.ToBase64String(refObject); var DeserializedObject = BinaryFormatterHelper.FromBase64String <A>(binary); Console.WriteLine(string.Format("DeserializedObject and A.Empty are {0}.", object.ReferenceEquals(refObject, A.Empty) ? "identical" : "different")); Debug.Assert(object.ReferenceEquals(refObject, A.Empty) == object.ReferenceEquals(DeserializedObject, A.Empty)); // No assert Debug.Assert(shouldBeEqual == object.ReferenceEquals(refObject, DeserializedObject)); // No assert }
public static void Test() { var test = new TestConfiguration(); Debug.WriteLine("\nTesting Xmlserializer..."); var xml = XmlSerializationHelper.GetXml(test); using (new SetValue <bool>(TestConfiguration.ShowDebugInformation, true)) { var testFromXml = XmlSerializationHelper.LoadFromXML <TestConfiguration>(xml); Debug.WriteLine("XmlSerializer result: " + testFromXml.ToString()); } Debug.WriteLine("\nTesting Json.NET..."); var json = JsonConvert.SerializeObject(test, Formatting.Indented); using (new SetValue <bool>(TestConfiguration.ShowDebugInformation, true)) { var testFromJson = JsonConvert.DeserializeObject <TestConfiguration>(json); Debug.WriteLine("Json.NET result: " + testFromJson.ToString()); } Debug.WriteLine("\nTesting DataContractSerializer..."); var contractXml = DataContractSerializerHelper.GetXml(test); using (new SetValue <bool>(TestConfiguration.ShowDebugInformation, true)) { var testFromContractXml = DataContractSerializerHelper.LoadFromXML <TestConfiguration>(contractXml); Debug.WriteLine("DataContractSerializer result: " + testFromContractXml.ToString()); } Debug.WriteLine("\nTesting BinaryFormatter..."); var binary = BinaryFormatterHelper.ToBase64String(test); using (new SetValue <bool>(TestConfiguration.ShowDebugInformation, true)) { var testFromBinary = BinaryFormatterHelper.FromBase64String <TestConfiguration>(binary); Debug.WriteLine("BinaryFormatter result: " + testFromBinary.ToString()); } Debug.WriteLine("\nTesting JavaScriptSerializer..."); var javaScript = new JavaScriptSerializer().Serialize(test); using (new SetValue <bool>(TestConfiguration.ShowDebugInformation, true)) { var testFromJavaScript = new JavaScriptSerializer().Deserialize <TestConfiguration>(javaScript); Debug.WriteLine("JavaScriptSerializer result: " + testFromJavaScript.ToString()); } }