@@ -12,16 +12,28 @@ public class TestCache
1212 private readonly Dictionary < string , DateTime > _dateCache = new Dictionary < string , DateTime > ( ) ;
1313 private bool _haveChanges = true ;
1414 private ScanResults _results = new ScanResults ( ) ;
15- private readonly FileScanner _scanner = new FileScanner ( new TSql130Parser ( false ) ) ;
15+ private readonly FileScanner _scanner ;
1616 private readonly List < TestClass > _tests = new List < TestClass > ( ) ;
17+ private readonly IFileReader _fileReader ;
18+ public TestCache ( )
19+ {
20+ _scanner = new FileScanner ( new TSql130Parser ( false ) ) ;
21+ _fileReader = new FileReader ( ) ;
22+ }
23+
24+ public TestCache ( FileScanner probablyAMock , IFileReader anotherMock )
25+ {
26+ _scanner = probablyAMock ;
27+ _fileReader = anotherMock ;
28+ }
1729
1830
1931 public void AddPath ( string path )
2032 {
21- var date = File . GetLastWriteTimeUtc ( path ) ;
33+ var date = _fileReader . GetLastWriteTimeUtc ( path ) ;
2234 if ( ! _dateCache . ContainsKey ( path ) || date <= _dateCache [ path ] )
2335 {
24- _results = _scanner . ScanCode ( File . ReadAllText ( path ) , _results , path ) ;
36+ _results = _scanner . ScanCode ( _fileReader . ReadAll ( path ) , _results , path ) ;
2537 _haveChanges = true ;
2638 }
2739 }
@@ -32,14 +44,21 @@ public List<TestClass> GetTests()
3244 {
3345 return _tests ;
3446 }
35-
36- var classes = new List < TestClass > ( ) ;
3747
38- var foundClasses =
48+ var foundClasses = new List < SqlSchema > ( ) ;
49+
50+ foreach ( var clazz in
3951 _results . FoundClasses . Where (
4052 p =>
4153 _results . FoundPotentialTests . Any (
42- e => string . Equals ( p . Name , e . Name . Schema , StringComparison . OrdinalIgnoreCase ) ) ) ;
54+ e => string . Equals ( p . Name , e . Name . Schema , StringComparison . OrdinalIgnoreCase ) ) ) )
55+ {
56+ if ( foundClasses . All ( p => p . Name != clazz . Name ) )
57+ {
58+ foundClasses . Add ( clazz ) ;
59+ }
60+
61+ }
4362
4463 var foundTests =
4564 _results . FoundPotentialTests . Where (
@@ -54,7 +73,7 @@ public List<TestClass> GetTests()
5473 var testClass = new TestClass ( ) ;
5574 testClass . Name = cls . Name ;
5675 testClass . Path = cls . Path ;
57- //testClass.Tests =
76+
5877 foreach ( var test in foundTests . Where ( p => string . Equals ( p . Name . Schema , cls . Name , StringComparison . OrdinalIgnoreCase ) ) )
5978 {
6079 testClass . Tests . Add ( new Test { Name = test . Name . Object , Path = test . Path , Line = test . StartLine } ) ;
@@ -70,4 +89,23 @@ public List<TestClass> GetTests()
7089 return _tests ;
7190 }
7291 }
92+
93+ public class FileReader : IFileReader
94+ {
95+ public FileReader ( )
96+ {
97+
98+ }
99+
100+
101+ public virtual string ReadAll ( string path )
102+ {
103+ return File . ReadAllText ( path ) ;
104+ }
105+
106+ public virtual DateTime GetLastWriteTimeUtc ( string path )
107+ {
108+ return File . GetLastWriteTimeUtc ( path ) ;
109+ }
110+ }
73111}
0 commit comments