// -------------------------------------------------------------------------------------------------------------------------- // TODO: This won't work for lists or dictionaries! private static void ReadWriteTest <T>(T data) { using (var ms = new MemoryStream()) { MethodInfo writer = typeof(EZWriter).GetMethod("Write", new Type[] { typeof(Stream), typeof(T) }); if (writer == null) { throw new InvalidOperationException(string.Format("Could not find write method for type {0}!", typeof(T))); } writer.Invoke(null, new object[] { ms, data }); ms.Seek(0, SeekOrigin.Begin); T comp = EZReader.Read <T>(ms); //List<string> comp = EZReader.ReadList<string>(ms); ObjectInspector inspector = new ObjectInspector(); inspector.CompareObjects((object)data, (object)comp, true); } }
public void CanUseGenericEZReaderMethod() { // A more difficult one... const int MAX = 10; Int32[] data = new Int32[MAX]; for (int i = 0; i < MAX; i++) { data[i] = i; } MemoryStream m = new MemoryStream(); EZWriter.Write(m, data); m.Seek(0, SeekOrigin.Begin); Int32[] comp = EZReader.Read <Int32[]>(m); ObjectInspector oi = new ObjectInspector(); var result = oi.CompareArrays <int>(data, comp); // Make sure that it matches! Assert.IsTrue(result.Item1, result.Item2); // Let's do a string to make sure! string testString = RandomTools.GetRandomCharString(MAX); m = new MemoryStream(); EZWriter.Write(m, testString); m.Seek(0, SeekOrigin.Begin); string compString = EZReader.Read <string>(m); Assert.AreEqual(testString, compString); }