Mock System.IO.Compression.ZipFile
See original GitHub issueHello guys,
For one of my project I started to write a basic wrapper around the methods of System.IO.Compression.ZipFile. To achieve that I’m of course using System.IO.Abstractions.
I started to introduce 4 new types IZipFileFactory, ZipFileFactory, MockZipFileFactory, MockZipFileData. Now I would like to have a property ZipFile of type IZipFileFactory in IFileSystem so I can write something like
var fileSystem = new FileSystem();
fileSystem.ZipFile.CreateFromDirectory(sourceDirectoryName, destinationArchiveFileName);
...
fileSystem.ZipFile.ExtractToDirectory(destinationArchiveFileName, destinationDirectoryName);
Would you like to see a pull request for that feature?
Thanks
Issue Analytics
- State:
- Created 5 years ago
- Comments:14 (7 by maintainers)
Top Results From Across the Web
Mock System.IO.Compression.ZipFile · Issue #396
Hello guys, For one of my project I started to write a basic wrapper around the methods of System.IO.Compression.ZipFile.
Read more >c# - Unit Testing using Shims for ZipFile
There isn't a way to mock a static class like ZipFile using mock, ... Note: We need to Fake System.IO.Compression.FileSystem (i.e. the dll) ......
Read more >How to Mock the File System for Unit Testing in .NET
In this article, we are going to learn how to mock the file system and unit test a component that interacts with the...
Read more >ZipFile.CreateFromDirectory Method
Creates a zip archive that contains the files and directories from the specified directory, uses the specified compression level and character encoding for ......
Read more >Mocking System.IO filesystem in unit tests in ASP.NET Core
Now when it comes to unit testing, it is not possible to mock these classes and methods for the simple reason they are...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
We did something like this at the company I work for (will hopefully open source some of this stuff soon).
It’s actually quite nice to be able to take a
ZipArchiveon oneIFileSystemand extract it to another (e.g. take a real ZIP on disk and populate aMockFileSystemwith it), so we implemented this as extension methods onFileBaseandZipArchive:etc. Note that
ZipArchivealready works against theStreamAPIs instead of files directly, so this is all pretty easy.The advantage of that is that it works against any
IFileSystemimplementation (and across them), and that you don’t need to implement this stuff in theIFileSystemimplementations themselves.Or that, with a destination
IFileSystemalso passed in. Sorry, that was missing in my original, have updated. Anyway, lots of ways to skin this particular cat!