public static void TestBinaryGzipSavingAndLoading() { var test = Program.GetTest(); using (Stream fileStream = File.Create(Path.Combine(DefaultSaveFolderName, "SavedTest.zip"))) { using (var zippedFileStream = new GZipStream(fileStream, CompressionMode.Compress)) { using (var testFormatter = new BinaryTestFormatter<string>(zippedFileStream, new BinaryStringFormatter( zippedFileStream)) ) { testFormatter.Save(test); } } } using (Stream fileStream = File.OpenRead(Path.Combine(DefaultSaveFolderName, "SavedTest.zip"))) { using (var zippedFileStream = new GZipStream(fileStream, CompressionMode.Decompress)) { using (var testFormatter = new BinaryTestFormatter<string>(zippedFileStream, new BinaryStringFormatter( zippedFileStream))) { var loadedTest = testFormatter.Load(); Debug.Assert(loadedTest.Questions.SequenceEqual(test.Questions)); } } } }
public static void TestBinaryCryptoGzipSavingAndLoading() { var test = Program.GetTest(); using (Stream fileStream = File.Create(Path.Combine(DefaultSaveFolderName, "SavedTest.cryzip"))) { using (var cryptoStream = new CryptoStream(fileStream, new ToBase64Transform(), CryptoStreamMode.Write)) { using (var cryptoZippedFileStream = new GZipStream(cryptoStream, CompressionMode.Compress)) { using (var testFormatter = new BinaryTestFormatter<string>(cryptoZippedFileStream, new BinaryStringFormatter( cryptoZippedFileStream))) { testFormatter.Save(test); } } } } using (Stream fileStream = File.OpenRead(Path.Combine(DefaultSaveFolderName, "SavedTest.cryzip"))) { using (var cryptoStream = new CryptoStream(fileStream, new FromBase64Transform(), CryptoStreamMode.Read) ) { using (var cryptoZippedFileStream = new GZipStream(cryptoStream, CompressionMode.Decompress)) { using (var testFormatter = new BinaryTestFormatter<string>(cryptoZippedFileStream, new BinaryStringFormatter( cryptoZippedFileStream))) { var loadedTest = testFormatter.Load(); Debug.Assert(loadedTest.Questions.SequenceEqual(test.Questions)); } } } } }
public static void TestBinarySavingAndLoading() { var test = GetTest(); using (var fileStream = File.Create(Path.Combine(DefaultSaveFolderName, "SavedTest.bin"))) { using ( var testFormatter = new BinaryTestFormatter<string>(fileStream, new BinaryStringFormatter(fileStream))) { testFormatter.Save(test); } } using (var fileStream = File.OpenRead(Path.Combine(DefaultSaveFolderName, "SavedTest.bin"))) { using ( var testFormatter = new BinaryTestFormatter<string>(fileStream, new BinaryStringFormatter(fileStream))) { var loadedTest = testFormatter.Load(); Debug.Assert(loadedTest.Questions.SequenceEqual(test.Questions)); } } }