Support ShouldExist on file or directory based objects
jeffkl opened this issue · comments
Some of my tests expect files to exist after calling something. I have extension methods for this but I would love it to be built in.
Calling fileInfo.Exists.ShouldBeTrue()
isn't helpful in my opinion. Having the file or directory path listed is much better.
public static FileInfo ShouldExist(this FileInfo fileInfo)
{
if (!fileInfo.Exists)
{
throw new ShouldAssertException($"The file \"{fileInfo.FullName}\" should exist but does not");
}
return fileInfo;
}
FileInfo fileInfo = new FileInfo("some path");
classUnderTest.MethodUnderTest(fileInfo);
fileInfo.ShouldExist();