1111using System . Linq ;
1212using System . Globalization ;
1313using GitHub . Reflection ;
14+ using GitHub ;
1415
1516namespace MetricsTests
1617{
@@ -230,10 +231,10 @@ public async Task UsageServiceWritesAllTheDataCorrectly()
230231 expected . NumberOfStartupsWeek ++ ;
231232 expected . NumberOfStartupsMonth ++ ;
232233
233- UsageData result = usageService . ReceivedCalls ( ) . First ( x => x . GetMethodInfo ( ) . Name == "WriteLocalData" ) . GetArguments ( ) [ 0 ] as UsageData ;
234+ var result = ( usageService . ReceivedCalls ( ) . First ( x => x . GetMethodInfo ( ) . Name == "WriteLocalData" ) . GetArguments ( ) [ 0 ] as UsageData ) . Model ;
234235 CollectionAssert . AreEquivalent (
235- ReflectionUtils . GetFields ( expected . GetType ( ) ) . Select ( x => new { x . Name , Value = x . GetValue ( expected ) } ) ,
236- ReflectionUtils . GetFields ( result . Model . GetType ( ) ) . Select ( x => new { x . Name , Value = x . GetValue ( result . Model ) } ) ) ;
236+ ReflectionUtils . GetProperties ( expected . GetType ( ) ) . Select ( x => new { x . Name , Value = x . GetValue ( expected ) } ) ,
237+ ReflectionUtils . GetProperties ( result . GetType ( ) ) . Select ( x => new { x . Name , Value = x . GetValue ( result ) } ) ) ;
237238 }
238239
239240 [ Test ]
@@ -258,8 +259,8 @@ public async Task MetricserviceSendsDailyData()
258259 expected . NumberOfStartups ++ ;
259260
260261 CollectionAssert . AreEquivalent (
261- ReflectionUtils . GetFields ( expected . GetType ( ) ) . Select ( x => new { x . Name , Value = x . GetValue ( expected ) } ) ,
262- ReflectionUtils . GetFields ( result . GetType ( ) ) . Select ( x => new { x . Name , Value = x . GetValue ( result ) } ) ) ;
262+ ReflectionUtils . GetProperties ( expected . GetType ( ) ) . Select ( x => new { x . Name , Value = x . GetValue ( expected ) } ) ,
263+ ReflectionUtils . GetProperties ( result . GetType ( ) ) . Select ( x => new { x . Name , Value = x . GetValue ( result ) } ) ) ;
263264 }
264265
265266 [ Test ]
@@ -285,8 +286,8 @@ public async Task MetricserviceSendsWeeklyData()
285286 expected . NumberOfStartupsWeek ++ ;
286287
287288 CollectionAssert . AreEquivalent (
288- ReflectionUtils . GetFields ( expected . GetType ( ) ) . Select ( x => new { x . Name , Value = x . GetValue ( expected ) } ) ,
289- ReflectionUtils . GetFields ( result . GetType ( ) ) . Select ( x => new { x . Name , Value = x . GetValue ( result ) } ) ) ;
289+ ReflectionUtils . GetProperties ( expected . GetType ( ) ) . Select ( x => new { x . Name , Value = x . GetValue ( expected ) } ) ,
290+ ReflectionUtils . GetProperties ( result . GetType ( ) ) . Select ( x => new { x . Name , Value = x . GetValue ( result ) } ) ) ;
290291 }
291292
292293 [ Test ]
@@ -313,34 +314,34 @@ public async Task MetricserviceSendsMonthlyData()
313314 expected . NumberOfStartupsMonth ++ ;
314315
315316 CollectionAssert . AreEquivalent (
316- ReflectionUtils . GetFields ( expected . GetType ( ) ) . Select ( x => new { x . Name , Value = x . GetValue ( expected ) } ) ,
317- ReflectionUtils . GetFields ( result . GetType ( ) ) . Select ( x => new { x . Name , Value = x . GetValue ( result ) } ) ) ;
317+ ReflectionUtils . GetProperties ( expected . GetType ( ) ) . Select ( x => new { x . Name , Value = x . GetValue ( expected ) } ) ,
318+ ReflectionUtils . GetProperties ( result . GetType ( ) ) . Select ( x => new { x . Name , Value = x . GetValue ( result ) } ) ) ;
318319 }
319320
320321 private static UsageModel CreateUsageModel ( )
321322 {
322323 var count = 1 ;
323324 // UsageModel is a struct so we have to force box it to be able to set values on it
324325 object model = new UsageModel ( ) ;
325- var fields = model . GetType ( ) . GetRuntimeFields ( ) ;
326- foreach ( var field in fields )
326+ var props = ReflectionUtils . GetProperties ( model . GetType ( ) ) ;
327+ foreach ( var prop in props )
327328 {
328- if ( field . FieldType == typeof ( int ) )
329+ if ( prop . PropertyType == typeof ( int ) )
329330 {
330- field . SetValue ( model , count ++ ) ;
331+ prop . SetValue ( model , count ++ ) ;
331332 }
332- else if ( field . FieldType == typeof ( string ) )
333+ else if ( prop . PropertyType == typeof ( string ) )
333334 {
334- if ( field . Name == "Lang" )
335- field . SetValue ( model , CultureInfo . InstalledUICulture . IetfLanguageTag ) ;
336- else if ( field . Name == "AppVersion" )
337- field . SetValue ( model , AssemblyVersionInformation . Version ) ;
335+ if ( prop . Name == "Lang" )
336+ prop . SetValue ( model , CultureInfo . InstalledUICulture . IetfLanguageTag ) ;
337+ else if ( prop . Name == "AppVersion" )
338+ prop . SetValue ( model , AssemblyVersionInformation . Version ) ;
338339 else
339- field . SetValue ( model , $ "string { count ++ } ") ;
340+ prop . SetValue ( model , $ "string { count ++ } ") ;
340341 }
341- else if ( field . FieldType == typeof ( bool ) )
342+ else if ( prop . PropertyType == typeof ( bool ) )
342343 {
343- field . SetValue ( model , true ) ;
344+ prop . SetValue ( model , true ) ;
344345 }
345346 else
346347 Assert . Fail ( "Unknown field type in UsageModel. Fix this test to support it" ) ;
0 commit comments