@@ -256,6 +256,95 @@ public void ShouldHandleFailedAnalysis()
256256 action . ShouldThrow < InputException > ( ) ;
257257 }
258258
259+ [ TestMethod ]
260+ public void ShouldFailIfSolutionNotFound ( )
261+ {
262+ var fileSystem = new MockFileSystem ( new Dictionary < string , MockFileData >
263+ {
264+ { _sourceProjectPath , new MockFileData ( _defaultTestProjectFileContents ) } ,
265+ { _testProjectPath , new MockFileData ( _defaultTestProjectFileContents ) } ,
266+ { Path . Combine ( _sourcePath , "Recursive.cs" ) , new MockFileData ( _sourceFile ) } ,
267+ { Path . Combine ( _sourcePath , "Plain.cs" ) , new MockFileData ( _sourceFile ) } ,
268+ } ) ;
269+
270+ var sourceProjectManagerMock = SourceProjectAnalyzerMock ( _sourceProjectPath ,
271+ fileSystem . AllFiles . Where ( s => s . EndsWith ( ".cs" ) ) . ToArray ( ) ) ;
272+ var testProjectManagerMock = TestProjectAnalyzerMock ( _testProjectPath , _sourceProjectPath , [ "netcoreapp2.1" ] , success : false ) ;
273+
274+ var analyzerResults = new Dictionary < string , IProjectAnalyzer >
275+ {
276+ { "MyProject" , sourceProjectManagerMock . Object } ,
277+ { "MyProject.UnitTests" , testProjectManagerMock . Object }
278+ } ;
279+ BuildBuildAnalyzerMock ( analyzerResults ) ;
280+ var options = new StrykerOptions ( )
281+ {
282+ ProjectPath = _sourcePath ,
283+ SolutionPath = Path . Combine ( _sourcePath , "solution.nope" )
284+ } ;
285+ var target = new InputFileResolver ( fileSystem ,
286+ BuildalyzerProviderMock . Object ,
287+ _nugetMock . Object ) ;
288+
289+ var action = ( ) => target . ResolveSourceProjectInfos ( options ) . First ( ) ;
290+ action . ShouldThrow < InvalidOperationException > ( ) ;
291+ }
292+
293+ [ TestMethod ]
294+ public void ShouldFailIfSolutionLoadFails ( )
295+ {
296+ var fileSystem = new MockFileSystem ( new Dictionary < string , MockFileData > ( ) ) ;
297+
298+ var sourceProjectManagerMock = SourceProjectAnalyzerMock ( _sourceProjectPath ,
299+ fileSystem . AllFiles . Where ( s => s . EndsWith ( ".cs" ) ) . ToArray ( ) ) ;
300+ var testProjectManagerMock = TestProjectAnalyzerMock ( _testProjectPath , _sourceProjectPath , [ "netcoreapp2.1" ] , success : false ) ;
301+
302+ var analyzerResults = new Dictionary < string , IProjectAnalyzer >
303+ {
304+ { "MyProject" , sourceProjectManagerMock . Object } ,
305+ { "MyProject.UnitTests" , testProjectManagerMock . Object }
306+ } ;
307+ BuildBuildAnalyzerMock ( analyzerResults ) ;
308+ var options = new StrykerOptions ( )
309+ {
310+ ProjectPath = _sourcePath ,
311+ SolutionPath = Path . Combine ( _sourcePath , "solution.sln" )
312+ } ;
313+ var target = new InputFileResolver ( fileSystem ,
314+ BuildalyzerProviderMock . Object ,
315+ _nugetMock . Object , _ => throw new IOException ( "Failed to read solution" ) ) ;
316+
317+ var action = ( ) => target . ResolveSourceProjectInfos ( options ) . First ( ) ;
318+ action . ShouldThrow < InvalidOperationException > ( ) ;
319+ }
320+ [ TestMethod ]
321+ public void ShouldFailIfSolutionCantBeAccessed ( )
322+ {
323+ var fileSystem = new MockFileSystem ( new Dictionary < string , MockFileData > ( ) ) ;
324+
325+ var sourceProjectManagerMock = SourceProjectAnalyzerMock ( _sourceProjectPath ,
326+ fileSystem . AllFiles . Where ( s => s . EndsWith ( ".cs" ) ) . ToArray ( ) ) ;
327+ var testProjectManagerMock = TestProjectAnalyzerMock ( _testProjectPath , _sourceProjectPath , [ "netcoreapp2.1" ] , success : false ) ;
328+
329+ var analyzerResults = new Dictionary < string , IProjectAnalyzer >
330+ {
331+ { "MyProject" , sourceProjectManagerMock . Object } ,
332+ { "MyProject.UnitTests" , testProjectManagerMock . Object }
333+ } ;
334+ BuildBuildAnalyzerMock ( analyzerResults ) ;
335+ var options = new StrykerOptions ( )
336+ {
337+ ProjectPath = _sourcePath ,
338+ SolutionPath = Path . Combine ( _sourcePath , "solution.slnx" )
339+ } ;
340+ var target = new InputFileResolver ( fileSystem ,
341+ BuildalyzerProviderMock . Object ,
342+ _nugetMock . Object , _ => throw new UnauthorizedAccessException ( "Access forbidden" ) ) ;
343+
344+ var action = ( ) => target . ResolveSourceProjectInfos ( options ) . First ( ) ;
345+ action . ShouldThrow < UnauthorizedAccessException > ( ) ;
346+ }
347+
259348 [ TestMethod ]
260349 public void InitializeShouldNotSkipXamlFiles ( )
261350 {
0 commit comments