Reputation: 8944
I'm generating some .csv files and I need to compress this inside a Zip File. Ok, I have a framework to do this and probably everything will be fine.
But! As TDD says I just can write code, after I have some tests!
My first test sound simple, but I'm having some problems reading the Zip file, anyone know a simple way to count the number of files in my zip file?
Upvotes: 1
Views: 6608
Reputation: 887777
You seem to be looking for something like DotNetZip.
int count;
using (ZipFile zip = ZipFile.Read(path))
count = zip.Count;
Upvotes: 6
Reputation: 2345
I don't think that was a TDD question you asked but I'll answer it anyway.
[Test] public void countsNumberOfFilesInZip() { var counter = new FileCounter("existing_archive_with_2_files.zip"); AssertEqual(2, counter.count()); }
Now, using the library of your choice, make FileCounter
work. Once it works and you have a passing test, if you so choose, refactor the code so that it uses a mocking framework to mock out the calls to the zip library. Now you don't have a dependency on the file system. (I probably wouldn't go this far unless your tests are slowed down too much by the disk I/O)
Upvotes: 1