private static async Task ExtractArchiveFilesAsync(string headerFile, string dataFile, string extractPath) { using IMS2Archive archive = await MS2Archive.GetAndLoadArchiveAsync(headerFile, dataFile).ConfigureAwait(false); foreach (var file in archive) { await ExtractFileAsync(extractPath, file).ConfigureAwait(false); } }
private static void AddDataStringToArchive(IMS2Archive archive, string data, string dataForArchiving, Mock <IMS2SizeHeader> sizeMock, uint id, string name, CompressionType compressionType) { byte[] bytes = EncodingTest.GetBytes(data); var ms = new MemoryStream(bytes); byte[] bytesArchiving = EncodingTest.GetBytes(dataForArchiving); var msArchiving = new MemoryStream(bytesArchiving); var fileMock = CreateFileMock(archive, ms, msArchiving, sizeMock, id, name, compressionType); archive.Add(fileMock.Object); }
private static List <Mock <IMS2File> > AddFileMocksToArchive(IMS2Archive archive, int fileCount) { var mocks = new List <Mock <IMS2File> >(); for (int i = 0; i < fileCount; i++) { var fileMock = new Mock <IMS2File>(MockBehavior.Strict); fileMock.SetupGet(f => f.Id).Returns(i); fileMock.Setup(f => f.Dispose()).Verifiable(); archive.Add(fileMock.Object); mocks.Add(fileMock); } return(mocks); }
private static Mock <IMS2File> CreateFileMock(IMS2Archive archive, MemoryStream stream, MemoryStream archivingStream, Mock <IMS2SizeHeader> archivingSizeMock, uint id, string name, CompressionType compressionType) { Mock <IMS2FileInfo> fileInfoMock = CreateFileInfoMock(id.ToString(), name); Mock <IMS2SizeHeader> sizeMock = CreateSizeMock(stream.Length, stream.Length, stream.Length); Mock <IMS2FileHeader> fileHeaderMock = CreateFileHeaderMock(sizeMock, id, 0, compressionType); var result = new Mock <IMS2File>(MockBehavior.Strict); result.SetupGet(f => f.Archive).Returns(archive); result.SetupGet(f => f.Header).Returns(fileHeaderMock.Object); result.SetupGet(f => f.Id).Returns(id); result.SetupGet(f => f.Info).Returns(fileInfoMock.Object); result.SetupGet(f => f.Name).Returns(name); result.Setup(f => f.GetStreamAsync()).Returns(Task.FromResult <Stream>(stream)); result.Setup(f => f.GetStreamForArchivingAsync()).Returns(Task.FromResult <(Stream, IMS2SizeHeader)>((archivingStream, archivingSizeMock.Object))); result.Setup(f => f.Dispose()).Callback(() => { stream.Dispose(); archivingStream.Dispose(); }); return(result); }