55using ChartTools . IO . Ini ;
66using ChartTools . Meta ;
77
8- using Microsoft . VisualStudio . TestTools . UnitTesting ;
9-
108using System . Reflection ;
119
1210namespace ChartTools . Tests . Meta ;
1311
1412[ TestClass ]
1513public class MetadataTests
1614{
17- private readonly Metadata invalidDummy = new ( ) ;
15+ private static readonly Metadata s_invalidDummy = new ( ) ;
1816
1917 #region Invalid format
2018 [ TestMethod , TestCategory ( nameof ( Metadata ) ) , TestCategory ( nameof ( Exception ) ) ]
2119 public void TryGet_InvalidFormat_Throws ( )
22- => Assert . ThrowsException < ArgumentException > (
23- ( ) => invalidDummy . TryGet ( FileType . Midi , "Dummy" , out _ ) ) ;
20+ => Assert . Throws < ArgumentException > (
21+ static ( ) => s_invalidDummy . TryGet ( FileType . Midi , "Dummy" , out _ ) ) ;
2422
2523 [ TestMethod , TestCategory ( nameof ( Metadata . Get ) ) , TestCategory ( nameof ( Exception ) ) ]
2624 public void Get_InvalidFormat_Throws ( )
27- => Assert . ThrowsException < ArgumentException > (
28- ( ) => invalidDummy . Get ( FileType . Midi , "Dummy" ) ) ;
25+ => Assert . Throws < ArgumentException > (
26+ static ( ) => s_invalidDummy . Get ( FileType . Midi , "Dummy" ) ) ;
2927
3028 [ TestMethod , TestCategory ( nameof ( Metadata . Set ) ) , TestCategory ( nameof ( Exception ) ) ]
3129 public void Set_InvalidFormat_Throws ( )
32- => Assert . ThrowsException < ArgumentException > (
33- ( ) => invalidDummy . Set ( FileType . Midi , string . Empty , string . Empty ) ) ;
30+ => Assert . Throws < ArgumentException > (
31+ static ( ) => s_invalidDummy . Set ( FileType . Midi , string . Empty , string . Empty ) ) ;
3432
3533 [ TestMethod , TestCategory ( nameof ( Metadata . Remove ) ) , TestCategory ( nameof ( Exception ) ) ]
3634 public void Remove_InvalidFormat_Throws ( )
37- => Assert . ThrowsException < ArgumentException > (
38- ( ) => invalidDummy . Remove ( FileType . Midi , "Dummy" ) ) ;
35+ => Assert . Throws < ArgumentException > (
36+ static ( ) => s_invalidDummy . Remove ( FileType . Midi , "Dummy" ) ) ;
3937
4038 [ TestMethod , TestCategory ( nameof ( Metadata . Remove ) ) , TestCategory ( nameof ( Exception ) ) ]
4139 public void Contains_InvalidFormat_Throws ( )
42- => Assert . ThrowsException < ArgumentException > (
43- ( ) => invalidDummy . Contains ( FileType . Midi , "Dummy" ) ) ;
40+ => Assert . Throws < ArgumentException > (
41+ static ( ) => s_invalidDummy . Contains ( FileType . Midi , "Dummy" ) ) ;
4442 #endregion
4543
4644 #region Empty key
4745 [ TestMethod , TestCategory ( nameof ( Metadata . Get ) ) ]
4846 [ TestCategory ( nameof ( FileType . Chart ) ) , TestCategory ( nameof ( FileType . Ini ) ) ]
4947 [ DataRow ( FileType . Chart ) , DataRow ( FileType . Ini ) ]
5048 public void Get_EmptyKey_Throws ( FileType fileType )
51- => Assert . ThrowsException < ArgumentException > (
52- ( ) => invalidDummy . Get ( fileType , string . Empty ) ) ;
49+ => Assert . Throws < ArgumentException > (
50+ ( ) => s_invalidDummy . Get ( fileType , string . Empty ) ) ;
5351
5452 [ TestMethod , TestCategory ( nameof ( Metadata . Set ) ) ,
5553 TestCategory ( nameof ( FileType . Chart ) ) , TestCategory ( nameof ( FileType . Ini ) ) ]
5654 [ DataRow ( FileType . Chart ) , DataRow ( FileType . Ini ) ]
5755 public void Set_EmptyKey_Throws ( FileType fileType )
58- => Assert . ThrowsException < ArgumentException > (
59- ( ) => invalidDummy . Set ( fileType , string . Empty , "Dummy" ) ) ;
56+ => Assert . Throws < ArgumentException > (
57+ ( ) => s_invalidDummy . Set ( fileType , string . Empty , "Dummy" ) ) ;
6058
6159 [ TestMethod , TestCategory ( nameof ( Metadata . Remove ) ) ]
6260 [ TestCategory ( nameof ( FileType . Chart ) ) , TestCategory ( nameof ( FileType . Ini ) ) ]
6361 [ DataRow ( FileType . Chart ) , DataRow ( FileType . Ini ) ]
6462 public void Remove_EmptyKey_Throws ( FileType fileType )
65- => Assert . ThrowsException < ArgumentException > (
66- ( ) => invalidDummy . Remove ( fileType , string . Empty ) ) ;
63+ => Assert . Throws < ArgumentException > (
64+ ( ) => s_invalidDummy . Remove ( fileType , string . Empty ) ) ;
6765
6866 [ TestMethod , TestCategory ( nameof ( Metadata . Contains ) ) ]
6967 [ TestCategory ( nameof ( FileType . Chart ) ) , TestCategory ( nameof ( FileType . Ini ) ) ]
7068 [ DataRow ( FileType . Chart ) , DataRow ( FileType . Ini ) ]
7169 public void Contains_EmptyKey_Throws ( FileType fileType )
72- => Assert . ThrowsException < ArgumentException > (
73- ( ) => invalidDummy . Contains ( fileType , string . Empty ) ) ;
70+ => Assert . Throws < ArgumentException > (
71+ ( ) => s_invalidDummy . Contains ( fileType , string . Empty ) ) ;
7472 #endregion
7573
7674 #region FromAttribute
@@ -165,11 +163,8 @@ public void Set_AudioOffet_Formats(FileType fileType, string key, string value)
165163 [ DataRow ( FileType . Chart , ChartFormatting . AudioOffset ) ]
166164 [ DataRow ( FileType . Ini , IniFormatting . AudioOffset ) ]
167165 public void Set_AudioOffsetInvalid_Throws ( FileType fileType , string key )
168- => Assert . ThrowsException < ParseException > ( ( ) =>
169- {
170- Metadata metadata = new ( ) ;
171- metadata . Set ( fileType , key , "InvalidOffset" ) ;
172- } ) ;
166+ => Assert . Throws < ParseException > (
167+ ( ) => new Metadata ( ) . Set ( fileType , key , "InvalidOffset" ) ) ;
173168 #endregion
174169
175170 #region Chart year
@@ -178,7 +173,7 @@ public void Set_AudioOffsetInvalid_Throws(FileType fileType, string key)
178173 public void Get_ChartYear_Formats ( )
179174 {
180175 const ushort year = 2000 ;
181- string expected = $ "\" , { year } \" ";
176+ string expected = $ "\" , { year } \" ";
182177
183178 Metadata metadata = new ( ) { Year = year } ;
184179
@@ -190,7 +185,7 @@ public void Get_ChartYear_Formats()
190185 public void Set_ChartYear_Formats ( )
191186 {
192187 const ushort expected = 2000 ;
193- string formatted = $ "\" , { expected } \" ";
188+ string formatted = $ "\" , { expected } \" ";
194189
195190 Metadata metadata = new ( ) ;
196191 metadata . Set ( FileType . Chart , ChartFormatting . Year , formatted ) ;
@@ -201,11 +196,8 @@ public void Set_ChartYear_Formats()
201196 [ TestMethod , TestCategory ( nameof ( Exception ) ) , TestCategory ( nameof ( FileType . Chart ) ) ]
202197 [ TestCategory ( nameof ( Metadata . Set ) ) , TestCategory ( nameof ( Metadata . Year ) ) ]
203198 public void Set_ChartYearInvalid_Throws ( )
204- => Assert . ThrowsException < ParseException > ( ( ) =>
205- {
206- Metadata metadata = new ( ) ;
207- metadata . Set ( FileType . Chart , ChartFormatting . Year , "InvalidYear" ) ;
208- } ) ;
199+ => Assert . Throws < ParseException > (
200+ static ( ) => new Metadata ( ) . Set ( FileType . Chart , ChartFormatting . Year , "InvalidYear" ) ) ;
209201 #endregion
210202
211203 #region Ini
@@ -240,22 +232,17 @@ public void Set_IniVideoOffset_Formats(double milliseconds)
240232 [ TestMethod , TestCategory ( nameof ( Exception ) ) , TestCategory ( nameof ( FileType . Ini ) ) ]
241233 [ TestCategory ( nameof ( Metadata . Set ) ) , TestCategory ( nameof ( Metadata . VideoOffset ) ) ]
242234 public void Set_IniVideoOffsetInvalid_Throws ( )
243- => Assert . ThrowsException < ParseException > ( ( ) =>
244- {
245- Metadata metadata = new ( ) ;
246- metadata . Set ( FileType . Ini , IniFormatting . VideoOffset , "InvalidOffet" ) ;
247- } ) ;
235+ => Assert . Throws < ParseException > (
236+ static ( ) => new Metadata ( ) . Set ( FileType . Ini , IniFormatting . VideoOffset , "InvalidOffet" ) ) ;
248237 #endregion
249238
250239 #region Modchart
251240 [ TestMethod , TestCategory ( nameof ( FileType . Ini ) ) ]
252241 [ TestCategory ( nameof ( Metadata . Get ) ) , TestCategory ( nameof ( Metadata . IsModchart ) ) ]
253242 [ DataRow ( false , "0" ) , DataRow ( true , "1" ) ]
254243 public void Get_IniModChart_Formats ( bool value , string expected )
255- {
256- Metadata metadata = new ( ) { IsModchart = value } ;
257- Assert . AreEqual ( expected , metadata . Get ( FileType . Ini , IniFormatting . Modchart ) ) ;
258- }
244+ => Assert . AreEqual ( expected , new Metadata { IsModchart = value }
245+ . Get ( FileType . Ini , IniFormatting . Modchart ) ) ;
259246
260247 [ TestMethod , TestCategory ( nameof ( FileType . Ini ) ) ]
261248 [ TestCategory ( nameof ( Metadata . Set ) ) , TestCategory ( nameof ( Metadata . IsModchart ) ) ]
@@ -271,11 +258,8 @@ public void Set_IniModChart_Formats(bool expected, string value)
271258 [ TestMethod , TestCategory ( nameof ( Exception ) ) , TestCategory ( nameof ( FileType . Ini ) ) ]
272259 [ TestCategory ( nameof ( Metadata . Set ) ) , TestCategory ( nameof ( Metadata . IsModchart ) ) ]
273260 public void Set_IniModChartInvalid_Throws ( )
274- => Assert . ThrowsException < ParseException > ( ( ) =>
275- {
276- Metadata metadata = new ( ) ;
277- metadata . Set ( FileType . Ini , IniFormatting . Modchart , "InvalidBool" ) ;
278- } ) ;
261+ => Assert . Throws < ParseException > (
262+ static ( ) => new Metadata ( ) . Set ( FileType . Ini , IniFormatting . Modchart , "InvalidBool" ) ) ;
279263 #endregion
280264
281265 #region Album track
@@ -339,7 +323,7 @@ public void Set_IniTrack_Maps(AlbumTrackKeys keys, string keyString)
339323 [ TestMethod , TestCategory ( nameof ( Exception ) ) , TestCategory ( nameof ( FileType . Ini ) ) ]
340324 [ TestCategory ( nameof ( Metadata . Set ) ) , TestCategory ( nameof ( Metadata . AlbumTrack ) ) ]
341325 public void Set_IniTrackInvalid_Throws ( )
342- => Assert . ThrowsException < ParseException > (
326+ => Assert . Throws < ParseException > (
343327 ( ) => new Metadata { Formatting = new ( ) { AlbumTrackKeys = AlbumTrackKeys . Track } }
344328 . Set ( FileType . Ini , IniFormatting . Track , "InvalidTrack" ) ) ;
345329
0 commit comments