9 changed files with 251 additions and 113 deletions
@ -0,0 +1,106 @@
@@ -0,0 +1,106 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Linq; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using NUnit.Framework; |
||||
using UnitTesting.Tests.Utils; |
||||
|
||||
namespace UnitTesting.Tests.Tree |
||||
{ |
||||
[TestFixture] |
||||
public class AbstractRunTestCommandTests |
||||
{ |
||||
DerivedRunTestCommand runTestCommand; |
||||
MockRunTestCommandContext runTestCommandContext; |
||||
|
||||
void CreateRunTestCommand() |
||||
{ |
||||
runTestCommandContext = new MockRunTestCommandContext(); |
||||
runTestCommand = new DerivedRunTestCommand(runTestCommandContext); |
||||
} |
||||
|
||||
void UnitTestsPadNotCreated() |
||||
{ |
||||
runTestCommandContext.MockUnitTestsPad = null; |
||||
} |
||||
|
||||
void NoSolutionOpen() |
||||
{ |
||||
runTestCommandContext.Solution = null; |
||||
} |
||||
|
||||
IProject SolutionWithOneProjectOpen() |
||||
{ |
||||
var solution = new Solution(new MockProjectChangeWatcher()); |
||||
var project = new MockCSharpProject(solution, "MyProject"); |
||||
solution.AddFolder(project); |
||||
|
||||
runTestCommandContext.Solution = solution; |
||||
|
||||
return project; |
||||
} |
||||
|
||||
IProject GetFirstProjectTestedByTestRunner() |
||||
{ |
||||
return runTestCommand |
||||
.TestRunnersCreated |
||||
.First() |
||||
.SelectedTestsPassedToStartMethod |
||||
.Project; |
||||
} |
||||
|
||||
void BuildIsNotNeededBeforeTestRunForProject(IProject expectedProject) |
||||
{ |
||||
MockTestFramework testFramework = RegisterTestFrameworkForProject(expectedProject); |
||||
testFramework.IsBuildNeededBeforeTestRun = false; |
||||
} |
||||
|
||||
MockTestFramework RegisterTestFrameworkForProject(IProject project) |
||||
{ |
||||
var testFramework = new MockTestFramework(); |
||||
runTestCommandContext |
||||
.MockRegisteredTestFrameworks |
||||
.AddTestFrameworkForProject(project, testFramework); |
||||
|
||||
return testFramework; |
||||
} |
||||
|
||||
[Test] |
||||
public void Run_UnitTestsPadNotCreatedAndNoSolutionOpen_NullReferenceExceptionNotThrown() |
||||
{ |
||||
CreateRunTestCommand(); |
||||
NoSolutionOpen(); |
||||
|
||||
Assert.DoesNotThrow(() => runTestCommand.Run()); |
||||
} |
||||
|
||||
[Test] |
||||
public void Run_UnitTestsPadNotCreatedAndNoSolutionOpen_OnBeforeRunIsNotCalled() |
||||
{ |
||||
CreateRunTestCommand(); |
||||
UnitTestsPadNotCreated(); |
||||
NoSolutionOpen(); |
||||
|
||||
runTestCommand.Run(); |
||||
|
||||
Assert.IsFalse(runTestCommand.IsOnBeforeBuildMethodCalled); |
||||
} |
||||
|
||||
[Test] |
||||
public void Run_UnitTestsPadNotCreatedAndSolutionWithOneProjectOpen_TestsRunForProject() |
||||
{ |
||||
CreateRunTestCommand(); |
||||
UnitTestsPadNotCreated(); |
||||
IProject expectedProject = SolutionWithOneProjectOpen(); |
||||
BuildIsNotNeededBeforeTestRunForProject(expectedProject); |
||||
|
||||
runTestCommand.Run(); |
||||
|
||||
IProject project = GetFirstProjectTestedByTestRunner(); |
||||
|
||||
Assert.AreEqual(expectedProject, project); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,63 @@
@@ -0,0 +1,63 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using ICSharpCode.UnitTesting; |
||||
using NUnit.Framework; |
||||
using UnitTesting.Tests.Utils; |
||||
|
||||
namespace UnitTesting.Tests.Tree |
||||
{ |
||||
[TestFixture] |
||||
public class EmptyUnitTestsPadTests |
||||
{ |
||||
EmptyUnitTestsPad pad; |
||||
Solution solution; |
||||
|
||||
void CreatePadWithNullSolution() |
||||
{ |
||||
CreatePad(null); |
||||
} |
||||
|
||||
void CreatePad(Solution solution) |
||||
{ |
||||
pad = new EmptyUnitTestsPad(solution); |
||||
} |
||||
|
||||
void CreatePadWithSolution() |
||||
{ |
||||
solution = new Solution(new MockProjectChangeWatcher()); |
||||
CreatePad(solution); |
||||
} |
||||
|
||||
IProject AddProjectToSolution() |
||||
{ |
||||
var project = new MockCSharpProject(solution, "MyProject"); |
||||
solution.AddFolder(project); |
||||
return project; |
||||
} |
||||
|
||||
[Test] |
||||
public void GetProjects_NullSolution_ReturnsNoProjects() |
||||
{ |
||||
CreatePadWithNullSolution(); |
||||
|
||||
int count = pad.GetProjects().Length; |
||||
|
||||
Assert.AreEqual(0, count); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetProjects_SolutionHasOneProject_ReturnsOneProject() |
||||
{ |
||||
CreatePadWithSolution(); |
||||
IProject project = AddProjectToSolution(); |
||||
var expectedProjects = new IProject[] { project }; |
||||
|
||||
IProject[] projects = pad.GetProjects(); |
||||
|
||||
CollectionAssert.AreEqual(expectedProjects, projects); |
||||
} |
||||
} |
||||
} |
@ -1,38 +0,0 @@
@@ -1,38 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.UnitTesting; |
||||
using NUnit.Framework; |
||||
using UnitTesting.Tests.Utils; |
||||
|
||||
namespace UnitTesting.Tests.Tree |
||||
{ |
||||
[TestFixture] |
||||
public class NoTestsRunWhenUnitTestPadNotCreatedTestFixture |
||||
{ |
||||
DerivedRunTestCommand runTestCommand; |
||||
MockRunTestCommandContext runTestCommandContext; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
runTestCommandContext = new MockRunTestCommandContext(); |
||||
runTestCommand = new DerivedRunTestCommand(runTestCommandContext); |
||||
} |
||||
|
||||
[Test] |
||||
public void RunTestCommandRunMethodDoesNotThrowNullReferenceException() |
||||
{ |
||||
Assert.DoesNotThrow(delegate { runTestCommand.Run(); }); |
||||
} |
||||
|
||||
[Test] |
||||
public void OnBeforeRunIsNotCalled() |
||||
{ |
||||
runTestCommand.Run(); |
||||
Assert.IsFalse(runTestCommand.IsOnBeforeBuildMethodCalled); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue