internal static void RunStreamRWTest( string filePath, Type type, string writeMethodName) { var readMethod = typeof(StreamReaderExtensions).GetMethod($"Read{type.Name}"); Assert.IsNotNull(readMethod, $"Could not find extension method to read {type.Name}."); var writeMethod = typeof(StreamWriterExtensions).GetMethod(writeMethodName, new[] { typeof(StreamWriter), type }); Assert.IsNotNull(writeMethod, $"Could not find extension method to write {type.Name}."); using var expectedStream = MpqFile.OpenRead(filePath); using var reader = new StreamReader(expectedStream, new UTF8Encoding(false, true)); var parsedFile = readMethod !.Invoke(null, new[] { reader }); Assert.AreEqual(type, parsedFile !.GetType()); using var actualStream = new MemoryStream(); using var writer = new StreamWriter(actualStream, reader.CurrentEncoding); writeMethod !.Invoke(null, new[] { writer, parsedFile }); writer.Flush(); StreamAssert.AreEqualText(expectedStream, actualStream, true); }
internal static void RunStreamRWTest( string filePath, Type type, Encoding?encoding = null, string?readMethodName = null, string writeMethodName = nameof(StreamWriter.Write), params object[] additionalReadParameters) { var readMethod = typeof(StreamReaderExtensions).GetMethod(readMethodName ?? $"Read{type.Name}"); Assert.IsNotNull(readMethod, $"Could not find extension method to read {type.Name}."); var writeMethod = typeof(StreamWriterExtensions).GetMethod(writeMethodName, new[] { typeof(StreamWriter), type }); Assert.IsNotNull(writeMethod, $"Could not find extension method to write {type.Name}."); using var expectedStream = FileProvider.GetFile(filePath); using var reader = new StreamReader(expectedStream, encoding ?? new UTF8Encoding(false, true)); var parsedFile = readMethod !.Invoke(null, new[] { reader }.Concat(additionalReadParameters).ToArray()); Assert.AreEqual(type, parsedFile.GetType()); using var actualStream = new MemoryStream(); using var writer = new StreamWriter(actualStream, reader.CurrentEncoding); writeMethod !.Invoke(null, new[] { writer, parsedFile }); writer.Flush(); StreamAssert.AreEqualText(expectedStream, actualStream, true); }
public void TestParseMapTriggerStrings(string mapTriggerStringsFilePath) { using var original = FileProvider.GetFile(mapTriggerStringsFilePath); using var recreated = new MemoryStream(); MapTriggerStrings.Parse(original, null, true).SerializeTo(recreated, true); StreamAssert.AreEqualText(original, recreated, true); }