private void StreamCompressionRoundtrip_Test(ISerializer serializer) { // arrange, write test file var path = Path.Combine($"test-{serializer.GetType().Name}-{Guid.NewGuid().ToString("N").Substring(10)}.gz"); var model = new StubModel { StringProperty = "abc", IntProperty = 999 }; StubModel newModel = null; // act using (var input = new MemoryStream()) { serializer.Serialize(model, input); // to stream FileCompressionHelper.Compress(input, path); // from stream } using (var output = new MemoryStream()) { FileCompressionHelper.Decompress(path, output); // to stream newModel = serializer.Deserialize <StubModel>(output); // from stream } // assert newModel.ShouldNotBeNull(); newModel.StringProperty.ShouldBe(model.StringProperty); newModel.IntProperty.ShouldBe(model.IntProperty); }
public void FileCompressionRoundtrip_Test() { // arrange, write test file var path = Path.Combine($"test-{Guid.NewGuid().ToString("N").Substring(10)}"); const string content = "ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456ABCDEFGHIJKLMNOP123456"; using (var writer = new StreamWriter(path + ".txt")) { writer.WriteLine(content); } // act FileCompressionHelper.Compress(path + ".txt"); FileCompressionHelper.Decompress(path + ".gz", path + ".new.txt"); // assert File.ReadAllLines(path + ".new.txt")[0].ShouldBe(content); }