Skip to content

Commit 618520e

Browse files
committed
tests: improve coverage
1 parent 2b176cb commit 618520e

File tree

4 files changed

+109
-3
lines changed

4 files changed

+109
-3
lines changed

src/Stryker.Core/Stryker.Core.UnitTest/Initialisation/InitialBuildProcessTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,26 @@ public void InitialBuildProcess_ShouldUseCustomMsbuildIfNotNull()
132132
Times.Once);
133133
}
134134

135+
[TestMethod]
136+
public void InitialBuildProcess_ShouldUseProvidedConfiguration()
137+
{
138+
var processMock = new Mock<IProcessExecutor>(MockBehavior.Strict);
139+
var mockFileSystem = new MockFileSystem();
140+
141+
processMock.SetupProcessMockToReturn("");
142+
143+
var target = new InitialBuildProcess(processMock.Object, mockFileSystem);
144+
145+
target.InitialBuild(false, "/", "./ExampleProject.sln", "TheDebug");
146+
processMock.Verify(x => x.Start(It.IsAny<string>(),
147+
It.IsAny<string>(),
148+
It.Is<string>(argumentsParam => argumentsParam.Contains("-c TheDebug")),
149+
It.IsAny<IEnumerable<KeyValuePair<string, string>>>(),
150+
It.IsAny<int>()),
151+
Times.Once);
152+
}
153+
154+
135155
[TestMethod]
136156
public void InitialBuildProcess_ShouldRunDotnetBuildIfNotDotnetFramework()
137157
{

src/Stryker.Core/Stryker.Core.UnitTest/Initialisation/InputFileResolverTests.cs

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
{

src/Stryker.Core/Stryker.Core/Initialisation/InputFileResolver.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ public IReadOnlyCollection<SourceProjectInfo> ResolveSourceProjectInfos(IStryker
6868
Dictionary<IAnalyzerResult, List<IAnalyzerResult>> findMutableAnalyzerResults;
6969
if (options.IsSolutionContext)
7070
{
71-
7271
SolutionFile solution;
7372

7473
try

src/Stryker.Solutions/SolutionFile.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ public class SolutionFile
1010

1111
public HashSet<string> GetBuildTypes() => _configurations.Keys.Select(x => x.buildType).ToHashSet();
1212

13-
public HashSet<string> GetPlatforms() => _configurations.Keys.Select(x => x.platform).ToHashSet();
14-
1513
public bool ConfigurationExists(string buildType, string? platform = null) => _configurations.Keys.Any(x => x.buildType == buildType && (platform == null || platform == x.platform));
1614

1715
public IReadOnlyCollection<string> GetProjects(string buildType, string? platform = null)

0 commit comments

Comments
 (0)