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

feat: Add FileVersionInfo support #1177

Merged
merged 32 commits into from
Dec 28, 2024
Merged

feat: Add FileVersionInfo support #1177

merged 32 commits into from
Dec 28, 2024

Conversation

t4m45
Copy link
Contributor

@t4m45 t4m45 commented Dec 16, 2024

Added a wrapper for the immutable FileVersionInfo.

For testing, the IFileVersionInfo can be stored in the MockFileData as a property.
Since testing it is rarely neccessary, I didn't add a constructor for it but it's a mutable property, so it can be set anytime after initialization.
A MockFileVersionInfo has also been added which is mutable.

In a normal scenario, the FileVersionInfo can be accessed through the FileVersionInfo property of IFileInfo.

The MockFileSystem's AddFile method will initialize this version if it's null, and the values will be the default (Only it's FileName will be set).

Since the System.IO.FileInfo does not contain a FileVersionInfo property, I excluded it from the ApiParityTests

PS.: Sorry, seems like were some auto formats on my side which removed some extra spaces and the Visual Studio's Diff viewer did not show these before commit. I'm not really familiar with github, thats why I didn't try to revert them after commit.

@t4m45 t4m45 changed the title Add FileVersionInfo support feat: Add FileVersionInfo support Dec 16, 2024
Copy link
Member

@vbreuss vbreuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for suggesting this change, @t4m45!

While I do like the idea of adding support for FileVersionInfo, I don't like adding it to the IFileInfo interface, as this is different to the public API.

Instead I would suggest adding a IFileInfoFactory to the IFileSystem with a static method GetVersionInfo(string) which returns an instance of IFileInfo. This way you could use it as follows:

// Instead of
FileVersionInfo version = FileVersionInfo.GetVersionInfo("my-library.dll");
// you can use
MockFileSystem fileSystem = new();
IFileVersionInfo version = fileSystem.FileVersionInfo.GetVersionInfo("my-library.dll");

This works the same way as the existing API. You could then adapt the parity tests, to also verify, that the interface IFileVersionInfo matches FileVersionInfo.

Would you be willing to adapt your pull request as suggested?

@t4m45
Copy link
Contributor Author

t4m45 commented Dec 16, 2024

Hello @vbreuss!

Just for clarity, in the sentence "I would suggest adding a IFileInfoFactory to the IFileSystem with a static method GetVersionInfo(string) which returns an instance of IFileInfo"

Did you mean 'IFileVersionInfoFactory' and 'IFileVersionInfo' instead of 'IFileInfoFactory' and 'IFileInfo'?

@t4m45
Copy link
Contributor Author

t4m45 commented Dec 16, 2024

Also, since I'm not really familiar with Github, can you please help me how can I change my pull request?
After changing the code in my fork, what should I do?

Thanks.

…uery from IFileInfo to IFileSystem

- Added a missing API test for the parity test of IFileVersionInfo and FileVersionInfo
@t4m45
Copy link
Contributor Author

t4m45 commented Dec 16, 2024

I implemented the factory you asked for, and removed the FileVersionInfo from IFileInfo.

Copy link
Member

@vbreuss vbreuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though I have some comments, I am impressed by the overall approach; great work!

t4m45 and others added 6 commits December 16, 2024 19:44
…ockFileSystemTests.cs

Co-authored-by: Valentin Breuß <vbreuss@gmail.com>
Co-authored-by: Valentin Breuß <vbreuss@gmail.com>
Major,Minor,Build and Private versions will be calculated from FileVersion and ProductVersion
Added tests for the version parsing
Converted the expected string to verbatim string
…ional parameters."

Reordered the parameters and the properties for convenience
@t4m45
Copy link
Contributor Author

t4m45 commented Dec 17, 2024

When it comes to the MockFileVersionInfoFactory, I'm not sure how to fix the issue reported by Codacy: "Remove this assignment of 'mockFileSystem' or initialize it statically."

If you're okay with it, I can remove the constructor, create a static method called SetFileDataAccessor, and inject it that way.
But if you have another idea, I'm all ears.

@vbreuss
Copy link
Member

vbreuss commented Dec 17, 2024

When it comes to the MockFileVersionInfoFactory, I'm not sure how to fix the issue reported by Codacy: "Remove this assignment of 'mockFileSystem' or initialize it statically."

If you're okay with it, I can remove the constructor, create a static method called SetFileDataAccessor, and inject it that way. But if you have another idea, I'm all ears.

You should not use a static field in the MockFileVersionInfoFactory.
If you make the following changes, it should build without errors:
image

I will have a more in-depth look at the pull request after christmas...

@t4m45
Copy link
Contributor Author

t4m45 commented Dec 17, 2024

You should not use a static field in the MockFileVersionInfoFactory. If you make the following changes, it should build without errors: image

Well, I know that. The only reason I made the method static is because thats what you asked for.

Instead I would suggest adding a IFileInfoFactory to the IFileSystem with a static method GetVersionInfo(string) which returns an instance of IFileInfo.

But I will change it then.

By the way, every mock factory uses the interface IMockFileDataAccessor instead of the MockFileSystem implementation, so I think it's better I'm not changing the type. I'll only remove the static declarations.

@t4m45 t4m45 requested a review from vbreuss December 17, 2024 17:07
@vbreuss
Copy link
Member

vbreuss commented Dec 17, 2024

Well, I know that. The only reason I made the method static is because thats what you asked for.

Sorry, that was misleading by me. I meant, that you should mimick the static method in the System.Diagnostics namespace the same way we mimick the static File methods (by instance methods on a factory class)...

Copy link
Member

@vbreuss vbreuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have only found some minor comments.
Please also update the version in version.json to "21.2".

Kormos Tamás added 2 commits December 28, 2024 18:23
…uery from IFileInfo to IFileSystem

- Added a missing API test for the parity test of IFileVersionInfo and FileVersionInfo
t4m45 and others added 13 commits December 28, 2024 18:23
…ockFileSystemTests.cs

Co-authored-by: Valentin Breuß <vbreuss@gmail.com>
Co-authored-by: Valentin Breuß <vbreuss@gmail.com>
Major,Minor,Build and Private versions will be calculated from FileVersion and ProductVersion
Added tests for the version parsing
Converted the expected string to verbatim string
…ional parameters."

Reordered the parameters and the properties for convenience
…lyInformationalVersion attribute.

Added Version.TryParse to the FileVersion parsing for a similar reason.
Copy link
Member

@vbreuss vbreuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks a lot!

@t4m45
Copy link
Contributor Author

t4m45 commented Dec 28, 2024

Awesome! Thank you for the help!

@mergify mergify bot merged commit ce67de2 into TestableIO:main Dec 28, 2024
8 checks passed
Copy link

This is addressed in release v21.2.1.

@github-actions github-actions bot added the state: released Issues that are released label Dec 28, 2024
vbreuss added a commit to Testably/Testably.Abstractions that referenced this pull request Jan 9, 2025
Support for `FileVersionInfo` was added in TestableIO/System.IO.Abstractions#1177. Add basic support for the updated interfaces.
*It is not yet possible to influence the mocked `IFileVersionInfo` in any way...*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state: released Issues that are released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants