public async Task Save_OneFileToFile_FileInfoHeaderEqualsExpectedData()
        {
            const string  FileName           = nameof(Save_OneFileToFile_FileInfoHeaderEqualsExpectedData);
            string        headerPath         = FileName + HeaderFileExtension;
            string        dataPath           = FileName + DataFileExtension;
            string        input              = "inputdata123," + nameof(Save_OneFileToFile_FileInfoHeaderEqualsExpectedData);
            string        encryptedInput     = "encrypteddata654," + nameof(Save_OneFileToFile_FileInfoHeaderEqualsExpectedData);
            var           sizeMock           = CreateSizeMock(1, 20, 8);
            MS2CryptoMode expectedCryptoMode = (MS2CryptoMode)12345;
            IMS2FileInfo  expectedFileInfo   = CreateFileInfoMock(1.ToString(), "singlefile").Object;
            IMS2ArchiveCryptoRepository repo = new FakeCryptoRepository(expectedCryptoMode, EncodingTest, "1,singlefile", "1,singlefile", sizeMock.Object);

            var archive = new MS2Archive(repo);

            AddDataStringToArchive(archive, input, encryptedInput, sizeMock, 1, "singlefile", CompressionType.Zlib);
            await archive.SaveAsync(headerPath, dataPath);

            using var fsHeader = File.OpenRead(headerPath);
            using var br       = new BinaryReader(fsHeader, EncodingTest, true);
            MS2CryptoMode actualCryptoMode = (MS2CryptoMode)br.ReadUInt32();

            var(actualFileInfoSize, actualFileDataSize, actualFileCount) = await repo.GetArchiveHeaderCrypto().ReadAsync(fsHeader);

            var msFileInfo = await repo.GetDecryptionStreamAsync(fsHeader, actualFileInfoSize, true);

            using var srFileInfo = new StreamReader(msFileInfo, EncodingTest, true, -1, true);
            IMS2FileInfo actualFileInfo = await repo.GetFileInfoReaderCrypto().ReadAsync(srFileInfo);

            Assert.AreEqual(expectedFileInfo.Id, actualFileInfo.Id);
            Assert.AreEqual(expectedFileInfo.Path, actualFileInfo.Path);
            Assert.AreEqual(expectedFileInfo.RootFolderId, actualFileInfo.RootFolderId);
        }
Beispiel #2
0
 public Task WriteAsync(TextWriter textWriter, IMS2FileInfo fileInfo)
 {
     if (String.IsNullOrWhiteSpace(fileInfo.RootFolderId))
     {
         return(textWriter.WriteLineAsync(String.Join(PropertySeparator, fileInfo.Id, fileInfo.Path)));
     }
     else
     {
         return(textWriter.WriteLineAsync(String.Join(PropertySeparator, fileInfo.Id, fileInfo.RootFolderId, fileInfo.Path)));
     }
 }
Beispiel #3
0
 bool IEquatable <IMS2FileInfo> .Equals(IMS2FileInfo other)
 {
     return(this.Equals(other as MS2FileInfo));
 }
Beispiel #4
0
        public Task WriteAsync(TextWriter textWriter, IMS2FileInfo fileInfo)
        {
            textWriter.WriteLine(String.Join(',', fileInfo.Id, fileInfo.Path));

            return(Task.CompletedTask);
        }