Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public async Task Save_OneFileToPath_ArchiveHeaderEqualsExpectedData()
        {
            const string   FileName             = nameof(Save_OneFileToPath_ArchiveHeaderEqualsExpectedData);
            string         headerPath           = FileName + HeaderFileExtension;
            string         dataPath             = FileName + DataFileExtension;
            string         input                = "inputdata123" + nameof(Save_OneFileToPath_ArchiveHeaderEqualsExpectedData);
            string         encryptedInput       = "encrypteddata654" + nameof(Save_OneFileToPath_ArchiveHeaderEqualsExpectedData);
            var            sizeMock             = CreateSizeMock(1, 20, 8);
            IMS2SizeHeader expectedFileInfoSize = sizeMock.Object;
            IMS2SizeHeader expectedFileDataSize = sizeMock.Object;
            long           expectedFileCount    = 1;
            MS2CryptoMode  expectedCryptoMode   = (MS2CryptoMode)12345;
            IMS2ArchiveCryptoRepository repo    = new FakeCryptoRepository(expectedCryptoMode, EncodingTest, input, encryptedInput, 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);

            Assert.AreEqual(expectedCryptoMode, actualCryptoMode);
            Assert.AreEqual(expectedFileInfoSize.EncodedSize, actualFileInfoSize.EncodedSize);
            Assert.AreEqual(expectedFileInfoSize.CompressedSize, actualFileInfoSize.CompressedSize);
            Assert.AreEqual(expectedFileInfoSize.Size, actualFileInfoSize.Size);
            Assert.AreEqual(expectedFileDataSize.EncodedSize, actualFileDataSize.EncodedSize);
            Assert.AreEqual(expectedFileDataSize.CompressedSize, actualFileDataSize.CompressedSize);
            Assert.AreEqual(expectedFileDataSize.Size, actualFileDataSize.Size);
            Assert.AreEqual(expectedFileCount, actualFileCount);
        }