示例#1
0
        public async Task Save_ThreeFilesCompressedToFile_DataEqualsExpected()
        {
            const string  FileName           = nameof(Save_ThreeFilesToFile_DataEqualsExpected);
            string        headerPath         = FileName + HeaderFileExtension;
            string        dataPath           = FileName + DataFileExtension;
            string        input              = "inputdata123" + nameof(Save_ThreeFilesToFile_DataEqualsExpected);
            string        encryptedInput     = "encrypteddata654" + nameof(Save_ThreeFilesToFile_DataEqualsExpected);
            var           sbExpected         = new StringBuilder();
            var           sizeMock           = CreateSizeMock(20, 30, 40);
            MS2CryptoMode cryptoMode         = (MS2CryptoMode)12345;
            IMS2ArchiveCryptoRepository repo = new FakeCryptoRepository(cryptoMode, EncodingTest, input, encryptedInput, sizeMock.Object);
            const int fileCount              = 3;

            var archive = MS2Archive.GetArchiveMS2F();

            for (uint i = 1; i <= fileCount; i++)
            {
                sbExpected.Append(input);
                AddDataStringToArchive(archive, input, encryptedInput, sizeMock, i, "file" + i, CompressionType.Zlib);
            }
            await archive.SaveAsync(headerPath, dataPath);

            using var fsData = File.OpenRead(dataPath);
            StringBuilder sbActual = new StringBuilder();

            for (uint i = 1; i <= fileCount; i++)
            {
                string actual = await StreamToString(await repo.GetDecryptionStreamAsync(fsData, sizeMock.Object, false));

                sbActual.Append(actual);
            }
            Assert.AreEqual(sbExpected.ToString(), sbActual.ToString());
        }
示例#2
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);
        }
示例#3
0
        public async Task Save_OneFileToPath_DataEqualsInput()
        {
            const string  FileName           = nameof(Save_OneFileToPath_DataEqualsInput);
            string        headerPath         = FileName + HeaderFileExtension;
            string        dataPath           = FileName + DataFileExtension;
            string        input              = "inputdata123" + nameof(Save_OneFileToPath_DataEqualsInput);
            string        encryptedInput     = "encrypteddata654" + nameof(Save_OneFileToPath_DataEqualsInput);
            var           sizeMock           = CreateSizeMock(20, 30, 40);
            MS2CryptoMode cryptoMode         = (MS2CryptoMode)12345;
            IMS2ArchiveCryptoRepository repo = new FakeCryptoRepository(cryptoMode, 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 fsData = File.OpenRead(dataPath);
            string actual = await StreamToString(await repo.GetDecryptionStreamAsync(fsData, sizeMock.Object, false));

            Assert.AreEqual(input, actual);
        }