33using SG . CodeCoverage . Common ;
44using SG . CodeCoverage . Coverage ;
55using SG . CodeCoverage . Instrumentation ;
6+ using SG . CodeCoverage . Metadata ;
67using System ;
78using System . Collections . Generic ;
89using System . IO ;
@@ -14,10 +15,10 @@ namespace SG.CodeCoverage.Tests
1415 public class InstrumenterTester
1516 {
1617 public const int PortNumber = 61238 ;
17- public const string MapFileName = "map.json" ;
1818 public static string DefaultOutputPath { get ; }
1919 public string OutputPath { get ; }
2020 public string MapFilePath { get ; }
21+ public InstrumentationMap Map { get ; private set ; }
2122 public string InstrumentedAssemblyPath { get ; private set ; }
2223
2324 static InstrumenterTester ( )
@@ -28,13 +29,11 @@ static InstrumenterTester()
2829 public InstrumenterTester ( )
2930 {
3031 OutputPath = DefaultOutputPath ;
31- MapFilePath = Path . Combine ( OutputPath , MapFileName ) ;
3232 }
3333
3434 public InstrumenterTester ( string existingInstrumentedSampleFolder )
3535 {
3636 OutputPath = existingInstrumentedSampleFolder ;
37- MapFilePath = Path . Combine ( OutputPath , MapFileName ) ;
3837 InstrumentedAssemblyPath = Path . Combine ( OutputPath , Path . GetFileName ( typeof ( PrimeCalculator ) . Assembly . Location ) ) ;
3938 }
4039
@@ -56,10 +55,10 @@ public void InstrumentSampleProject()
5655 var options = new InstrumentationOptions (
5756 new [ ] { assemblyFileName } ,
5857 Array . Empty < string > ( ) , OutputPath , PortNumber ) ;
59- Instrumenter instrumenter = new Instrumenter ( options , MapFilePath , new ConsoleLogger ( ) ) ;
58+ Instrumenter instrumenter = new Instrumenter ( options , new ConsoleLogger ( ) ) ;
6059 instrumenter . BackupFolder = Path . Combine ( OutputPath , "backup" ) ;
6160 Directory . CreateDirectory ( instrumenter . BackupFolder ) ;
62- instrumenter . Instrument ( ) ;
61+ Map = instrumenter . Instrument ( ) ;
6362 InstrumentedAssemblyPath = assemblyFileName ;
6463 }
6564
@@ -75,7 +74,7 @@ public void RunSomeCode()
7574 {
7675 if ( InstrumentedAssemblyPath == null )
7776 throw new InvalidOperationException ( "Sample assembly is not instrumented." ) ;
78- var client = new Collection . RecordingController ( PortNumber ) ;
77+ var client = RecordingController . ForEndPoint ( "localhost" , PortNumber , Map ) ;
7978 Assembly . LoadFrom ( Path . Combine ( OutputPath , "SG.CodeCoverage.Recorder.dll" ) ) ;
8079 var assembly = Assembly . LoadFrom ( InstrumentedAssemblyPath ) ;
8180 var calc = assembly . DefinedTypes . Where ( x => x . Name == nameof ( PrimeCalculator ) ) . FirstOrDefault ( ) ;
@@ -86,10 +85,8 @@ public List<string> GetVisitedFiles()
8685 {
8786 if ( InstrumentedAssemblyPath == null )
8887 throw new InvalidOperationException ( "Sample assembly is not instrumented." ) ;
89- var client = new RecordingController ( PortNumber ) ;
90- var hitsFile = Path . Combine ( OutputPath , "hits.bin" ) ;
91- client . SaveHitsAndReset ( hitsFile ) ;
92- return new CoverageResult ( MapFilePath , hitsFile ) . GetVisitedSources ( ) . ToList ( ) ;
88+ var client = RecordingController . ForEndPoint ( "localhost" , PortNumber , Map ) ;
89+ return client . CollectResultAndReset ( ) . GetVisitedSources ( ) . ToList ( ) ; ;
9390 }
9491 }
9592}
0 commit comments