44using System . Diagnostics ;
55using System . Linq ;
66using System . IO ;
7- using Microsoft . VisualStudio . TestTools . UnitTesting ;
7+ using NUnit . Framework ;
88using Datamodel ;
99using System . Numerics ;
1010using DM = Datamodel . Datamodel ;
@@ -37,13 +37,19 @@ static DatamodelTests()
3737 TestValues_V3 = TestValues_V1 . Concat ( new object [ ] { ( byte ) 0xFF , ( UInt64 ) 0xFFFFFFFF } ) . ToList ( ) ;
3838 }
3939
40- public TestContext TestContext { get ; set ; }
4140
42- protected string OutPath => Path . Combine ( TestContext . TestResultsDirectory , TestContext . TestName ) ;
43- protected string DmxSavePath { get { return OutPath + ".dmx" ; } }
44- protected string DmxConvertPath { get { return OutPath + "_convert.dmx" ; } }
41+ protected static string OutPath
42+ => Path . Combine ( TestContext . CurrentContext . TestDirectory , TestContext . CurrentContext . Test . Name ) ;
43+ protected static string DmxSavePath { get { return OutPath + ".dmx" ; } }
44+ protected static string DmxConvertPath { get { return OutPath + "_convert.dmx" ; } }
4545
46- protected void Cleanup ( )
46+ protected static string [ ] GetDmxFiles ( )
47+ {
48+ var path = Path . Combine ( TestContext . CurrentContext . TestDirectory , "Resources" ) ;
49+ return Directory . GetFiles ( path , "*.dmx" ) ;
50+ }
51+
52+ protected static void Cleanup ( )
4753 {
4854 File . Delete ( DmxSavePath ) ;
4955 if ( DmxConvertExe_Exists )
@@ -57,12 +63,13 @@ protected static DM MakeDatamodel()
5763 return new DM ( "model" , 1 ) ; // using "model" to keep dxmconvert happy
5864 }
5965
60- protected bool SaveAndConvert ( Datamodel . Datamodel dm , string encoding , int version )
66+ protected static bool SaveAndConvert ( DM datamodel , string encoding , int version )
6167 {
62- dm . Save ( DmxSavePath , encoding , version ) ;
68+ datamodel . Save ( DmxSavePath , encoding , version ) ;
6369
6470 if ( ! DmxConvertExe_Exists )
6571 {
72+ Assert . Warn ( "dmxconvert.exe not available." ) ;
6673 return false ;
6774 }
6875
@@ -71,25 +78,22 @@ protected bool SaveAndConvert(Datamodel.Datamodel dm, string encoding, int versi
7178 StartInfo = new ProcessStartInfo ( )
7279 {
7380 FileName = DmxConvertExe ,
74- Arguments = String . Format ( "-i \" {0}\" -o \" {1}\" -oe {2}" , DmxSavePath , DmxConvertPath , encoding ) ,
81+ Arguments = string . Format ( "-i \" {0}\" -o \" {1}\" -oe {2}" , DmxSavePath , DmxConvertPath , encoding ) ,
7582 UseShellExecute = false ,
7683 CreateNoWindow = true ,
7784 RedirectStandardOutput = true ,
7885 RedirectStandardError = true ,
7986 }
8087 } ;
8188
82- Console . WriteLine ( String . Join ( " " , dmxconvert . StartInfo . FileName , dmxconvert . StartInfo . Arguments ) ) ;
89+ Console . WriteLine ( $ "Converting { TestContext . CurrentContext . Test . Name } .dmx to { encoding } " ) ;
8390
8491 dmxconvert . Start ( ) ;
8592 var err = dmxconvert . StandardOutput . ReadToEnd ( ) ;
8693 err += dmxconvert . StandardError . ReadToEnd ( ) ;
8794 dmxconvert . WaitForExit ( ) ;
8895
89- Console . WriteLine ( err ) ;
90-
91- if ( dmxconvert . ExitCode != 0 )
92- throw new AssertFailedException ( err ) ;
96+ Assert . That ( dmxconvert . ExitCode , Is . Zero , $ "dmxconvert failed to convert the file with error: { err } ") ;
9397
9498 return true ;
9599 }
@@ -99,16 +103,16 @@ protected bool SaveAndConvert(Datamodel.Datamodel dm, string encoding, int versi
99103 /// </summary>
100104 protected static void PrintContents ( DM dm )
101105 {
102- System . Threading . Tasks . Parallel . ForEach < Datamodel . Element > ( dm . AllElements , e =>
106+ System . Threading . Tasks . Parallel . ForEach ( dm . AllElements , e =>
103107 {
104108 System . Threading . Tasks . Parallel . ForEach ( e , a => { ; } ) ;
105109 } ) ;
106110 }
107111
108- protected static List < object > TestValues_V1 ;
109- protected static List < object > TestValues_V2 ;
110- protected static List < object > TestValues_V3 ;
111- protected static Guid RootGuid = Guid . NewGuid ( ) ;
112+ protected static List < object > TestValues_V1 { get ; }
113+ protected static List < object > TestValues_V2 { get ; }
114+ protected static List < object > TestValues_V3 { get ; }
115+ protected static Guid RootGuid { get ; } = Guid . NewGuid ( ) ;
112116
113117 protected static List < object > AttributeValuesFor ( string encoding_name , int encoding_version )
114118 {
@@ -215,53 +219,53 @@ protected DM Create(string encoding, int version, bool memory_save = false)
215219 }
216220
217221 dm . AllElements . Remove ( dm . Root . GetArray < Element > ( "ElemArray" ) [ 3 ] , DM . ElementList . RemoveMode . MakeStubs ) ;
218- Assert . AreEqual < bool > ( true , dm . Root . GetArray < Element > ( "ElemArray" ) [ 3 ] . Stub ) ;
222+ Assert . AreEqual ( true , dm . Root . GetArray < Element > ( "ElemArray" ) [ 3 ] . Stub ) ;
219223
220224 dm . AllElements . Remove ( dm . Root , DM . ElementList . RemoveMode . MakeStubs ) ;
221- Assert . AreEqual < bool > ( true , dm . Root . Stub ) ;
225+ Assert . AreEqual ( true , dm . Root . Stub ) ;
222226
223227 return dm ;
224228 }
225229 }
226230
227- [ TestClass ]
231+ [ TestFixture ]
228232 public class Functionality : DatamodelTests
229233 {
230234
231- [ TestMethod ]
235+ [ Test ]
232236 public void Create_Binary_9 ( )
233237 {
234238 Create ( "binary" , 9 ) ;
235239 }
236- [ TestMethod ]
240+ [ Test ]
237241 public void Create_Binary_5 ( )
238242 {
239243 Create ( "binary" , 5 ) ;
240244 }
241- [ TestMethod ]
245+ [ Test ]
242246 public void Create_Binary_4 ( )
243247 {
244248 Create ( "binary" , 4 ) ;
245249 }
246- [ TestMethod ]
250+ [ Test ]
247251 public void Create_Binary_3 ( )
248252 {
249253 Create ( "binary" , 3 ) ;
250254 }
251- [ TestMethod ]
255+ [ Test ]
252256 public void Create_Binary_2 ( )
253257 {
254258 Create ( "binary" , 2 ) ;
255259 }
256260
257- [ TestMethod ]
261+ [ Test ]
258262 public void Create_KeyValues2_4 ( )
259263 {
260264 Create ( "keyvalues2" , 4 ) ;
261265 }
262266
263267
264- [ TestMethod ]
268+ [ Test ]
265269 public void Create_KeyValues2_1 ( )
266270 {
267271 Create ( "keyvalues2" , 1 ) ;
@@ -273,7 +277,7 @@ void Get_TF2(Datamodel.Datamodel dm)
273277 dm . FormatVersion = 22 ; // otherwise recent versions of dmxconvert fail
274278 }
275279
276- [ TestMethod ]
280+ [ Test ]
277281 public void Dota2_Binary_9 ( )
278282 {
279283 var dm = DM . Load ( Binary_9_File ) ;
@@ -284,7 +288,7 @@ public void Dota2_Binary_9()
284288 Cleanup ( ) ;
285289 }
286290
287- [ TestMethod ]
291+ [ Test ]
288292 public void TF2_Binary_5 ( )
289293 {
290294 var dm = DM . Load ( Binary_5_File ) ;
@@ -295,7 +299,7 @@ public void TF2_Binary_5()
295299 Cleanup ( ) ;
296300 }
297301
298- [ TestMethod ]
302+ [ Test ]
299303 public void TF2_Binary_4 ( )
300304 {
301305 var dm = DM . Load ( Binary_4_File ) ;
@@ -306,7 +310,7 @@ public void TF2_Binary_4()
306310 Cleanup ( ) ;
307311 }
308312
309- [ TestMethod ]
313+ [ Test ]
310314 public void TF2_KeyValues2_1 ( )
311315 {
312316 var dm = DM . Load ( KeyValues2_1_File ) ;
@@ -317,7 +321,16 @@ public void TF2_KeyValues2_1()
317321 Cleanup ( ) ;
318322 }
319323
320- [ TestMethod ]
324+ [ Test , TestCaseSource ( nameof ( GetDmxFiles ) ) ]
325+ public void Load ( string path )
326+ {
327+ var dm = DM . Load ( path ) ;
328+ PrintContents ( dm ) ;
329+ dm . Dispose ( ) ;
330+ }
331+
332+
333+ [ Test ]
321334 public void Import ( )
322335 {
323336 var dm = MakeDatamodel ( ) ;
@@ -331,11 +344,11 @@ public void Import()
331344 }
332345 }
333346
334- [ TestClass ]
347+ [ TestFixture , Category ( "Performance" ) ]
335348 public class Performance : DatamodelTests
336349 {
337350 const int Load_Iterations = 10 ;
338- System . Diagnostics . Stopwatch Timer = new System . Diagnostics . Stopwatch ( ) ;
351+ readonly Stopwatch Timer = new ( ) ;
339352
340353 void Load ( FileStream f )
341354 {
@@ -346,34 +359,35 @@ void Load(FileStream f)
346359 DM . Load ( f , Datamodel . Codecs . DeferredMode . Disabled ) ;
347360 if ( i > 0 )
348361 {
349- Console . WriteLine ( Timer . ElapsedMilliseconds ) ;
362+ Console . Write ( Timer . ElapsedMilliseconds + ", " ) ;
350363 elapsed += Timer . ElapsedMilliseconds ;
351364 }
352365 Timer . Restart ( ) ;
353366 }
354367 Timer . Stop ( ) ;
355368 Console . WriteLine ( "Average: {0}ms" , elapsed / Load_Iterations ) ;
356369 }
357- [ TestMethod ]
370+
371+ [ Test ]
358372 public void Perf_Load_Binary5 ( )
359373 {
360374 Load ( Binary_5_File ) ;
361375 }
362376
363- [ TestMethod ]
377+ [ Test ]
364378 public void Perf_Load_KeyValues2_1 ( )
365379 {
366380 Load ( KeyValues2_1_File ) ;
367381 }
368382
369- [ TestMethod ]
383+ [ Test ]
370384 public void Perf_Create_Binary5 ( )
371385 {
372386 foreach ( var i in Enumerable . Range ( 0 , 1000 ) )
373387 Create ( "binary" , 5 , true ) ;
374388 }
375389
376- [ TestMethod ]
390+ [ Test ]
377391 public void Perf_CreateElements_Binary5 ( )
378392 {
379393 var dm = MakeDatamodel ( ) ;
@@ -389,7 +403,7 @@ public void Perf_CreateElements_Binary5()
389403 Cleanup ( ) ;
390404 }
391405
392- [ TestMethod ]
406+ [ Test ]
393407 public void Perf_CreateAttributes_Binary5 ( )
394408 {
395409 var dm = MakeDatamodel ( ) ;
@@ -416,7 +430,7 @@ static class Extensions
416430 {
417431 public static Type MakeListType ( this Type t )
418432 {
419- return typeof ( System . Collections . Generic . List < > ) . MakeGenericType ( t ) ;
433+ return typeof ( List < > ) . MakeGenericType ( t ) ;
420434 }
421435 }
422436}
0 commit comments