@@ -12,43 +12,30 @@ public class MockFileVersionInfo : FileVersionInfoBase
1212 {
1313 /// <inheritdoc />
1414 public MockFileVersionInfo (
15- [ Optional ] string comments ,
16- [ Optional ] string companyName ,
17- [ Optional ] int fileBuildPart ,
18- [ Optional ] string fileDescription ,
19- [ Optional ] int fileMajorPart ,
20- [ Optional ] int fileMinorPart ,
21- [ Optional ] string fileName ,
22- [ Optional ] int filePrivatePart ,
23- [ Optional ] string fileVersion ,
24- [ Optional ] string internalName ,
25- [ Optional ] bool isDebug ,
26- [ Optional ] bool isPatched ,
27- [ Optional ] bool isPrivateBuild ,
28- [ Optional ] bool isPreRelease ,
29- [ Optional ] bool isSpecialBuild ,
30- [ Optional ] string language ,
31- [ Optional ] string legalCopyright ,
32- [ Optional ] string legalTrademarks ,
33- [ Optional ] string originalFilename ,
34- [ Optional ] string privateBuild ,
35- [ Optional ] int productBuildPart ,
36- [ Optional ] int productMajorPart ,
37- [ Optional ] int productMinorPart ,
38- [ Optional ] string productName ,
39- [ Optional ] int productPrivatePart ,
40- [ Optional ] string productVersion ,
41- [ Optional ] string specialBuild )
15+ string comments = null ,
16+ string companyName = null ,
17+ string fileDescription = null ,
18+ string fileName = null ,
19+ string fileVersion = null ,
20+ string internalName = null ,
21+ bool isDebug = false ,
22+ bool isPatched = false ,
23+ bool isPrivateBuild = false ,
24+ bool isPreRelease = false ,
25+ bool isSpecialBuild = false ,
26+ string language = null ,
27+ string legalCopyright = null ,
28+ string legalTrademarks = null ,
29+ string originalFilename = null ,
30+ string privateBuild = null ,
31+ string productName = null ,
32+ string productVersion = null ,
33+ string specialBuild = null )
4234 {
4335 Comments = comments ;
4436 CompanyName = companyName ;
45- FileBuildPart = fileBuildPart ;
4637 FileDescription = fileDescription ;
47- FileMajorPart = fileMajorPart ;
48- FileMinorPart = fileMinorPart ;
4938 FileName = fileName ;
50- FilePrivatePart = filePrivatePart ;
51- FileVersion = fileVersion ;
5239 InternalName = internalName ;
5340 IsDebug = isDebug ;
5441 IsPatched = isPatched ;
@@ -60,95 +47,195 @@ public MockFileVersionInfo(
6047 LegalTrademarks = legalTrademarks ;
6148 OriginalFilename = originalFilename ;
6249 PrivateBuild = privateBuild ;
63- ProductBuildPart = productBuildPart ;
64- ProductMajorPart = productMajorPart ;
65- ProductMinorPart = productMinorPart ;
6650 ProductName = productName ;
67- ProductPrivatePart = productPrivatePart ;
68- ProductVersion = productVersion ;
6951 SpecialBuild = specialBuild ;
52+
53+ if ( fileVersion != null )
54+ {
55+ ParseVersion ( fileVersion , out int fileMajor , out int fileMinor , out int fileBuild , out int filePrivate ) ;
56+ FileMajorPart = fileMajor ;
57+ FileMinorPart = fileMinor ;
58+ FileBuildPart = fileBuild ;
59+ FilePrivatePart = filePrivate ;
60+ }
61+
62+ if ( productVersion != null )
63+ {
64+ ParseVersion ( productVersion , out int productMajor , out int productMinor , out int productBuild , out int productPrivate ) ;
65+ ProductMajorPart = productMajor ;
66+ ProductMinorPart = productMinor ;
67+ ProductBuildPart = productBuild ;
68+ ProductPrivatePart = productPrivate ;
69+ }
7070 }
7171
7272 /// <inheritdoc/>
73- public override string Comments { get ; }
73+ public override string Comments
74+ {
75+ get ;
76+ }
7477
7578 /// <inheritdoc/>
76- public override string CompanyName { get ; }
79+ public override string CompanyName
80+ {
81+ get ;
82+ }
7783
7884 /// <inheritdoc/>
79- public override int FileBuildPart { get ; }
85+ public override int FileBuildPart
86+ {
87+ get ;
88+ }
8089
8190 /// <inheritdoc/>
82- public override string FileDescription { get ; }
91+ public override string FileDescription
92+ {
93+ get ;
94+ }
8395
8496 /// <inheritdoc/>
85- public override int FileMajorPart { get ; }
97+ public override int FileMajorPart
98+ {
99+ get ;
100+ }
86101
87102 /// <inheritdoc/>
88- public override int FileMinorPart { get ; }
103+ public override int FileMinorPart
104+ {
105+ get ;
106+ }
89107
90108 /// <inheritdoc/>
91- public override string FileName { get ; }
109+ public override string FileName
110+ {
111+ get ;
112+ }
92113
93114 /// <inheritdoc/>
94- public override int FilePrivatePart { get ; }
115+ public override int FilePrivatePart
116+ {
117+ get ;
118+ }
95119
96120 /// <inheritdoc/>
97- public override string FileVersion { get ; }
121+ public override string FileVersion
122+ {
123+ get
124+ {
125+ return $ "{ FileMajorPart } .{ FileMinorPart } .{ FileBuildPart } .{ FilePrivatePart } ";
126+ }
127+ }
98128
99129 /// <inheritdoc/>
100- public override string InternalName { get ; }
130+ public override string InternalName
131+ {
132+ get ;
133+ }
101134
102135 /// <inheritdoc/>
103- public override bool IsDebug { get ; }
136+ public override bool IsDebug
137+ {
138+ get ;
139+ }
104140
105141 /// <inheritdoc/>
106- public override bool IsPatched { get ; }
142+ public override bool IsPatched
143+ {
144+ get ;
145+ }
107146
108147 /// <inheritdoc/>
109- public override bool IsPrivateBuild { get ; }
148+ public override bool IsPrivateBuild
149+ {
150+ get ;
151+ }
110152
111153 /// <inheritdoc/>
112- public override bool IsPreRelease { get ; }
154+ public override bool IsPreRelease
155+ {
156+ get ;
157+ }
113158
114159 /// <inheritdoc/>
115- public override bool IsSpecialBuild { get ; }
160+ public override bool IsSpecialBuild
161+ {
162+ get ;
163+ }
116164
117165 /// <inheritdoc/>
118- public override string Language { get ; }
166+ public override string Language
167+ {
168+ get ;
169+ }
119170
120171 /// <inheritdoc/>
121- public override string LegalCopyright { get ; }
172+ public override string LegalCopyright
173+ {
174+ get ;
175+ }
122176
123177 /// <inheritdoc/>
124- public override string LegalTrademarks { get ; }
178+ public override string LegalTrademarks
179+ {
180+ get ;
181+ }
125182
126183 /// <inheritdoc/>
127- public override string OriginalFilename { get ; }
184+ public override string OriginalFilename
185+ {
186+ get ;
187+ }
128188
129189 /// <inheritdoc/>
130- public override string PrivateBuild { get ; }
190+ public override string PrivateBuild
191+ {
192+ get ;
193+ }
131194
132195 /// <inheritdoc/>
133- public override int ProductBuildPart { get ; }
196+ public override int ProductBuildPart
197+ {
198+ get ;
199+ }
134200
135201 /// <inheritdoc/>
136- public override int ProductMajorPart { get ; }
202+ public override int ProductMajorPart
203+ {
204+ get ;
205+ }
137206
138207 /// <inheritdoc/>
139- public override int ProductMinorPart { get ; }
208+ public override int ProductMinorPart
209+ {
210+ get ;
211+ }
140212
141213 /// <inheritdoc/>
142- public override string ProductName { get ; }
214+ public override string ProductName
215+ {
216+ get ;
217+ }
143218
144219 /// <inheritdoc/>
145- public override int ProductPrivatePart { get ; }
220+ public override int ProductPrivatePart
221+ {
222+ get ;
223+ }
146224
147225 /// <inheritdoc/>
148- public override string ProductVersion { get ; }
226+ public override string ProductVersion
227+ {
228+ get
229+ {
230+ return $ "{ ProductMajorPart } .{ ProductMinorPart } .{ ProductBuildPart } .{ ProductPrivatePart } ";
231+ }
232+ }
149233
150234 /// <inheritdoc/>
151- public override string SpecialBuild { get ; }
235+ public override string SpecialBuild
236+ {
237+ get ;
238+ }
152239
153240 /// <inheritdoc cref="FileVersionInfo.ToString" />
154241 public override string ToString ( )
@@ -172,5 +259,22 @@ public override string ToString()
172259 sb . Append ( "Language: " ) . AppendLine ( Language ) ;
173260 return sb . ToString ( ) ;
174261 }
262+
263+ private static void ParseVersion ( string version , out int major , out int minor , out int build , out int revision )
264+ {
265+ var parts = version . Split ( '.' ) ;
266+ if ( parts . Length != 4 )
267+ {
268+ throw new FormatException ( "Version string must have the format 'major.minor.build.revision'." ) ;
269+ }
270+
271+ if ( ! int . TryParse ( parts [ 0 ] , out major ) ||
272+ ! int . TryParse ( parts [ 1 ] , out minor ) ||
273+ ! int . TryParse ( parts [ 2 ] , out build ) ||
274+ ! int . TryParse ( parts [ 3 ] , out revision ) )
275+ {
276+ throw new FormatException ( "Version parts must be numeric." ) ;
277+ }
278+ }
175279 }
176280}
0 commit comments