|
| 1 | +using System.Diagnostics; |
| 2 | +using System.Text; |
| 3 | + |
| 4 | +namespace System.IO.Abstractions.TestingHelpers |
| 5 | +{ |
| 6 | + /// <inheritdoc /> |
| 7 | +#if FEATURE_SERIALIZABLE |
| 8 | + [Serializable] |
| 9 | +#endif |
| 10 | + public class MockFileVersionInfo : FileVersionInfoBase |
| 11 | + { |
| 12 | + /// <inheritdoc /> |
| 13 | + public MockFileVersionInfo( |
| 14 | + string fileName, |
| 15 | + string fileVersion = null, |
| 16 | + string productVersion = null, |
| 17 | + string fileDescription = null, |
| 18 | + string productName = null, |
| 19 | + string companyName = null, |
| 20 | + string comments = null, |
| 21 | + string internalName = null, |
| 22 | + bool isDebug = false, |
| 23 | + bool isPatched = false, |
| 24 | + bool isPrivateBuild = false, |
| 25 | + bool isPreRelease = false, |
| 26 | + bool isSpecialBuild = false, |
| 27 | + string language = null, |
| 28 | + string legalCopyright = null, |
| 29 | + string legalTrademarks = null, |
| 30 | + string originalFilename = null, |
| 31 | + string privateBuild = null, |
| 32 | + string specialBuild = null) |
| 33 | + { |
| 34 | + FileName = fileName; |
| 35 | + FileVersion = fileVersion; |
| 36 | + ProductVersion = productVersion; |
| 37 | + FileDescription = fileDescription; |
| 38 | + ProductName = productName; |
| 39 | + CompanyName = companyName; |
| 40 | + Comments = comments; |
| 41 | + InternalName = internalName; |
| 42 | + IsDebug = isDebug; |
| 43 | + IsPatched = isPatched; |
| 44 | + IsPrivateBuild = isPrivateBuild; |
| 45 | + IsPreRelease = isPreRelease; |
| 46 | + IsSpecialBuild = isSpecialBuild; |
| 47 | + Language = language; |
| 48 | + LegalCopyright = legalCopyright; |
| 49 | + LegalTrademarks = legalTrademarks; |
| 50 | + OriginalFilename = originalFilename; |
| 51 | + PrivateBuild = privateBuild; |
| 52 | + SpecialBuild = specialBuild; |
| 53 | + |
| 54 | + if (Version.TryParse(fileVersion, out Version version)) |
| 55 | + { |
| 56 | + FileMajorPart = version.Major; |
| 57 | + FileMinorPart = version.Minor; |
| 58 | + FileBuildPart = version.Build; |
| 59 | + FilePrivatePart = version.Revision; |
| 60 | + } |
| 61 | + |
| 62 | + var parsedProductVersion = ProductVersionParser.Parse(productVersion); |
| 63 | + |
| 64 | + ProductMajorPart = parsedProductVersion.Major; |
| 65 | + ProductMinorPart = parsedProductVersion.Minor; |
| 66 | + ProductBuildPart = parsedProductVersion.Build; |
| 67 | + ProductPrivatePart = parsedProductVersion.PrivatePart; |
| 68 | + } |
| 69 | + |
| 70 | + /// <inheritdoc/> |
| 71 | + public override string FileName { get; } |
| 72 | + |
| 73 | + /// <inheritdoc/> |
| 74 | + public override string FileVersion { get; } |
| 75 | + |
| 76 | + /// <inheritdoc/> |
| 77 | + public override string ProductVersion { get; } |
| 78 | + |
| 79 | + /// <inheritdoc/> |
| 80 | + public override string FileDescription { get; } |
| 81 | + |
| 82 | + /// <inheritdoc/> |
| 83 | + public override string ProductName { get; } |
| 84 | + |
| 85 | + /// <inheritdoc/> |
| 86 | + public override string CompanyName { get; } |
| 87 | + |
| 88 | + /// <inheritdoc/> |
| 89 | + public override string Comments { get; } |
| 90 | + |
| 91 | + /// <inheritdoc/> |
| 92 | + public override string InternalName { get; } |
| 93 | + |
| 94 | + /// <inheritdoc/> |
| 95 | + public override bool IsDebug { get; } |
| 96 | + |
| 97 | + /// <inheritdoc/> |
| 98 | + public override bool IsPatched { get; } |
| 99 | + |
| 100 | + /// <inheritdoc/> |
| 101 | + public override bool IsPrivateBuild { get; } |
| 102 | + |
| 103 | + /// <inheritdoc/> |
| 104 | + public override bool IsPreRelease { get; } |
| 105 | + |
| 106 | + /// <inheritdoc/> |
| 107 | + public override bool IsSpecialBuild { get; } |
| 108 | + |
| 109 | + /// <inheritdoc/> |
| 110 | + public override string Language { get; } |
| 111 | + |
| 112 | + /// <inheritdoc/> |
| 113 | + public override string LegalCopyright { get; } |
| 114 | + |
| 115 | + /// <inheritdoc/> |
| 116 | + public override string LegalTrademarks { get; } |
| 117 | + |
| 118 | + /// <inheritdoc/> |
| 119 | + public override string OriginalFilename { get; } |
| 120 | + |
| 121 | + /// <inheritdoc/> |
| 122 | + public override string PrivateBuild { get; } |
| 123 | + |
| 124 | + /// <inheritdoc/> |
| 125 | + public override string SpecialBuild { get; } |
| 126 | + |
| 127 | + /// <inheritdoc/> |
| 128 | + public override int FileMajorPart { get; } |
| 129 | + |
| 130 | + /// <inheritdoc/> |
| 131 | + public override int FileMinorPart { get; } |
| 132 | + |
| 133 | + /// <inheritdoc/> |
| 134 | + public override int FileBuildPart { get; } |
| 135 | + |
| 136 | + /// <inheritdoc/> |
| 137 | + public override int FilePrivatePart { get; } |
| 138 | + |
| 139 | + /// <inheritdoc/> |
| 140 | + public override int ProductMajorPart { get; } |
| 141 | + |
| 142 | + /// <inheritdoc/> |
| 143 | + public override int ProductMinorPart { get; } |
| 144 | + |
| 145 | + /// <inheritdoc/> |
| 146 | + public override int ProductBuildPart { get; } |
| 147 | + |
| 148 | + /// <inheritdoc/> |
| 149 | + public override int ProductPrivatePart { get; } |
| 150 | + |
| 151 | + /// <inheritdoc cref="FileVersionInfo.ToString" /> |
| 152 | + public override string ToString() |
| 153 | + { |
| 154 | + // An initial capacity of 512 was chosen because it is large enough to cover |
| 155 | + // the size of the static strings with enough capacity left over to cover |
| 156 | + // average length property values. |
| 157 | + var sb = new StringBuilder(512); |
| 158 | + sb.Append("File: ").AppendLine(FileName); |
| 159 | + sb.Append("InternalName: ").AppendLine(InternalName); |
| 160 | + sb.Append("OriginalFilename: ").AppendLine(OriginalFilename); |
| 161 | + sb.Append("FileVersion: ").AppendLine(FileVersion); |
| 162 | + sb.Append("FileDescription: ").AppendLine(FileDescription); |
| 163 | + sb.Append("Product: ").AppendLine(ProductName); |
| 164 | + sb.Append("ProductVersion: ").AppendLine(ProductVersion); |
| 165 | + sb.Append("Debug: ").AppendLine(IsDebug.ToString()); |
| 166 | + sb.Append("Patched: ").AppendLine(IsPatched.ToString()); |
| 167 | + sb.Append("PreRelease: ").AppendLine(IsPreRelease.ToString()); |
| 168 | + sb.Append("PrivateBuild: ").AppendLine(IsPrivateBuild.ToString()); |
| 169 | + sb.Append("SpecialBuild: ").AppendLine(IsSpecialBuild.ToString()); |
| 170 | + sb.Append("Language: ").AppendLine(Language); |
| 171 | + return sb.ToString(); |
| 172 | + } |
| 173 | + } |
| 174 | +} |
0 commit comments