public void BinaryWriterUtility_WriteNullableArrayT_1() { Dummy[] expected = new Dummy[10]; for (int i = 0; i < expected.Length; i++) { expected[i] = new Dummy { Value = i }; } MemoryStream stream = new MemoryStream(); BinaryWriter writer = new BinaryWriter(stream); BinaryWriterUtility.WriteNullableArray(writer, expected); byte[] bytes = stream.ToArray(); stream = new MemoryStream(bytes); BinaryReader reader = new BinaryReader(stream); Dummy[] actual = BinaryReaderUtility.ReadNullableArray <Dummy>(reader); Assert.IsNotNull(actual); Assert.AreEqual(expected.Length, actual.Length); for (int i = 0; i < expected.Length; i++) { Dummy item1 = expected[i]; Dummy item2 = actual[i]; Assert.AreEqual(item1.Value, item2.Value); } }
public void BinaryWriterUtility_WriteNullableArrayT_2() { Dummy[] expected = null; MemoryStream stream = new MemoryStream(); BinaryWriter writer = new BinaryWriter(stream); BinaryWriterUtility.WriteNullableArray(writer, expected); byte[] bytes = stream.ToArray(); stream = new MemoryStream(bytes); BinaryReader reader = new BinaryReader(stream); Dummy[] actual = BinaryReaderUtility.ReadNullableArray <Dummy>(reader); Assert.IsNull(actual); }