Skip to content

Commit

Permalink
Add extra tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GerardSmit committed May 30, 2024
1 parent 6967eff commit 917a70e
Showing 1 changed file with 47 additions and 2 deletions.
49 changes: 47 additions & 2 deletions src/Zio.Tests/FileSystems/TestZipArchiveFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,17 @@ public void TestCaseInSensitiveZip(string path)
using var archive = new ZipArchive(stream, ZipArchiveMode.Read);
var fs = new ZipArchiveFileSystem(archive);

Assert.True(fs.DirectoryExists("/Folder"));
Assert.True(fs.DirectoryExists("/folder"));

Assert.False(fs.FileExists("/Folder"));
Assert.False(fs.FileExists("/folder"));

Assert.True(fs.FileExists("/Folder/File.txt"));
Assert.True(fs.FileExists("/folder/file.txt"));

Assert.False(fs.DirectoryExists("/Folder/file.txt"));
Assert.False(fs.DirectoryExists("/folder/File.txt"));
}

[Theory]
Expand All @@ -252,16 +261,25 @@ public void TestCaseSensitiveZip(string path)
using var archive = new ZipArchive(stream, ZipArchiveMode.Read);
var fs = new ZipArchiveFileSystem(archive, true);

Assert.True(fs.DirectoryExists("/Folder"));
Assert.False(fs.DirectoryExists("/folder"));

Assert.False(fs.FileExists("/Folder"));
Assert.False(fs.FileExists("/folder"));

Assert.True(fs.FileExists("/Folder/File.txt"));
Assert.False(fs.FileExists("/folder/file.txt"));

Assert.False(fs.DirectoryExists("/Folder/file.txt"));
Assert.False(fs.DirectoryExists("/folder/File.txt"));
}

[Fact]
public void TestSave()
public void TestSaveStream()
{
var stream = new MemoryStream();

var fs = new ZipArchiveFileSystem(stream);
using var fs = new ZipArchiveFileSystem(stream);

fs.WriteAllText("/a/b.txt", "abc");
fs.Save();
Expand All @@ -284,4 +302,31 @@ public void TestSave()
Assert.Equal("def", fs2.ReadAllText("/a/b.txt"));
}
}

[Fact]
public void TestSaveFile()
{
var path = Path.Combine(SystemPath, Guid.NewGuid().ToString("N") + ".zip");

try
{
using var fs = new ZipArchiveFileSystem(path);

Assert.Equal(0, new FileInfo(path).Length);

fs.WriteAllText("/a/b.txt", "abc");
fs.Save();

// We cannot check the content because the file is still open
Assert.NotEqual(0, new FileInfo(path).Length);

// Ensure we can save multiple times
fs.WriteAllText("/a/b.txt", "def");
fs.Save();
}
finally
{
File.Delete(path);
}
}
}

0 comments on commit 917a70e

Please sign in to comment.