diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 5bc2bd35dc..3fefce5c76 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -2,7 +2,7 @@ CS1591;CS0649;xUnit1026;xUnit1013;msb3277;CS0436;CS1573;NU1901;NU1902;NU1903 - 21.1.3 + 21.1.4 enable preview true diff --git a/src/Verify.Tests/StreamTests.cs b/src/Verify.Tests/StreamTests.cs index 707a4893c4..167d1fd0e7 100644 --- a/src/Verify.Tests/StreamTests.cs +++ b/src/Verify.Tests/StreamTests.cs @@ -64,7 +64,7 @@ public Task VerifyBytes() => public async Task EmptyBinary() { var exception = await Assert.ThrowsAsync(() => Verify(Array.Empty(), "bin")); - Assert.Equal("Empty data is not allowed.", exception.Message); + Assert.StartsWith("Empty data is not allowed. Path: ", exception.Message); } [Fact] diff --git a/src/Verify/IoHelpers.cs b/src/Verify/IoHelpers.cs index 74944d8515..7bb56f7469 100644 --- a/src/Verify/IoHelpers.cs +++ b/src/Verify/IoHelpers.cs @@ -217,8 +217,12 @@ public static async Task WriteStream(string path, Stream stream) CreateDirectory(Path.GetDirectoryName(path)!); if (!TryCopyFileStream(path, stream)) { - await using var targetStream = OpenWrite(path); - await stream.SafeCopy(targetStream); + // keep using scope to stream is flushed + await using (var targetStream = OpenWrite(path)) + { + await stream.SafeCopy(targetStream); + } + HandleEmptyFile(path); } } @@ -236,8 +240,12 @@ public static async Task WriteStream(string path, Stream stream) CreateDirectory(Path.GetDirectoryName(path)); if (!TryCopyFileStream(path, stream)) { - using var targetStream = OpenWrite(path); - await stream.SafeCopy(targetStream); + // keep using scope to stream is flushed + using (var targetStream = OpenWrite(path)) + { + await stream.SafeCopy(targetStream); + } + HandleEmptyFile(path); } } @@ -248,7 +256,7 @@ static void HandleEmptyFile(string path) { if (new FileInfo(path).Length == 0) { - throw new("Empty data is not allowed."); + throw new($"Empty data is not allowed. Path: {path}"); } } } \ No newline at end of file