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
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
8f3a2e6
Added FileVersionInfo support
Dec 16, 2024
6e407cd
- Implemented IFileVersionInfoFactory and moved the FileVersionInfo q…
Dec 16, 2024
4c569eb
Update tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/M…
t4m45 Dec 16, 2024
f4c4404
Update src/TestableIO.System.IO.Abstractions/IFileSystem.cs
t4m45 Dec 16, 2024
d68c667
Update tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/M…
Dec 16, 2024
8178f70
Typo fix
Dec 16, 2024
f240e1b
Changed the optional parameter handling of MockFileVersionInfo
Dec 16, 2024
7cfdca7
Fixed codacy errors "Use the overloading mechanism instead of the opt…
Dec 17, 2024
dd68ff2
Removed the static declarations from the FileVersionInfo factories.
Dec 17, 2024
2e6fa66
Implemented ProductVersionParser to mimick the behavior of the Assemb…
Dec 20, 2024
a8380f4
Bump version to 21.2
Dec 20, 2024
6628888
Removed the constructor overloads of MockFileVersionInfo and set the …
t4m45 Dec 21, 2024
5d8e168
fix for Codacy error: "Consider refactoring this method in order to r…
t4m45 Dec 21, 2024
eb509ac
Added an overload for the constructor of MockFileVersionInfo
t4m45 Dec 21, 2024
1f246a3
Revert "Added an overload for the constructor of MockFileVersionInfo"
t4m45 Dec 21, 2024
da9061e
Added FileVersionInfo support
Dec 16, 2024
c331fb6
- Implemented IFileVersionInfoFactory and moved the FileVersionInfo q…
Dec 16, 2024
b2a4ca9
Update tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/M…
t4m45 Dec 16, 2024
41b3d88
Update src/TestableIO.System.IO.Abstractions/IFileSystem.cs
t4m45 Dec 16, 2024
73b4285
Update tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/M…
Dec 16, 2024
4d5efbd
Typo fix
Dec 16, 2024
dfe0449
Changed the optional parameter handling of MockFileVersionInfo
Dec 16, 2024
dc49485
Fixed codacy errors "Use the overloading mechanism instead of the opt…
Dec 17, 2024
9feeb4e
Removed the static declarations from the FileVersionInfo factories.
Dec 17, 2024
c1e5520
Implemented ProductVersionParser to mimick the behavior of the Assemb…
Dec 20, 2024
0d92dbe
Bump version to 21.2
Dec 20, 2024
0e11ee4
Removed the constructor overloads of MockFileVersionInfo and set the …
t4m45 Dec 21, 2024
4282915
fix for Codacy error: "Consider refactoring this method in order to r…
t4m45 Dec 21, 2024
d661eb3
Added an overload for the constructor of MockFileVersionInfo
t4m45 Dec 21, 2024
6095538
Revert "Added an overload for the constructor of MockFileVersionInfo"
t4m45 Dec 21, 2024
4c06da3
Merge branch 'main' of https://github.com/t4m45/System.IO.Abstractions
t4m45 Dec 28, 2024
23bdeb4
Modified the accessibility modifier of ProductVersionParser to intern…
t4m45 Dec 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ public MockFileData(MockFileData template)
/// </summary>
public byte[] Contents { get; set; }

/// <summary>
/// Gets or sets the file version info of the <see cref="MockFileData"/>
/// </summary>
public IFileVersionInfo FileVersionInfo { get; set; }

/// <summary>
/// Gets or sets the string contents of the <see cref="MockFileData"/>.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public override void Encrypt()
var mockFileData = GetMockFileDataForWrite();
mockFileData.Attributes |= FileAttributes.Encrypted;
}

/// <inheritdoc />
public override void MoveTo(string destFileName)
{
Expand Down Expand Up @@ -323,7 +323,7 @@ public override IFileInfo Replace(string destinationFileName, string destination
mockFile.Replace(path, destinationFileName, destinationBackupFileName, ignoreMetadataErrors);
return mockFileSystem.FileInfo.New(destinationFileName);
}

/// <inheritdoc />
public override IDirectoryInfo Directory
{
Expand All @@ -333,6 +333,15 @@ public override IDirectoryInfo Directory
}
}

/// <inheritdoc />
public override IFileVersionInfo FileVersionInfo
{
get
{
return mockFileSystem.GetFile(path).FileVersionInfo;
}
}

/// <inheritdoc />
public override string DirectoryName
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ public void AddFile(string path, MockFileData mockFile)
AddDirectory(directoryPath);
}

mockFile.FileVersionInfo ??= new MockFileVersionInfo(fileName: fixedPath);

SetEntry(fixedPath, mockFile);
}

Expand Down Expand Up @@ -568,7 +570,7 @@ private bool FileIsReadOnly(string path)
}

#if FEATURE_SERIALIZABLE
[Serializable]
[Serializable]
#endif
private class FileSystemEntry
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;

