Skip to content

Commit

Permalink
refactor: cleanup temporary file created in unit test (#600)
Browse files Browse the repository at this point in the history
In the `Method_Wrap_FileStream_ShouldRegisterCall` test, in order to get a valid `FileStream` a temporary test file has to be created on the real file system.
This file should be cleaned up after the test execution is finished.
  • Loading branch information
vbreuss committed May 13, 2024
1 parent 64be166 commit 223504f
Showing 1 changed file with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,21 +189,29 @@ public void Method_New_String_FileStreamOptions_ShouldRegisterCall()
[SkippableFact]
public void Method_Wrap_FileStream_ShouldRegisterCall()
{
string path = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
MockFileSystem sut = new();
FileStream fileStream = new("foo", FileMode.OpenOrCreate);

try
{
using FileSystemStream result = sut.FileStream.Wrap(fileStream);
using FileStream fileStream = new(path, FileMode.OpenOrCreate);

try
{
using FileSystemStream result = sut.FileStream.Wrap(fileStream);
}
catch (NotSupportedException)
{
// Wrap is not possible on the MockFileSystem, but should still be registered!
}

sut.StatisticsRegistration.TotalCount.Should().Be(1);
sut.Statistics.FileStream.ShouldOnlyContainMethodCall(nameof(IFileStreamFactory.Wrap),
fileStream);
}
catch (NotSupportedException)
finally
{
// Wrap is not possible on the MockFileSystem, but should still be registered!
File.Delete(path);
}

sut.StatisticsRegistration.TotalCount.Should().Be(1);
sut.Statistics.FileStream.ShouldOnlyContainMethodCall(nameof(IFileStreamFactory.Wrap),
fileStream);
}

[SkippableFact]
Expand Down

0 comments on commit 223504f

Please sign in to comment.