Nothing Special   »   [go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ShouldExist on file or directory based objects #896

Open
jeffkl opened this issue Apr 17, 2023 · 0 comments · May be fixed by #918
Open

Support ShouldExist on file or directory based objects #896

jeffkl opened this issue Apr 17, 2023 · 0 comments · May be fixed by #918

Comments

@jeffkl
Copy link
jeffkl commented Apr 17, 2023

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.

https://github.com/jeffkl/MSBuildProjectCreator/blob/8e0a219aa7025f8c0ade8d5e10c8e917b8b8d6b4/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/ExtensionMethods.cs#L10-L31

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();
@jeffkl jeffkl changed the title Support ShouldExists on file or directory based objects Support ShouldExist on file or directory based objects Apr 17, 2023
elhosayny pushed a commit to elhosayny/shouldly that referenced this issue Aug 12, 2023
Introduced new extension methods to enhance file system testing:
- `ShouldExist` for both FileInfo and DirectoryInfo.
- `ShouldNotExist` for both FileInfo and DirectoryInfo.

These methods provide a more intuitive way to assert the existence or
non-existence of files and directories.

Resolves shouldly#896
elhosayny added a commit to elhosayny/shouldly that referenced this issue Aug 12, 2023
Introduced new extension methods to enhance file system testing:
- `ShouldExist` for both FileInfo and DirectoryInfo.
- `ShouldNotExist` for both FileInfo and DirectoryInfo.

These methods provide a more intuitive way to assert the existence or
non-existence of files and directories.

Resolves shouldly#896
elhosayny added a commit to elhosayny/shouldly that referenced this issue Aug 16, 2023
Introduced new extension methods to enhance file system testing:
- `ShouldExist` for both FileInfo and DirectoryInfo.
- `ShouldNotExist` for both FileInfo and DirectoryInfo.

These methods provide a more intuitive way to assert the existence or
non-existence of files and directories.

Resolves shouldly#896
elhosayny added a commit to elhosayny/shouldly that referenced this issue Aug 16, 2023
Introduced new extension methods to enhance file system testing:
- `ShouldExist` for both FileInfo and DirectoryInfo.
- `ShouldNotExist` for both FileInfo and DirectoryInfo.

These methods provide a more intuitive way to assert the existence or
non-existence of files and directories.

Resolves shouldly#896
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants