@@ -14,19 +14,14 @@ namespace SG.CodeCoverage.Tests
1414{
1515 public class InstrumenterTester
1616 {
17- public const int PortNumber = 61238 ;
18- public static string DefaultOutputPath { get ; }
17+ public int PortNumber { get ; set ; } = 61238 ;
18+ public static string DefaultOutputPath { get ; } = Path . Combine ( Path . GetTempPath ( ) , "SG.CodeCoverage" ) ;
1919 public string OutputPath { get ; }
2020 public string MapFilePath { get ; }
21- public InstrumentationMap Map { get ; private set ; }
21+ public IRecordingController RecordingController { get ; private set ; }
2222 public string InstrumentedAssemblyPath { get ; private set ; }
2323 private readonly ILogger _logger ;
2424
25- static InstrumenterTester ( )
26- {
27- DefaultOutputPath = Path . Combine ( Path . GetTempPath ( ) , "SG.CodeCoverage" ) ;
28- }
29-
3025 public InstrumenterTester ( ILogger logger = null )
3126 {
3227 OutputPath = DefaultOutputPath ;
@@ -61,7 +56,7 @@ public void InstrumentSampleProject()
6156 Instrumenter instrumenter = new Instrumenter ( options , _logger ) ;
6257 instrumenter . BackupFolder = Path . Combine ( OutputPath , "backup" ) ;
6358 Directory . CreateDirectory ( instrumenter . BackupFolder ) ;
64- Map = instrumenter . Instrument ( ) ;
59+ RecordingController = instrumenter . Instrument ( ) ;
6560 InstrumentedAssemblyPath = assemblyFileName ;
6661 }
6762
@@ -77,19 +72,17 @@ public void RunSomeCode()
7772 {
7873 if ( InstrumentedAssemblyPath == null )
7974 throw new InvalidOperationException ( "Sample assembly is not instrumented." ) ;
80- var client = RecordingController . ForEndPoint ( "localhost" , PortNumber , Map , _logger ) ;
8175 Assembly . LoadFrom ( Path . Combine ( OutputPath , "SG.CodeCoverage.Recorder.dll" ) ) ;
8276 var assembly = Assembly . LoadFrom ( InstrumentedAssemblyPath ) ;
8377 var calc = assembly . DefinedTypes . Where ( x => x . Name == nameof ( PrimeCalculator ) ) . FirstOrDefault ( ) ;
8478 var res = calc . GetMethod ( "IsPrime" ) . Invoke ( calc . DeclaredConstructors . First ( ) . Invoke ( null ) , new object [ ] { 7 } ) ;
8579 }
8680
87- public List < string > GetVisitedFiles ( )
81+ public CoverageResult GetCoverageResult ( )
8882 {
89- if ( InstrumentedAssemblyPath == null )
83+ if ( InstrumentedAssemblyPath == null || RecordingController == null )
9084 throw new InvalidOperationException ( "Sample assembly is not instrumented." ) ;
91- var client = RecordingController . ForEndPoint ( "localhost" , PortNumber , Map , _logger ) ;
92- return client . CollectResultAndReset ( ) . GetVisitedSources ( ) . ToList ( ) ; ;
85+ return RecordingController . CollectResultAndReset ( ) ;
9386 }
9487 }
9588}
0 commit comments