~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/Analysis/UnitTesting/Test/Tree/RunProjectTestsTestFixture.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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)
 
3
 
 
4
using System;
 
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;
 
13
 
 
14
namespace UnitTesting.Tests.Tree
 
15
{
 
16
        [TestFixture]
 
17
        public class RunProjectTestsTestFixture : RunTestCommandTestFixtureBase
 
18
        {
 
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;
 
29
                
 
30
                [SetUp]
 
31
                public void Init()
 
32
                {
 
33
                        base.InitBase();
 
34
                        
 
35
                        project = new MockCSharpProject();
 
36
                        context.MockUnitTestsPad.AddProject(project);
 
37
                        
 
38
                        string[] methodNames = new string[] { "FirstTest", "SecondTest", "ThirdTest" };
 
39
                        
 
40
                        testProject = 
 
41
                                TestProjectHelper.CreateTestProjectWithTestClassTestMethods(project,
 
42
                                        "MyTests.MyTestClass",
 
43
                                        methodNames);
 
44
                        
 
45
                        TestClass testClass = testProject.TestClasses[0];
 
46
                        firstTestMethod = testClass.TestMethods[0];
 
47
                        secondTestMethod = testClass.TestMethods[1];
 
48
                        thirdTestMethod = testClass.TestMethods[2];
 
49
                        
 
50
                        context.MockUnitTestsPad.AddTestProject(testProject);
 
51
                        
 
52
                        MockBuildProjectBeforeTestRun buildProjectBeforeTestRun = new MockBuildProjectBeforeTestRun();
 
53
                        context.MockBuildProjectFactory.AddBuildProjectBeforeTestRun(buildProjectBeforeTestRun);
 
54
                        
 
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;
 
61
                        
 
62
                        testFramework = new MockTestFramework();
 
63
                        context.MockRegisteredTestFrameworks.AddTestFrameworkForProject(project, testFramework);
 
64
                        
 
65
                        runTestCommand.Run();
 
66
                        
 
67
                        buildProjectBeforeTestRun.FireBuildCompleteEvent();
 
68
                        
 
69
                        errorTestResult = new TestResult("MyTests.MyTestClass.FirstTest");
 
70
                        errorTestResult.ResultType = TestResultType.Failure;
 
71
                        
 
72
                        warningTestResult = new TestResult("MyTests.MyTestClass.SecondTest");
 
73
                        warningTestResult.ResultType = TestResultType.Ignored;
 
74
                        
 
75
                        successTestResult = new TestResult("MyTests.MyTestClass.ThirdTest");
 
76
                        successTestResult.ResultType = TestResultType.Success;
 
77
                        
 
78
                        context.MockUnitTestWorkbench.MakeSafeThreadAsyncMethodCallsWithArguments = true;
 
79
                        MockTestRunner testRunner = runTestCommand.TestRunnersCreated[0];
 
80
                        testRunner.FireTestFinishedEvent(errorTestResult);
 
81
                        testRunner.FireTestFinishedEvent(warningTestResult);
 
82
                        testRunner.FireTestFinishedEvent(successTestResult);
 
83
                        
 
84
                        context.MockUnitTestsPad.IsUpdateToolbarMethodCalled = false;
 
85
                        runningTestsBeforeTestsFinishedCalled = AbstractRunTestCommand.IsRunningTest;
 
86
                        runTestCommand.CallTestsCompleted();
 
87
                }
 
88
                
 
89
                [Test]
 
90
                public void RegisteredTestFrameworksReturnsTestFrameworkForProject()
 
91
                {
 
92
                        Assert.AreEqual(testFramework, context.MockRegisteredTestFrameworks.GetTestFrameworkForProject(project));
 
93
                }
 
94
                
 
95
                [Test]
 
96
                public void FirstSafeAsyncMethodCallWithArgsIsMadeOnRunTestCommandShowResultsMethod()
 
97
                {
 
98
                        ActionArguments<TestResult> actionArgs = new ActionArguments<TestResult>();
 
99
                        actionArgs.Action = runTestCommand.ShowResultAction;
 
100
                        actionArgs.Arg = errorTestResult;
 
101
                        
 
102
                        Assert.AreEqual(actionArgs, context.MockUnitTestWorkbench.SafeThreadAsyncMethodCallsWithArguments[0]);
 
103
                }
 
104
                
 
105
                [Test]
 
106
                public void FirstTaskAddedToTaskServiceIsErrorTask()
 
107
                {
 
108
                        Task expectedTask = TestResultTask.Create(errorTestResult, testProject);
 
109
                        TaskComparison taskComparison = new TaskComparison(expectedTask, context.MockTaskService.Tasks[0]);
 
110
                        Assert.IsTrue(taskComparison.IsMatch, taskComparison.MismatchReason);
 
111
                }
 
112
                
 
113
                [Test]
 
114
                public void FirstTaskMethodRegionIsTakenFromTestProject()
 
115
                {
 
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);
 
120
                }
 
121
                
 
122
                [Test]
 
123
                public void UnitTestsPadGetProjectReturnsTestProject()
 
124
                {
 
125
                        Assert.AreEqual(testProject, context.MockUnitTestsPad.GetTestProject(testProject.Project));
 
126
                }
 
127
                
 
128
                [Test]
 
129
                public void FirstTestMethodResultTypeIsFailure()
 
130
                {
 
131
                        Assert.AreEqual(TestResultType.Failure, firstTestMethod.Result);
 
132
                }
 
133
                
 
134
                [Test]
 
135
                public void SecondTaskAddedToTaskServiceIsWarningTask()
 
136
                {
 
137
                        Task expectedTask = TestResultTask.Create(warningTestResult, testProject);
 
138
                        TaskComparison taskComparison = new TaskComparison(expectedTask, context.MockTaskService.Tasks[1]);
 
139
                        Assert.IsTrue(taskComparison.IsMatch, taskComparison.MismatchReason);
 
140
                }
 
141
                
 
142
                [Test]
 
143
                public void SecondTestMethodResultTypeIsIgnored()
 
144
                {
 
145
                        Assert.AreEqual(TestResultType.Ignored, secondTestMethod.Result);
 
146
                }
 
147
                
 
148
                [Test]
 
149
                public void TaskServiceOnlyHasTwoTasksSinceSuccessTestResultsDoNotCreateTasks()
 
150
                {
 
151
                        Assert.AreEqual(2, context.MockTaskService.Tasks.Count);
 
152
                }
 
153
                
 
154
                [Test]
 
155
                public void ThirdTestMethodResultTypeIsSuccess()
 
156
                {
 
157
                        Assert.AreEqual(TestResultType.Success, thirdTestMethod.Result);
 
158
                }
 
159
                
 
160
                [Test]
 
161
                public void IsRunningTestsReturnsTrueBeforeTestsFinishedMethodIsCalled()
 
162
                {
 
163
                        Assert.IsTrue(runningTestsBeforeTestsFinishedCalled);
 
164
                }
 
165
                
 
166
                [Test]
 
167
                public void IsRunningTestsReturnsTrueAfterTestsFinishedMethodCalled()
 
168
                {
 
169
                        Assert.IsFalse(AbstractRunTestCommand.IsRunningTest);
 
170
                }
 
171
                
 
172
                [Test]
 
173
                public void IsUnitTestsPadToolbarUpdatedAfterTestFinishedMethodCalled()
 
174
                {
 
175
                        Assert.IsTrue(context.MockUnitTestsPad.IsUpdateToolbarMethodCalled);
 
176
                }
 
177
                
 
178
                [Test]
 
179
                public void OnAfterRunTestsCalledAfterTestFinishedMethodCalled()
 
180
                {
 
181
                        Assert.IsTrue(runTestCommand.IsOnAfterRunTestsMethodCalled);
 
182
                }
 
183
                
 
184
                [Test]
 
185
                public void ErrorListPadDescriptorExistsInWorkbench()
 
186
                {
 
187
                        Assert.IsNotNull(context.MockUnitTestWorkbench.GetPad(typeof(ErrorListPad)));
 
188
                }
 
189
                
 
190
                [Test]
 
191
                public void ErrorListPadBroughtToFrontAfterTestsFinishedCalled()
 
192
                {
 
193
                        Action expectedAction = context.MockUnitTestWorkbench.ErrorListPadDescriptor.BringPadToFront;
 
194
                        Assert.AreEqual(expectedAction, context.MockUnitTestWorkbench.SafeThreadAsyncMethodCalls[1]);
 
195
                }
 
196
        }
 
197
}