Skip to main content

FileVersionInfo

fileSystem.FileVersionInfo.GetVersionInfo(path) mirrors System.Diagnostics.FileVersionInfo.GetVersionInfo. On the mock, the returned IFileVersionInfo has every field set to null/false by default, since the in-memory file has no PE header.

To make a version-info-driven test deterministic, register a builder against a glob pattern with MockFileSystem.WithFileVersionInfo(...):

MockFileSystem fileSystem = new();
fileSystem.WithFileVersionInfo("*.dll", v => v
.SetCompanyName("Acme")
.SetProductName("Acme Widgets")
.SetProductVersion("1.2.3.4")
.SetFileVersion("1.2.3.0")
.SetIsDebug(false));

fileSystem.File.WriteAllText("Acme.Widgets.dll", "");

IFileVersionInfo info = fileSystem.FileVersionInfo.GetVersionInfo("Acme.Widgets.dll");
await Expect.That(info.CompanyName).IsEqualTo("Acme");
await Expect.That(info.ProductVersion).IsEqualTo("1.2.3.4");

The glob pattern is matched against the file path; the first matching registration wins. The builder exposes a setter for every field on IFileVersionInfo: Comments, CompanyName, FileDescription, FileVersion, InternalName, IsDebug, IsPatched, IsPreRelease, IsPrivateBuild, IsSpecialBuild, Language, LegalCopyright, LegalTrademarks, OriginalFilename, PrivateBuild, ProductName, ProductVersion, SpecialBuild.