1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
5
using ICSharpCode.Core;
6
using ICSharpCode.SharpDevelop;
7
using ICSharpCode.SharpDevelop.Dom;
8
using ICSharpCode.SharpDevelop.Gui;
9
using ICSharpCode.SharpDevelop.Project;
10
using ICSharpCode.UnitTesting;
11
using NUnit.Framework;
12
using UnitTesting.Tests.Utils;
14
namespace UnitTesting.Tests.Tree
17
public class RunProjectTestsTestFixture : RunTestCommandTestFixtureBase
19
MockCSharpProject project;
20
TestProject testProject;
21
TestResult errorTestResult;
22
TestMethod firstTestMethod;
23
TestResult warningTestResult;
24
TestMethod secondTestMethod;
25
TestResult successTestResult;
26
TestMethod thirdTestMethod;
27
MockTestFramework testFramework;
28
bool runningTestsBeforeTestsFinishedCalled;
35
project = new MockCSharpProject();
36
context.MockUnitTestsPad.AddProject(project);
38
string[] methodNames = new string[] { "FirstTest", "SecondTest", "ThirdTest" };
41
TestProjectHelper.CreateTestProjectWithTestClassTestMethods(project,
42
"MyTests.MyTestClass",
45
TestClass testClass = testProject.TestClasses[0];
46
firstTestMethod = testClass.TestMethods[0];
47
secondTestMethod = testClass.TestMethods[1];
48
thirdTestMethod = testClass.TestMethods[2];
50
context.MockUnitTestsPad.AddTestProject(testProject);
52
MockBuildProjectBeforeTestRun buildProjectBeforeTestRun = new MockBuildProjectBeforeTestRun();
53
context.MockBuildProjectFactory.AddBuildProjectBeforeTestRun(buildProjectBeforeTestRun);
55
context.UnitTestingOptions.NoThread = true;
56
context.UnitTestingOptions.NoShadow = true;
57
context.UnitTestingOptions.NoLogo = true;
58
context.UnitTestingOptions.NoDots = true;
59
context.UnitTestingOptions.Labels = true;
60
context.UnitTestingOptions.CreateXmlOutputFile = true;
62
testFramework = new MockTestFramework();
63
context.MockRegisteredTestFrameworks.AddTestFrameworkForProject(project, testFramework);
67
buildProjectBeforeTestRun.FireBuildCompleteEvent();
69
errorTestResult = new TestResult("MyTests.MyTestClass.FirstTest");
70
errorTestResult.ResultType = TestResultType.Failure;
72
warningTestResult = new TestResult("MyTests.MyTestClass.SecondTest");
73
warningTestResult.ResultType = TestResultType.Ignored;
75
successTestResult = new TestResult("MyTests.MyTestClass.ThirdTest");
76
successTestResult.ResultType = TestResultType.Success;
78
context.MockUnitTestWorkbench.MakeSafeThreadAsyncMethodCallsWithArguments = true;
79
MockTestRunner testRunner = runTestCommand.TestRunnersCreated[0];
80
testRunner.FireTestFinishedEvent(errorTestResult);
81
testRunner.FireTestFinishedEvent(warningTestResult);
82
testRunner.FireTestFinishedEvent(successTestResult);
84
context.MockUnitTestsPad.IsUpdateToolbarMethodCalled = false;
85
runningTestsBeforeTestsFinishedCalled = AbstractRunTestCommand.IsRunningTest;
86
runTestCommand.CallTestsCompleted();
90
public void RegisteredTestFrameworksReturnsTestFrameworkForProject()
92
Assert.AreEqual(testFramework, context.MockRegisteredTestFrameworks.GetTestFrameworkForProject(project));
96
public void FirstSafeAsyncMethodCallWithArgsIsMadeOnRunTestCommandShowResultsMethod()
98
ActionArguments<TestResult> actionArgs = new ActionArguments<TestResult>();
99
actionArgs.Action = runTestCommand.ShowResultAction;
100
actionArgs.Arg = errorTestResult;
102
Assert.AreEqual(actionArgs, context.MockUnitTestWorkbench.SafeThreadAsyncMethodCallsWithArguments[0]);
106
public void FirstTaskAddedToTaskServiceIsErrorTask()
108
Task expectedTask = TestResultTask.Create(errorTestResult, testProject);
109
TaskComparison taskComparison = new TaskComparison(expectedTask, context.MockTaskService.Tasks[0]);
110
Assert.IsTrue(taskComparison.IsMatch, taskComparison.MismatchReason);
114
public void FirstTaskMethodRegionIsTakenFromTestProject()
116
DomRegion expectedRegion = new DomRegion(4, 19);
117
Task task = context.MockTaskService.Tasks[0];
118
DomRegion region = new DomRegion(task.Line, task.Column);
119
Assert.AreEqual(expectedRegion, region);
123
public void UnitTestsPadGetProjectReturnsTestProject()
125
Assert.AreEqual(testProject, context.MockUnitTestsPad.GetTestProject(testProject.Project));
129
public void FirstTestMethodResultTypeIsFailure()
131
Assert.AreEqual(TestResultType.Failure, firstTestMethod.Result);
135
public void SecondTaskAddedToTaskServiceIsWarningTask()
137
Task expectedTask = TestResultTask.Create(warningTestResult, testProject);
138
TaskComparison taskComparison = new TaskComparison(expectedTask, context.MockTaskService.Tasks[1]);
139
Assert.IsTrue(taskComparison.IsMatch, taskComparison.MismatchReason);
143
public void SecondTestMethodResultTypeIsIgnored()
145
Assert.AreEqual(TestResultType.Ignored, secondTestMethod.Result);
149
public void TaskServiceOnlyHasTwoTasksSinceSuccessTestResultsDoNotCreateTasks()
151
Assert.AreEqual(2, context.MockTaskService.Tasks.Count);
155
public void ThirdTestMethodResultTypeIsSuccess()
157
Assert.AreEqual(TestResultType.Success, thirdTestMethod.Result);
161
public void IsRunningTestsReturnsTrueBeforeTestsFinishedMethodIsCalled()
163
Assert.IsTrue(runningTestsBeforeTestsFinishedCalled);
167
public void IsRunningTestsReturnsTrueAfterTestsFinishedMethodCalled()
169
Assert.IsFalse(AbstractRunTestCommand.IsRunningTest);
173
public void IsUnitTestsPadToolbarUpdatedAfterTestFinishedMethodCalled()
175
Assert.IsTrue(context.MockUnitTestsPad.IsUpdateToolbarMethodCalled);
179
public void OnAfterRunTestsCalledAfterTestFinishedMethodCalled()
181
Assert.IsTrue(runTestCommand.IsOnAfterRunTestsMethodCalled);
185
public void ErrorListPadDescriptorExistsInWorkbench()
187
Assert.IsNotNull(context.MockUnitTestWorkbench.GetPad(typeof(ErrorListPad)));
191
public void ErrorListPadBroughtToFrontAfterTestsFinishedCalled()
193
Action expectedAction = context.MockUnitTestWorkbench.ErrorListPadDescriptor.BringPadToFront;
194
Assert.AreEqual(expectedAction, context.MockUnitTestWorkbench.SafeThreadAsyncMethodCalls[1]);