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 System.Collections.Generic;
6
using System.Diagnostics;
8
using ICSharpCode.Core;
9
using ICSharpCode.Profiler.AddIn;
10
using ICSharpCode.Profiler.Controller.Data;
11
using ICSharpCode.SharpDevelop;
12
using ICSharpCode.SharpDevelop.Dom;
13
using ICSharpCode.SharpDevelop.Gui;
14
using ICSharpCode.UnitTesting;
16
namespace ICSharpCode.Profiler.AddIn
18
public class ProfilerTestRunner : TestRunnerBase
20
ProfilerRunner runner;
21
UnitTestingOptions options = new UnitTestingOptions();
22
TestResultsMonitor testResultsMonitor;
24
public ProfilerTestRunner()
28
public override void Start(SelectedTests selectedTests)
30
ProcessStartInfo startInfo = GetProcessStartInfo(selectedTests);
31
Start(startInfo, selectedTests);
34
protected override ProcessStartInfo GetProcessStartInfo(SelectedTests selectedTests)
36
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests, options);
37
testResultsMonitor = new TestResultsMonitor();
38
app.Results = testResultsMonitor.FileName;
39
return app.GetProcessStartInfo();
42
void Start(ProcessStartInfo startInfo, SelectedTests selectedTests)
44
LogCommandLine(startInfo);
46
string path = selectedTests.Project.GetSessionFileName();
48
LoggingService.Info("starting profiler...");
50
runner = new ProfilerRunner(startInfo, true, new UnitTestWriter(new ProfilingDataSQLiteWriter(path), GetUnitTestNames(selectedTests).ToArray()));
52
runner.RunFinished += delegate {
53
WorkbenchSingleton.SafeThreadCall(() => FileService.OpenFile(path));
54
AfterFinish(selectedTests, path);
57
testResultsMonitor.TestFinished += OnTestFinished;
58
testResultsMonitor.Start();
62
IEnumerable<string> GetUnitTestNames(SelectedTests selectedTests)
64
IProjectContent content = ParserService.GetProjectContent(selectedTests.Project);
66
if (selectedTests.Class == null) {
67
var testClasses = content.Classes
68
.Where(c => c.Attributes.Any(a => a.AttributeType.FullyQualifiedName == "NUnit.Framework.TestFixtureAttribute"));
70
.SelectMany(c2 => c2.Methods)
71
.Where(m => m.Attributes.Any(a2 => a2.AttributeType.FullyQualifiedName == "NUnit.Framework.TestAttribute"))
72
.Select(m2 => m2.FullyQualifiedName);
75
if (selectedTests.Method == null) {
76
return content.Classes
77
.Where(c => c.FullyQualifiedName == selectedTests.Class.DotNetName).First().Methods
78
.Where(m => m.Attributes.Any(a2 => a2.AttributeType.FullyQualifiedName == "NUnit.Framework.TestAttribute"))
79
.Select(m2 => m2.FullyQualifiedName);
82
return new[] { selectedTests.Class.DotNetName + "." + selectedTests.Method.Name };
85
void AfterFinish(SelectedTests selectedTests, string path)
87
selectedTests.Project.AddSessionToProject(path);
88
OnAllTestsFinished(this, new EventArgs());
89
LoggingService.Info("shutting profiler down...");
92
public override void Stop()
94
if (this.runner != null && this.runner.Profiler.IsRunning) {
95
LoggingService.Info("stopping profiler...");
99
if (testResultsMonitor != null) {
100
testResultsMonitor.Stop();
101
testResultsMonitor.Read();
102
testResultsMonitor = null;
106
public override void Dispose()