namespace System.IO.Abstractions.TestingHelpers
{
/// <inheritdoc />
#if FEATURE_SERIALIZABLE
[Serializable]
#endif
public class MockFileVersionInfo : FileVersionInfoBase
{
/// <inheritdoc />
public MockFileVersionInfo(
[Optional] string comments,
[Optional] string companyName,
[Optional] int fileBuildPart,
[Optional] string fileDescription,
[Optional] int fileMajorPart,
[Optional] int fileMinorPart,
[Optional] string fileName,
[Optional] int filePrivatePart,
[Optional] string fileVersion,
[Optional] string internalName,
[Optional] bool isDebug,
[Optional] bool isPatched,
[Optional] bool isPrivateBuild,
[Optional] bool isPreRelease,
[Optional] bool isSpecialBuild,
[Optional] string language,
[Optional] string legalCopyright,
[Optional] string legalTrademarks,
[Optional] string originalFilename,
[Optional] string privateBuild,
[Optional] int productBuildPart,
[Optional] int productMajorPart,
[Optional] int productMinorPart,
[Optional] string productName,
[Optional] int productPrivatePart,
[Optional] string productVersion,
[Optional] string specialBuild)
{
Comments = comments;
CompanyName = companyName;
FileBuildPart = fileBuildPart;
FileDescription = fileDescription;
FileMajorPart = fileMajorPart;
FileMinorPart = fileMinorPart;
FileName = fileName;
FilePrivatePart = filePrivatePart;
FileVersion = fileVersion;
InternalName = internalName;
IsDebug = isDebug;
IsPatched = isPatched;
IsPrivateBuild = isPrivateBuild;
IsPreRelease = isPreRelease;
IsSpecialBuild = isSpecialBuild;
Language = language;
LegalCopyright = legalCopyright;
LegalTrademarks = legalTrademarks;
OriginalFilename = originalFilename;
PrivateBuild = privateBuild;
ProductBuildPart = productBuildPart;
ProductMajorPart = productMajorPart;
ProductMinorPart = productMinorPart;
ProductName = productName;
ProductPrivatePart = productPrivatePart;
ProductVersion = productVersion;
SpecialBuild = specialBuild;
}

/// <inheritdoc/>
public override string Comments { get; }

/// <inheritdoc/>
public override string CompanyName { get; }

/// <inheritdoc/>
public override int FileBuildPart { get; }

/// <inheritdoc/>
public override string FileDescription { get; }

/// <inheritdoc/>
public override int FileMajorPart { get; }

/// <inheritdoc/>
public override int FileMinorPart { get; }

/// <inheritdoc/>
public override string FileName { get; }

/// <inheritdoc/>
public override int FilePrivatePart { get; }

/// <inheritdoc/>
public override string FileVersion { get; }

/// <inheritdoc/>
public override string InternalName { get; }

/// <inheritdoc/>
public override bool IsDebug { get; }

/// <inheritdoc/>
public override bool IsPatched { get; }

/// <inheritdoc/>
public override bool IsPrivateBuild { get; }

/// <inheritdoc/>
public override bool IsPreRelease { get; }

/// <inheritdoc/>
public override bool IsSpecialBuild { get; }

/// <inheritdoc/>
public override string Language { get; }

/// <inheritdoc/>
public override string LegalCopyright { get; }

/// <inheritdoc/>
public override string LegalTrademarks { get; }

/// <inheritdoc/>
public override string OriginalFilename { get; }

/// <inheritdoc/>
public override string PrivateBuild { get; }

/// <inheritdoc/>
public override int ProductBuildPart { get; }

/// <inheritdoc/>
public override int ProductMajorPart { get; }

/// <inheritdoc/>
public override int ProductMinorPart { get; }

/// <inheritdoc/>
public override string ProductName { get; }

/// <inheritdoc/>
public override int ProductPrivatePart { get; }

/// <inheritdoc/>
public override string ProductVersion { get; }

/// <inheritdoc/>
public override string SpecialBuild { get; }

/// <inheritdoc cref="FileVersionInfo.ToString" />
public override string ToString()
{
// An initial capacity of 512 was chosen because it is large enough to cover
// the size of the static strings with enough capacity left over to cover
// average length property values.
var sb = new StringBuilder(512);
sb.Append("File: ").AppendLine(FileName);
sb.Append("InternalName: ").AppendLine(InternalName);
sb.Append("OriginalFilename: ").AppendLine(OriginalFilename);
sb.Append("FileVersion: ").AppendLine(FileVersion);
sb.Append("FileDescription: ").AppendLine(FileDescription);
sb.Append("Product: ").AppendLine(ProductName);
sb.Append("ProductVersion: ").AppendLine(ProductVersion);
sb.Append("Debug: ").AppendLine(IsDebug.ToString());
sb.Append("Patched: ").AppendLine(IsPatched.ToString());
sb.Append("PreRelease: ").AppendLine(IsPreRelease.ToString());
sb.Append("PrivateBuild: ").AppendLine(IsPrivateBuild.ToString());
sb.Append("SpecialBuild: ").AppendLine(IsSpecialBuild.ToString());
sb.Append("Language: ").AppendLine(Language);
return sb.ToString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal FileInfoBase() { }

/// <inheritdoc cref="IFileInfo.Encrypt"/>
public abstract void Encrypt();

/// <inheritdoc cref="IFileInfo.MoveTo(string)"/>
public abstract void MoveTo(string destFileName);

Expand Down Expand Up @@ -73,10 +73,13 @@ internal FileInfoBase() { }

/// <inheritdoc cref="IFileInfo.Replace(string,string,bool)"/>
public abstract IFileInfo Replace(string destinationFileName, string destinationBackupFileName, bool ignoreMetadataErrors);

/// <inheritdoc cref="IFileInfo.Directory"/>
public abstract IDirectoryInfo Directory { get; }

/// <inheritdoc cref="IFileVersionInfo"/>
public abstract IFileVersionInfo FileVersionInfo { get; }

/// <inheritdoc cref="IFileInfo.DirectoryName"/>
public abstract string DirectoryName { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,12 @@ public override IDirectoryInfo Directory
get { return new DirectoryInfoWrapper(FileSystem, instance.Directory); }
}

/// <inheritdoc />
public override IFileVersionInfo FileVersionInfo
{
get { return new FileVersionInfoWrapper(Diagnostics.FileVersionInfo.GetVersionInfo(FullName)); }
}

/// <inheritdoc />
public override string DirectoryName
{
Expand Down
106 changes: 106 additions & 0 deletions src/TestableIO.System.IO.Abstractions.Wrappers/FileVersionInfoBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
using System.Diagnostics;

namespace System.IO.Abstractions
{
/// <inheritdoc cref="IFileVersionInfo"/>
#if FEATURE_SERIALIZABLE
[Serializable]
#endif
public abstract class FileVersionInfoBase : IFileVersionInfo
{
/// <inheritdoc cref="IFileVersionInfo.Comments" />
public abstract string Comments { get; }

/// <inheritdoc cref="IFileVersionInfo.CompanyName" />
public abstract string CompanyName { get; }

/// <inheritdoc cref="IFileVersionInfo.FileBuildPart" />
public abstract int FileBuildPart { get; }

/// <inheritdoc cref="IFileVersionInfo.FileDescription" />
public abstract string FileDescription { get; }

/// <inheritdoc cref="IFileVersionInfo.FileMajorPart" />
public abstract int FileMajorPart { get; }

/// <inheritdoc cref="IFileVersionInfo.FileMinorPart" />
public abstract int FileMinorPart { get; }

/// <inheritdoc cref="IFileVersionInfo.FileName" />
public abstract string FileName { get; }

/// <inheritdoc cref="IFileVersionInfo.FilePrivatePart" />
public abstract int FilePrivatePart { get; }

/// <inheritdoc cref="IFileVersionInfo.FileVersion" />
public abstract string FileVersion { get; }

/// <inheritdoc cref="IFileVersionInfo.InternalName" />
public abstract string InternalName { get; }

/// <inheritdoc cref="IFileVersionInfo.IsDebug" />
public abstract bool IsDebug { get; }

/// <inheritdoc cref="IFileVersionInfo.IsPatched" />
public abstract bool IsPatched { get; }

/// <inheritdoc cref="IFileVersionInfo.IsPrivateBuild" />
public abstract bool IsPrivateBuild { get; }

/// <inheritdoc cref="IFileVersionInfo.IsPreRelease" />
public abstract bool IsPreRelease { get; }

/// <inheritdoc cref="IFileVersionInfo.IsSpecialBuild" />
public abstract bool IsSpecialBuild { get; }

/// <inheritdoc cref="IFileVersionInfo.Language" />
public abstract string Language { get; }

/// <inheritdoc cref="IFileVersionInfo.LegalCopyright" />
public abstract string LegalCopyright { get; }

/// <inheritdoc cref="IFileVersionInfo.LegalTrademarks" />
public abstract string LegalTrademarks { get; }

/// <inheritdoc cref="IFileVersionInfo.OriginalFilename" />
public abstract string OriginalFilename { get; }

/// <inheritdoc cref="IFileVersionInfo.PrivateBuild" />
public abstract string PrivateBuild { get; }

/// <inheritdoc cref="IFileVersionInfo.ProductBuildPart" />
public abstract int ProductBuildPart { get; }

/// <inheritdoc cref="IFileVersionInfo.ProductMajorPart" />
public abstract int ProductMajorPart { get; }

/// <inheritdoc cref="IFileVersionInfo.ProductMinorPart" />
public abstract int ProductMinorPart { get; }

/// <inheritdoc cref="IFileVersionInfo.ProductName" />
public abstract string ProductName { get; }

/// <inheritdoc cref="IFileVersionInfo.ProductPrivatePart" />
public abstract int ProductPrivatePart { get; }

/// <inheritdoc cref="IFileVersionInfo.ProductVersion" />
public abstract string ProductVersion { get; }

/// <inheritdoc cref="IFileVersionInfo.SpecialBuild" />
public abstract string SpecialBuild { get; }

/// <inheritdoc />
public static implicit operator FileVersionInfoBase(FileVersionInfo fileVersionInfo)
{
if (fileVersionInfo == null)
{
return null;
}

return new FileVersionInfoWrapper(fileVersionInfo);
}

/// <inheritdoc />
public new abstract string ToString();
}
}
Loading
Loading