Browse Source

Unit testing addin can now be extended with custom test runners.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5844 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Matt Ward 15 years ago
parent
commit
daee118e45
  1. 20
      src/AddIns/Analysis/CodeCoverage/Project/Src/RunTestWithCodeCoverageCommand.cs
  2. 1
      src/AddIns/Analysis/Profiler/Frontend/AddIn/Profiler.AddIn.csproj
  3. 72
      src/AddIns/Analysis/Profiler/Frontend/AddIn/Src/Commands/RunTestWithProfilerCommand.cs
  4. 115
      src/AddIns/Analysis/Profiler/Frontend/AddIn/Src/ProfilerTestRunner.cs
  5. 332
      src/AddIns/Analysis/UnitTesting/Src/AbstractRunTestCommands.cs
  6. 44
      src/AddIns/Analysis/UnitTesting/Src/BuildProjectBeforeTestRun.cs
  7. 37
      src/AddIns/Analysis/UnitTesting/Src/EmptyUnitTestsPad.cs
  8. 17
      src/AddIns/Analysis/UnitTesting/Src/IAddInTree.cs
  9. 16
      src/AddIns/Analysis/UnitTesting/Src/IBuildOptions.cs
  10. 17
      src/AddIns/Analysis/UnitTesting/Src/IBuildProjectFactory.cs
  11. 26
      src/AddIns/Analysis/UnitTesting/Src/IRegisteredTestFrameworks.cs
  12. 25
      src/AddIns/Analysis/UnitTesting/Src/IRunTestCommandContext.cs
  13. 16
      src/AddIns/Analysis/UnitTesting/Src/ITestFrameworkFactory.cs
  14. 22
      src/AddIns/Analysis/UnitTesting/Src/ITestResultsMonitor.cs
  15. 21
      src/AddIns/Analysis/UnitTesting/Src/ITestRunner.cs
  16. 19
      src/AddIns/Analysis/UnitTesting/Src/IUnitTestDebuggerService.cs
  17. 18
      src/AddIns/Analysis/UnitTesting/Src/IUnitTestFileService.cs
  18. 17
      src/AddIns/Analysis/UnitTesting/Src/IUnitTestMessageService.cs
  19. 25
      src/AddIns/Analysis/UnitTesting/Src/IUnitTestProcessRunner.cs
  20. 16
      src/AddIns/Analysis/UnitTesting/Src/IUnitTestSaveAllFilesCommand.cs
  21. 23
      src/AddIns/Analysis/UnitTesting/Src/IUnitTestTaskService.cs
  22. 19
      src/AddIns/Analysis/UnitTesting/Src/IUnitTestWorkbench.cs
  23. 21
      src/AddIns/Analysis/UnitTesting/Src/IUnitTestsPad.cs
  24. 27
      src/AddIns/Analysis/UnitTesting/Src/MessageReceivedEventArgs.cs
  25. 108
      src/AddIns/Analysis/UnitTesting/Src/NUnitConsoleCommandLine.cs
  26. 47
      src/AddIns/Analysis/UnitTesting/Src/NUnitTestDebugger.cs
  27. 115
      src/AddIns/Analysis/UnitTesting/Src/NUnitTestFramework.cs
  28. 41
      src/AddIns/Analysis/UnitTesting/Src/NUnitTestResult.cs
  29. 45
      src/AddIns/Analysis/UnitTesting/Src/NUnitTestRunner.cs
  30. 113
      src/AddIns/Analysis/UnitTesting/Src/RegisteredTestFrameworks.cs
  31. 30
      src/AddIns/Analysis/UnitTesting/Src/RunAllTestsInPadCommand.cs
  32. 47
      src/AddIns/Analysis/UnitTesting/Src/RunProjectTestsInPadCommand.cs
  33. 61
      src/AddIns/Analysis/UnitTesting/Src/RunTestCommandContext.cs
  34. 550
      src/AddIns/Analysis/UnitTesting/Src/RunTestCommands.cs
  35. 30
      src/AddIns/Analysis/UnitTesting/Src/RunTestInPadCommand.cs
  36. 30
      src/AddIns/Analysis/UnitTesting/Src/RunTestWithDebuggerCommand.cs
  37. 96
      src/AddIns/Analysis/UnitTesting/Src/SelectedTests.cs
  38. 12
      src/AddIns/Analysis/UnitTesting/Src/TestAttributeName.cs
  39. 55
      src/AddIns/Analysis/UnitTesting/Src/TestClass.cs
  40. 112
      src/AddIns/Analysis/UnitTesting/Src/TestDebuggerBase.cs
  41. 6
      src/AddIns/Analysis/UnitTesting/Src/TestFinishedEventArgs.cs
  42. 25
      src/AddIns/Analysis/UnitTesting/Src/TestFramework.cs
  43. 81
      src/AddIns/Analysis/UnitTesting/Src/TestFrameworkDescriptor.cs
  44. 34
      src/AddIns/Analysis/UnitTesting/Src/TestFrameworkDoozer.cs
  45. 27
      src/AddIns/Analysis/UnitTesting/Src/TestFrameworkFactory.cs
  46. 38
      src/AddIns/Analysis/UnitTesting/Src/TestMethod.cs
  47. 82
      src/AddIns/Analysis/UnitTesting/Src/TestProcessRunnerBase.cs
  48. 68
      src/AddIns/Analysis/UnitTesting/Src/TestProject.cs
  49. 58
      src/AddIns/Analysis/UnitTesting/Src/TestResult.cs
  50. 102
      src/AddIns/Analysis/UnitTesting/Src/TestResultTask.cs
  51. 21
      src/AddIns/Analysis/UnitTesting/Src/TestResultsMonitor.cs
  52. 8
      src/AddIns/Analysis/UnitTesting/Src/TestResultsReader.cs
  53. 72
      src/AddIns/Analysis/UnitTesting/Src/TestRunnerBase.cs
  54. 51
      src/AddIns/Analysis/UnitTesting/Src/TestService.cs
  55. 142
      src/AddIns/Analysis/UnitTesting/Src/TestTreeView.cs
  56. 42
      src/AddIns/Analysis/UnitTesting/Src/TestableCondition.cs
  57. 21
      src/AddIns/Analysis/UnitTesting/Src/UnitTestAddInTree.cs
  58. 19
      src/AddIns/Analysis/UnitTesting/Src/UnitTestBuildOptions.cs
  59. 20
      src/AddIns/Analysis/UnitTesting/Src/UnitTestBuildProjectFactory.cs
  60. 48
      src/AddIns/Analysis/UnitTesting/Src/UnitTestCommands.cs
  61. 23
      src/AddIns/Analysis/UnitTesting/Src/UnitTestDebuggerService.cs
  62. 25
      src/AddIns/Analysis/UnitTesting/Src/UnitTestFileService.cs
  63. 20
      src/AddIns/Analysis/UnitTesting/Src/UnitTestMessageService.cs
  64. 57
      src/AddIns/Analysis/UnitTesting/Src/UnitTestProcessRunner.cs
  65. 19
      src/AddIns/Analysis/UnitTesting/Src/UnitTestSaveAllFilesCommand.cs
  66. 39
      src/AddIns/Analysis/UnitTesting/Src/UnitTestTaskService.cs
  67. 31
      src/AddIns/Analysis/UnitTesting/Src/UnitTestWorkbench.cs
  68. 79
      src/AddIns/Analysis/UnitTesting/Src/UnitTestsPad.cs
  69. 47
      src/AddIns/Analysis/UnitTesting/Test/Frameworks/CreateNUnitTestRunnerTestFixture.cs
  70. 266
      src/AddIns/Analysis/UnitTesting/Test/Frameworks/NUnitConsoleCommandLineTests.cs
  71. 36
      src/AddIns/Analysis/UnitTesting/Test/Frameworks/NUnitConsoleExeSelectedTestFixture.cs
  72. 62
      src/AddIns/Analysis/UnitTesting/Test/Frameworks/NUnitConsoleProcessStartInfoTestFixture.cs
  73. 90
      src/AddIns/Analysis/UnitTesting/Test/Frameworks/NUnitTestFrameworkIsTestClassTests.cs
  74. 113
      src/AddIns/Analysis/UnitTesting/Test/Frameworks/NUnitTestFrameworkIsTestMethodTests.cs
  75. 96
      src/AddIns/Analysis/UnitTesting/Test/Frameworks/NUnitTestFrameworkIsTestProjectTests.cs
  76. 74
      src/AddIns/Analysis/UnitTesting/Test/Frameworks/NUnitTestResultFailureTestFixture.cs
  77. 240
      src/AddIns/Analysis/UnitTesting/Test/Frameworks/RegisteredTestFrameworksTestFixture.cs
  78. 50
      src/AddIns/Analysis/UnitTesting/Test/Frameworks/TestFrameworkDescriptorIgnoresProjectFileExtensionWhitespaceTestFixture.cs
  79. 50
      src/AddIns/Analysis/UnitTesting/Test/Frameworks/TestFrameworkDescriptorSupportsCSharpAndVBNetProjectsTestFixture.cs
  80. 65
      src/AddIns/Analysis/UnitTesting/Test/Frameworks/TestFrameworkDescriptorSupportsCSharpProjectsTestFixture.cs
  81. 50
      src/AddIns/Analysis/UnitTesting/Test/Frameworks/TestFrameworkDescriptorSupportsUpperCaseProjectFileExtensionsTestFixture.cs
  82. 77
      src/AddIns/Analysis/UnitTesting/Test/Frameworks/TestFrameworkDoozerTestFixture.cs
  83. 2
      src/AddIns/Analysis/UnitTesting/Test/Frameworks/TestResultsReaderTests.cs
  84. 84
      src/AddIns/Analysis/UnitTesting/Test/Frameworks/TestableConditionIsValidForClassNodeTestFixture.cs
  85. 67
      src/AddIns/Analysis/UnitTesting/Test/Frameworks/TestableConditionIsValidMethodTestFixture.cs
  86. 2
      src/AddIns/Analysis/UnitTesting/Test/Frameworks/UnitTestingOptionsPanelTestFixture.cs
  87. 2
      src/AddIns/Analysis/UnitTesting/Test/Frameworks/UnitTestingOptionsTestFixture.cs
  88. 21
      src/AddIns/Analysis/UnitTesting/Test/Project/AbstractBaseClassWithTestMethodsTestFixture.cs
  89. 2
      src/AddIns/Analysis/UnitTesting/Test/Project/BaseTestMethodTestFixture.cs
  90. 17
      src/AddIns/Analysis/UnitTesting/Test/Project/ClassRootNamespaceTests.cs
  91. 4
      src/AddIns/Analysis/UnitTesting/Test/Project/ClassWithTwoChildNamespacesTestFixture.cs
  92. 26
      src/AddIns/Analysis/UnitTesting/Test/Project/DuplicateClassNameChangedTestFixture.cs
  93. 10
      src/AddIns/Analysis/UnitTesting/Test/Project/DuplicateClassNameTestFixture.cs
  94. 16
      src/AddIns/Analysis/UnitTesting/Test/Project/DuplicateMethodNameTestFixture.cs
  95. 13
      src/AddIns/Analysis/UnitTesting/Test/Project/DuplicateProjectRootNamespaceTestFixture.cs
  96. 24
      src/AddIns/Analysis/UnitTesting/Test/Project/EmptyProjectTestFixture.cs
  97. 12
      src/AddIns/Analysis/UnitTesting/Test/Project/EmptyRootNamespaceTestFixture.cs
  98. 13
      src/AddIns/Analysis/UnitTesting/Test/Project/InnerClassMethodRenamedTestFixture.cs
  99. 8
      src/AddIns/Analysis/UnitTesting/Test/Project/InnerClassNameChangesTestFixture.cs
  100. 9
      src/AddIns/Analysis/UnitTesting/Test/Project/InnerClassTestFixtureAttributeRemovedTestFixture.cs
  101. Some files were not shown because too many files have changed in this diff Show More

20
src/AddIns/Analysis/CodeCoverage/Project/Src/RunTestWithCodeCoverageCommand.cs

@ -34,9 +34,9 @@ namespace ICSharpCode.CodeCoverage @@ -34,9 +34,9 @@ namespace ICSharpCode.CodeCoverage
runner.OutputLineReceived += OutputLineReceived;
}
protected override void RunTests(UnitTestApplicationStartHelper helper)
protected override void RunTests(NUnitConsoleApplication app)
{
SetPartCoverRunnerProperties(helper);
SetPartCoverRunnerProperties(app);
RunPartCover();
}
@ -62,7 +62,7 @@ namespace ICSharpCode.CodeCoverage @@ -62,7 +62,7 @@ namespace ICSharpCode.CodeCoverage
protected override void OnAfterRunTests()
{
if (!TaskService.HasCriticalErrors(false)) {
ShowPad(WorkbenchSingleton.Workbench.GetPad(typeof(CodeCoveragePad)));
ShowPad(Context.Workbench.GetPad(typeof(CodeCoveragePad)));
}
}
@ -78,10 +78,10 @@ namespace ICSharpCode.CodeCoverage @@ -78,10 +78,10 @@ namespace ICSharpCode.CodeCoverage
}
}
void SetPartCoverRunnerProperties(UnitTestApplicationStartHelper helper)
void SetPartCoverRunnerProperties(NUnitConsoleApplication app)
{
string partCoverOutputDirectory = GetPartCoverOutputDirectory(helper.Project);
PartCoverSettings settings = GetPartCoverSettings(helper.Project);
string partCoverOutputDirectory = GetPartCoverOutputDirectory(app.Project);
PartCoverSettings settings = GetPartCoverSettings(app.Project);
// By default get the code coverage for everything if
// no include or exclude regular expressions have been
@ -94,9 +94,9 @@ namespace ICSharpCode.CodeCoverage @@ -94,9 +94,9 @@ namespace ICSharpCode.CodeCoverage
}
runner.PartCoverFileName = GetPartCoverFileName();
runner.Target = helper.UnitTestApplication;
runner.TargetArguments = helper.GetArguments();
runner.TargetWorkingDirectory = Path.GetDirectoryName(helper.Assemblies[0]);
runner.Target = app.FileName;
runner.TargetArguments = app.GetArguments();
runner.TargetWorkingDirectory = Path.GetDirectoryName(app.Assemblies[0]);
runner.Output = Path.Combine(partCoverOutputDirectory, "Coverage.Xml");
AddStringsToCollection(settings.Include, runner.Include);
AddStringsToCollection(settings.Exclude, runner.Exclude);
@ -128,7 +128,7 @@ namespace ICSharpCode.CodeCoverage @@ -128,7 +128,7 @@ namespace ICSharpCode.CodeCoverage
void PartCoverExited(object sender, PartCoverExitEventArgs e)
{
DisplayCoverageResults(runner.Output);
WorkbenchSingleton.SafeThreadAsyncCall(TestsFinished);
WorkbenchSingleton.SafeThreadAsyncCall(TestRunCompleted);
}
void OutputLineReceived(object sender, LineReceivedEventArgs e)

1
src/AddIns/Analysis/Profiler/Frontend/AddIn/Profiler.AddIn.csproj

@ -89,6 +89,7 @@ @@ -89,6 +89,7 @@
</Compile>
<Compile Include="Src\OptionPanels\OptionWrapper.cs" />
<Compile Include="Src\ProfilerRunner.cs" />
<Compile Include="Src\ProfilerTestRunner.cs" />
<Compile Include="Src\SharpDevelopTranslation.cs" />
<Compile Include="Src\Views\ComparisonView.xaml.cs">
<DependentUpon>ComparisonView.xaml</DependentUpon>

72
src/AddIns/Analysis/Profiler/Frontend/AddIn/Src/Commands/RunTestWithProfilerCommand.cs

@ -5,82 +5,16 @@ @@ -5,82 +5,16 @@
// <version>$Revision$</version>
// </file>
using ICSharpCode.SharpDevelop.Gui;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using ICSharpCode.Core;
using ICSharpCode.Profiler.AddIn;
using ICSharpCode.Profiler.Controller.Data;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.UnitTesting;
namespace ICSharpCode.Profiler.AddIn.Commands
{
public class RunTestWithProfilerCommand : AbstractRunTestCommand
{
ProfilerRunner runner;
protected override void RunTests(UnitTestApplicationStartHelper helper)
{
TestRunnerCategory.AppendLine(helper.GetCommandLine());
ProcessStartInfo startInfo = new ProcessStartInfo(helper.UnitTestApplication);
string path = helper.Project.GetSessionFileName();
startInfo.Arguments = helper.GetArguments();
startInfo.WorkingDirectory = UnitTestApplicationStartHelper.UnitTestApplicationDirectory;
LoggingService.Info("starting profiler...");
runner = new ProfilerRunner(startInfo, true, new UnitTestWriter(new ProfilingDataSQLiteWriter(path), GetUnitTestNames(helper).ToArray()));
runner.RunFinished += delegate {
WorkbenchSingleton.SafeThreadCall(() => FileService.OpenFile(path));
AfterFinish(helper, path);
};
runner.Run();
}
IEnumerable<string> GetUnitTestNames(UnitTestApplicationStartHelper helper)
{
IProjectContent content = ParserService.GetProjectContent(helper.Project);
if (helper.Fixture == null) {
var testClasses = content.Classes
.Where(c => c.Attributes.Any(a => a.AttributeType.FullyQualifiedName == "NUnit.Framework.TestFixtureAttribute"));
return testClasses
.SelectMany(c2 => c2.Methods)
.Where(m => m.Attributes.Any(a2 => a2.AttributeType.FullyQualifiedName == "NUnit.Framework.TestAttribute"))
.Select(m2 => m2.FullyQualifiedName);
}
if (helper.Test == null) {
return content.Classes
.Where(c => c.FullyQualifiedName == helper.Fixture).First().Methods
.Where(m => m.Attributes.Any(a2 => a2.AttributeType.FullyQualifiedName == "NUnit.Framework.TestAttribute"))
.Select(m2 => m2.FullyQualifiedName);
}
return new[] { helper.Fixture + "." + helper.Test };
}
void AfterFinish(UnitTestApplicationStartHelper helper, string path)
{
helper.Project.AddSessionToProject(path);
WorkbenchSingleton.SafeThreadAsyncCall(TestsFinished);
LoggingService.Info("shutting profiler down...");
}
protected override void OnStop()
protected override ITestRunner CreateTestRunner(IProject project)
{
if (this.runner != null && this.runner.Profiler.IsRunning) {
LoggingService.Info("stopping profiler...");
runner.Stop();
}
return new ProfilerTestRunner();
}
}
}

115
src/AddIns/Analysis/Profiler/Frontend/AddIn/Src/ProfilerTestRunner.cs

@ -0,0 +1,115 @@ @@ -0,0 +1,115 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Siegfried Pammer" email="sie_pam@gmx.at"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using ICSharpCode.Core;
using ICSharpCode.Profiler.AddIn;
using ICSharpCode.Profiler.Controller.Data;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.UnitTesting;
namespace ICSharpCode.Profiler.AddIn
{
public class ProfilerTestRunner : TestRunnerBase
{
ProfilerRunner runner;
UnitTestingOptions options = new UnitTestingOptions();
TestResultsMonitor testResultsMonitor;
public ProfilerTestRunner()
{
}
public override void Start(SelectedTests selectedTests)
{
ProcessStartInfo startInfo = GetProcessStartInfo(selectedTests);
Start(startInfo, selectedTests);
}
protected override ProcessStartInfo GetProcessStartInfo(SelectedTests selectedTests)
{
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests, options);
testResultsMonitor = new TestResultsMonitor();
app.Results = testResultsMonitor.FileName;
return app.GetProcessStartInfo();
}
void Start(ProcessStartInfo startInfo, SelectedTests selectedTests)
{
LogCommandLine(startInfo);
string path = selectedTests.Project.GetSessionFileName();
LoggingService.Info("starting profiler...");
runner = new ProfilerRunner(startInfo, true, new UnitTestWriter(new ProfilingDataSQLiteWriter(path), GetUnitTestNames(selectedTests).ToArray()));
runner.RunFinished += delegate {
WorkbenchSingleton.SafeThreadCall(() => FileService.OpenFile(path));
AfterFinish(selectedTests, path);
};
testResultsMonitor.TestFinished += OnTestFinished;
testResultsMonitor.Start();
runner.Run();
}
IEnumerable<string> GetUnitTestNames(SelectedTests selectedTests)
{
IProjectContent content = ParserService.GetProjectContent(selectedTests.Project);
if (selectedTests.Class == null) {
var testClasses = content.Classes
.Where(c => c.Attributes.Any(a => a.AttributeType.FullyQualifiedName == "NUnit.Framework.TestFixtureAttribute"));
return testClasses
.SelectMany(c2 => c2.Methods)
.Where(m => m.Attributes.Any(a2 => a2.AttributeType.FullyQualifiedName == "NUnit.Framework.TestAttribute"))
.Select(m2 => m2.FullyQualifiedName);
}
if (selectedTests.Method == null) {
return content.Classes
.Where(c => c.FullyQualifiedName == selectedTests.Class.DotNetName).First().Methods
.Where(m => m.Attributes.Any(a2 => a2.AttributeType.FullyQualifiedName == "NUnit.Framework.TestAttribute"))
.Select(m2 => m2.FullyQualifiedName);
}
return new[] { selectedTests.Class.DotNetName + "." + selectedTests.Method.Name };
}
void AfterFinish(SelectedTests selectedTests, string path)
{
selectedTests.Project.AddSessionToProject(path);
OnAllTestsFinished(this, new EventArgs());
LoggingService.Info("shutting profiler down...");
}
public override void Stop()
{
if (this.runner != null && this.runner.Profiler.IsRunning) {
LoggingService.Info("stopping profiler...");
runner.Stop();
}
if (testResultsMonitor != null) {
testResultsMonitor.Stop();
testResultsMonitor.Read();
testResultsMonitor = null;
}
}
public override void Dispose()
{
Stop();
}
}
}

332
src/AddIns/Analysis/UnitTesting/Src/AbstractRunTestCommands.cs

@ -0,0 +1,332 @@ @@ -0,0 +1,332 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.IO;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.UnitTesting
{
public abstract class AbstractRunTestCommand : AbstractMenuCommand
{
static AbstractRunTestCommand runningTestCommand;
IUnitTestsPad unitTestsPad;
SelectedTests selectedTests;
IRunTestCommandContext context;
ITestRunner testRunner;
public AbstractRunTestCommand()
: this(new RunTestCommandContext())
{
}
public AbstractRunTestCommand(IRunTestCommandContext context)
{
this.context = context;
}
protected IRunTestCommandContext Context {
get { return context; }
}
/// <summary>
/// Gets the running test command.
/// </summary>
public static AbstractRunTestCommand RunningTestCommand {
get { return runningTestCommand; }
set { runningTestCommand = value; }
}
/// <summary>
/// Gets whether a test is currently running.
/// </summary>
public static bool IsRunningTest {
get { return runningTestCommand != null; }
}
public override void Run()
{
GetUnitTestsPad(context.OpenUnitTestsPad);
selectedTests = new SelectedTests(Owner, this.unitTestsPad.GetProjects());
if (selectedTests.HasProjects) {
runningTestCommand = this;
BeforeRun();
RunTests();
}
}
void GetUnitTestsPad(IUnitTestsPad unitTestsPad)
{
if (unitTestsPad != null) {
this.unitTestsPad = unitTestsPad;
} else {
this.unitTestsPad = new EmptyUnitTestsPad();
}
}
/// <summary>
/// Sets the initial workbench state before starting
/// a test run.
/// </summary>
void BeforeRun()
{
ClearTasks();
ClearUnitTestCategoryText();
ShowUnitTestsPad();
ShowOutputPad();
UpdateUnitTestsPadToolbar();
ResetAllTestResultsInUnitTestsPad();
OnBeforeRunTests();
}
void RunTests()
{
if (IsBuildNeededBeforeTestRun()) {
BuildProjectBeforeRunningTests(selectedTests);
} else {
context.SaveAllFilesCommand.SaveAllFiles();
RunTests(selectedTests);
}
}
bool IsBuildNeededBeforeTestRun()
{
return context.RegisteredTestFrameworks.IsBuildNeededBeforeTestRunForProject(selectedTests.Project);
}
void ClearTasks()
{
context.TaskService.BuildMessageViewCategory.ClearText();
context.TaskService.InUpdate = true;
context.TaskService.ClearExceptCommentTasks();
context.TaskService.InUpdate = false;
}
void ClearUnitTestCategoryText()
{
context.UnitTestCategory.ClearText();
}
void ShowUnitTestsPad()
{
unitTestsPad.BringToFront();
}
void UpdateUnitTestsPadToolbar()
{
unitTestsPad.UpdateToolbar();
}
/// <summary>
/// Called before all tests are run. If multiple projects are
/// to be tested this is called only once.
/// </summary>
protected virtual void OnBeforeRunTests()
{
}
/// <summary>
/// Runs the tests after building the project under test.
/// </summary>
void BuildProjectBeforeRunningTests(SelectedTests selectedTests)
{
BuildProjectBeforeTestRun build = CreateBuildProjectBeforeTestRun(selectedTests);
build.BuildComplete += delegate {
OnBuildComplete(build.LastBuildResults, selectedTests);
};
build.Run();
}
BuildProjectBeforeTestRun CreateBuildProjectBeforeTestRun(SelectedTests selectedTests)
{
return context.BuildProjectFactory.CreateBuildProjectBeforeTestRun(selectedTests.Project);
}
/// <summary>
/// Stops running the tests.
/// </summary>
public void Stop()
{
StopActiveTestRunner();
runningTestCommand = null;
UpdateUnitTestsPadToolbar();
OnStop();
}
void StopActiveTestRunner()
{
if (testRunner != null) {
testRunner.Stop();
testRunner.Dispose();
testRunner = null;
}
}
/// <summary>
/// Called after all tests have been run even if there have
/// been errors. If multiple projects are to be tested this is called only once.
/// </summary>
protected virtual void OnAfterRunTests()
{
}
protected virtual void RunTests(NUnitConsoleApplication helper)
{
}
/// <summary>
/// Called by derived classes when a single test run
/// is finished.
/// </summary>
protected void TestRunCompleted()
{
StopActiveTestRunner();
selectedTests.RemoveFirstProject();
if (selectedTests.HasProjects) {
RunTests();
} else {
runningTestCommand = null;
UpdateUnitTestsPadToolbar();
ShowErrorList();
OnAfterRunTests();
}
}
void TestFinished(object source, TestFinishedEventArgs e)
{
context.Workbench.SafeThreadAsyncCall(ShowResult, e.Result);
}
protected void ShowResult(TestResult result)
{
if (IsTestResultFailureOrIsIgnored(result)) {
AddTaskForTestResult(result);
}
UpdateTestResult(result);
}
bool IsTestResultFailureOrIsIgnored(TestResult result)
{
return result.IsFailure || result.IsIgnored;
}
void AddTaskForTestResult(TestResult testResult)
{
TestProject project = GetTestProjectForProject(selectedTests.Project);
Task task = TestResultTask.Create(testResult, project);
context.TaskService.Add(task);
}
/// <summary>
/// Called when the test run should be stopped.
/// </summary>
protected virtual void OnStop()
{
}
void ShowOutputPad()
{
ShowPad(context.Workbench.GetPad(typeof(CompilerMessageView)));
}
protected void ShowPad(PadDescriptor padDescriptor)
{
context.Workbench.SafeThreadAsyncCall(padDescriptor.BringPadToFront);
}
void ShowErrorList()
{
if (HasErrorsThatShouldBeDisplayed()) {
ShowPad(context.Workbench.GetPad(typeof(ErrorListPad)));
}
}
bool HasErrorsThatShouldBeDisplayed()
{
return context.TaskService.SomethingWentWrong &&
context.BuildOptions.ShowErrorListAfterBuild;
}
/// <summary>
/// Runs the test for the project after a successful build.
/// </summary>
void OnBuildComplete(BuildResults results, SelectedTests selectedTests)
{
if (BuildHasNoErrorsAndStillRunningTests(results)) {
RunTests(selectedTests);
} else {
if (IsRunningTest) {
Stop();
}
ShowErrorList();
}
}
bool BuildHasNoErrorsAndStillRunningTests(BuildResults results)
{
return (results.ErrorCount == 0) && IsRunningTest;
}
void RunTests(SelectedTests selectedTests)
{
testRunner = CreateTestRunner(selectedTests.Project);
if (testRunner != null) {
testRunner.MessageReceived += TestRunnerMessageReceived;
testRunner.AllTestsFinished += AllTestsFinished;
testRunner.TestFinished += TestFinished;
testRunner.Start(selectedTests);
}
}
protected virtual ITestRunner CreateTestRunner(IProject project)
{
return null;
}
void TestRunnerMessageReceived(object source, MessageReceivedEventArgs e)
{
context.UnitTestCategory.AppendLine(e.Message);
}
void AllTestsFinished(object source, EventArgs e)
{
context.Workbench.SafeThreadAsyncCall(TestRunCompleted);
}
/// <summary>
/// Clears the test results in the test tree view for all the
/// displayed projects.
/// </summary>
void ResetAllTestResultsInUnitTestsPad()
{
unitTestsPad.ResetTestResults();
}
TestProject GetTestProjectForProject(IProject project)
{
return unitTestsPad.GetTestProject(project);
}
void UpdateTestResult(TestResult result)
{
TestProject testProject = GetTestProjectForProject(selectedTests.Project);
if (testProject != null) {
testProject.UpdateTestResult(result);
}
}
}
}

44
src/AddIns/Analysis/UnitTesting/Src/BuildProjectBeforeTestRun.cs

@ -0,0 +1,44 @@ @@ -0,0 +1,44 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.SharpDevelop.Project.Commands;
namespace ICSharpCode.UnitTesting
{
/// <summary>
/// Custom build command that makes sure errors and warnings
/// are not cleared from the Errors list before every build since
/// we may be running multiple tests after each other.
/// </summary>
public class BuildProjectBeforeTestRun : BuildProjectBeforeExecute
{
IUnitTestSaveAllFilesCommand saveAllFilesCommand;
public BuildProjectBeforeTestRun(IProject targetProject,
IUnitTestSaveAllFilesCommand saveAllFilesCommand)
: base(targetProject)
{
this.saveAllFilesCommand = saveAllFilesCommand;
}
public BuildProjectBeforeTestRun(IProject targetProject)
: this(targetProject, new UnitTestSaveAllFilesCommand())
{
}
/// <summary>
/// Before a build do not clear the tasks, just save any
/// dirty files.
/// </summary>
public override void BeforeBuild()
{
saveAllFilesCommand.SaveAllFiles();
}
}
}

37
src/AddIns/Analysis/UnitTesting/Src/EmptyUnitTestsPad.cs

@ -0,0 +1,37 @@ @@ -0,0 +1,37 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.UnitTesting
{
public class EmptyUnitTestsPad : IUnitTestsPad
{
public void UpdateToolbar()
{
}
public void BringToFront()
{
}
public void ResetTestResults()
{
}
public IProject[] GetProjects()
{
return new IProject[0];
}
public TestProject GetTestProject(IProject project)
{
return null;
}
}
}

17
src/AddIns/Analysis/UnitTesting/Src/IAddInTree.cs

@ -0,0 +1,17 @@ @@ -0,0 +1,17 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
namespace ICSharpCode.UnitTesting
{
public interface IAddInTree
{
List<T> BuildItems<T>(string path, object caller);
}
}

16
src/AddIns/Analysis/UnitTesting/Src/IBuildOptions.cs

@ -0,0 +1,16 @@ @@ -0,0 +1,16 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
namespace ICSharpCode.UnitTesting
{
public interface IBuildOptions
{
bool ShowErrorListAfterBuild { get; }
}
}

17
src/AddIns/Analysis/UnitTesting/Src/IBuildProjectFactory.cs

@ -0,0 +1,17 @@ @@ -0,0 +1,17 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.UnitTesting
{
public interface IBuildProjectFactory
{
BuildProjectBeforeTestRun CreateBuildProjectBeforeTestRun(IProject project);
}
}

26
src/AddIns/Analysis/UnitTesting/Src/IRegisteredTestFrameworks.cs

@ -0,0 +1,26 @@ @@ -0,0 +1,26 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.UnitTesting
{
public interface IRegisteredTestFrameworks
{
ITestFramework GetTestFrameworkForProject(IProject project);
ITestRunner CreateTestRunner(IProject project);
ITestRunner CreateTestDebugger(IProject project);
bool IsTestMethod(IMember member);
bool IsTestClass(IClass c);
bool IsTestProject(IProject project);
bool IsBuildNeededBeforeTestRunForProject(IProject project);
}
}

25
src/AddIns/Analysis/UnitTesting/Src/IRunTestCommandContext.cs

@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.UnitTesting
{
public interface IRunTestCommandContext
{
IRegisteredTestFrameworks RegisteredTestFrameworks { get; }
IUnitTestTaskService TaskService { get; }
IUnitTestWorkbench Workbench { get; }
IBuildProjectFactory BuildProjectFactory { get; }
IBuildOptions BuildOptions { get; }
MessageViewCategory UnitTestCategory { get; }
IUnitTestsPad OpenUnitTestsPad { get; }
IUnitTestMessageService MessageService { get; }
IUnitTestSaveAllFilesCommand SaveAllFilesCommand { get; }
}
}

16
src/AddIns/Analysis/UnitTesting/Src/ITestFrameworkFactory.cs

@ -0,0 +1,16 @@ @@ -0,0 +1,16 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
namespace ICSharpCode.UnitTesting
{
public interface ITestFrameworkFactory
{
ITestFramework Create(string className);
}
}

22
src/AddIns/Analysis/UnitTesting/Src/ITestResultsMonitor.cs

@ -0,0 +1,22 @@ @@ -0,0 +1,22 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
namespace ICSharpCode.UnitTesting
{
public interface ITestResultsMonitor : IDisposable
{
event TestFinishedEventHandler TestFinished;
string FileName { get; set; }
void Stop();
void Start();
void Read();
}
}

21
src/AddIns/Analysis/UnitTesting/Src/ITestRunner.cs

@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.SharpDevelop.Util;
namespace ICSharpCode.UnitTesting
{
public interface ITestRunner : IDisposable
{
event TestFinishedEventHandler TestFinished;
event EventHandler AllTestsFinished;
event MessageReceivedEventHandler MessageReceived;
void Start(SelectedTests selectedTests);
void Stop();
}
}

19
src/AddIns/Analysis/UnitTesting/Src/IUnitTestDebuggerService.cs

@ -0,0 +1,19 @@ @@ -0,0 +1,19 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Data;
using ICSharpCode.SharpDevelop.Debugging;
namespace ICSharpCode.UnitTesting
{
public interface IUnitTestDebuggerService
{
bool IsDebuggerLoaded { get; }
IDebugger CurrentDebugger { get; }
}
}

18
src/AddIns/Analysis/UnitTesting/Src/IUnitTestFileService.cs

@ -0,0 +1,18 @@ @@ -0,0 +1,18 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
namespace ICSharpCode.UnitTesting
{
public interface IUnitTestFileService
{
void OpenFile(string fileName);
void JumpToFilePosition(string fileName, int line, int column);
}
}

17
src/AddIns/Analysis/UnitTesting/Src/IUnitTestMessageService.cs

@ -0,0 +1,17 @@ @@ -0,0 +1,17 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
namespace ICSharpCode.UnitTesting
{
public interface IUnitTestMessageService
{
bool AskQuestion(string question, string caption);
}
}

25
src/AddIns/Analysis/UnitTesting/Src/IUnitTestProcessRunner.cs

@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.SharpDevelop.Util;
namespace ICSharpCode.UnitTesting
{
public interface IUnitTestProcessRunner
{
bool LogStandardOutputAndError { get; set; }
string WorkingDirectory { get; set; }
void Start(string command, string arguments);
void Kill();
event LineReceivedEventHandler OutputLineReceived;
event LineReceivedEventHandler ErrorLineReceived;
event EventHandler ProcessExited;
}
}

16
src/AddIns/Analysis/UnitTesting/Src/IUnitTestSaveAllFilesCommand.cs

@ -0,0 +1,16 @@ @@ -0,0 +1,16 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
namespace ICSharpCode.UnitTesting
{
public interface IUnitTestSaveAllFilesCommand
{
void SaveAllFiles();
}
}

23
src/AddIns/Analysis/UnitTesting/Src/IUnitTestTaskService.cs

@ -0,0 +1,23 @@ @@ -0,0 +1,23 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.UnitTesting
{
public interface IUnitTestTaskService
{
MessageViewCategory BuildMessageViewCategory { get; }
bool InUpdate { get; set; }
void ClearExceptCommentTasks();
void Add(Task task);
bool SomethingWentWrong { get; }
}
}

19
src/AddIns/Analysis/UnitTesting/Src/IUnitTestWorkbench.cs

@ -0,0 +1,19 @@ @@ -0,0 +1,19 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.SharpDevelop;
namespace ICSharpCode.UnitTesting
{
public interface IUnitTestWorkbench
{
PadDescriptor GetPad(Type type);
void SafeThreadAsyncCall(Action method);
void SafeThreadAsyncCall<A>(Action<A> method, A arg1);
}
}

21
src/AddIns/Analysis/UnitTesting/Src/IUnitTestsPad.cs

@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.UnitTesting
{
public interface IUnitTestsPad
{
void UpdateToolbar();
void BringToFront();
void ResetTestResults();
IProject[] GetProjects();
TestProject GetTestProject(IProject project);
}
}

27
src/AddIns/Analysis/UnitTesting/Src/MessageReceivedEventArgs.cs

@ -0,0 +1,27 @@ @@ -0,0 +1,27 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
namespace ICSharpCode.UnitTesting
{
public delegate void MessageReceivedEventHandler(object sender, MessageReceivedEventArgs e);
public class MessageReceivedEventArgs : EventArgs
{
string message;
public MessageReceivedEventArgs(string message)
{
this.message = message;
}
public string Message {
get { return message; }
}
}
}

108
src/AddIns/Analysis/UnitTesting/Src/UnitTestApplicationStartHelper.cs → src/AddIns/Analysis/UnitTesting/Src/NUnitConsoleCommandLine.cs

@ -1,12 +1,13 @@ @@ -1,12 +1,13 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
@ -18,25 +19,67 @@ using ICSharpCode.SharpDevelop.Project; @@ -18,25 +19,67 @@ using ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.UnitTesting
{
/// <summary>
/// Helper to run the unit testing console application.
/// </summary>
public class UnitTestApplicationStartHelper
public class NUnitConsoleApplication
{
public NUnitConsoleApplication(SelectedTests selectedTests, UnitTestingOptions options)
{
Initialize(selectedTests);
InitializeOptions(options);
}
public NUnitConsoleApplication(SelectedTests selectedTests)
{
Initialize(selectedTests);
}
void Initialize(SelectedTests selectedTests)
{
this.selectedTests = selectedTests;
this.project = selectedTests.Project;
Assemblies.Add(project.OutputAssemblyFullPath);
if (selectedTests.NamespaceFilter != null) {
NamespaceFilter = selectedTests.NamespaceFilter;
}
if (selectedTests.Class != null) {
Fixture = selectedTests.Class.DotNetName;
if (selectedTests.Method != null) {
Test = selectedTests.Method.Name;
}
}
}
void InitializeOptions(UnitTestingOptions options)
{
NoThread = options.NoThread;
NoLogo = options.NoLogo;
NoDots = options.NoDots;
Labels = options.Labels;
ShadowCopy = !options.NoShadow;
if (options.CreateXmlOutputFile) {
GenerateXmlOutputFileName();
}
}
void GenerateXmlOutputFileName()
{
string directory = Path.GetDirectoryName(project.OutputAssemblyFullPath);
string fileName = project.AssemblyName + "-TestResult.xml";
XmlOutputFile = Path.Combine(directory, fileName);
}
/// <summary>
/// returns full/path/to/Tools/NUnit
/// </summary>
public static string UnitTestApplicationDirectory {
get {
return Path.Combine(FileUtility.ApplicationRootPath, @"bin\Tools\NUnit");
}
string WorkingDirectory {
get { return Path.Combine(FileUtility.ApplicationRootPath, @"bin\Tools\NUnit"); }
}
/// <summary>
/// returns full/path/to/Tools/NUnit/nunit-console.exe (or whichever nunit-console exe is right
/// for the project - there are different .exes for .NET 4.0 and for x86-only projects.
/// returns full/path/to/Tools/NUnit/nunit-console.exe or nunit-console-x86.exe if the
/// project platform target is x86.
/// </summary>
public string UnitTestApplication {
public string FileName {
get {
string exe = "nunit-console";
if (ProjectUsesDotnet20Runtime(project)) {
@ -46,7 +89,7 @@ namespace ICSharpCode.UnitTesting @@ -46,7 +89,7 @@ namespace ICSharpCode.UnitTesting
exe += "-x86";
}
exe += ".exe";
return Path.Combine(UnitTestApplicationDirectory, exe);
return Path.Combine(WorkingDirectory, exe);
}
}
@ -104,36 +147,23 @@ namespace ICSharpCode.UnitTesting @@ -104,36 +147,23 @@ namespace ICSharpCode.UnitTesting
public string NamespaceFilter;
IProject project;
SelectedTests selectedTests;
public void Initialize(IProject project, IClass fixture, IMember test)
{
Initialize(project, null, fixture, test);
public SelectedTests SelectedTests {
get { return selectedTests; }
}
public void Initialize(IProject project, string namespaceFilter)
{
Initialize(project, namespaceFilter, null, null);
public IProject Project {
get { return project; }
}
public void Initialize(IProject project, string namespaceFilter, IClass fixture, IMember test)
public ProcessStartInfo GetProcessStartInfo()
{
this.project = project;
Assemblies.Add(project.OutputAssemblyFullPath);
if (namespaceFilter != null) {
NamespaceFilter = namespaceFilter;
}
if (fixture != null) {
Fixture = fixture.DotNetName;
if (test != null) {
Test = test.Name;
}
}
}
public IProject Project {
get {
return project;
}
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = FileName;
startInfo.Arguments = GetArguments();
startInfo.WorkingDirectory = WorkingDirectory;
return startInfo;
}
/// <summary>
@ -143,7 +173,7 @@ namespace ICSharpCode.UnitTesting @@ -143,7 +173,7 @@ namespace ICSharpCode.UnitTesting
/// </summary>
public string GetCommandLine()
{
return String.Concat("\"", UnitTestApplication, "\" ", GetArguments());
return String.Format("\"{0}\" {1}", FileName, GetArguments());
}
/// <summary>
@ -207,7 +237,7 @@ namespace ICSharpCode.UnitTesting @@ -207,7 +237,7 @@ namespace ICSharpCode.UnitTesting
MSBuildBasedProject msbuildProject = project as MSBuildBasedProject;
if (msbuildProject != null) {
string platformTarget = msbuildProject.GetEvaluatedProperty("PlatformTarget");
return String.Equals(platformTarget, "x86", StringComparison.OrdinalIgnoreCase);
return String.Compare(platformTarget, "x86", true) == 0;
}
return false;
}

47
src/AddIns/Analysis/UnitTesting/Src/NUnitTestDebugger.cs

@ -0,0 +1,47 @@ @@ -0,0 +1,47 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Diagnostics;
using ICSharpCode.SharpDevelop.Debugging;
namespace ICSharpCode.UnitTesting
{
public class NUnitTestDebugger : TestDebuggerBase
{
UnitTestingOptions options;
public NUnitTestDebugger()
: this(new UnitTestDebuggerService(),
new UnitTestMessageService(),
new TestResultsMonitor(),
new UnitTestingOptions())
{
}
public NUnitTestDebugger(IUnitTestDebuggerService debuggerService,
IUnitTestMessageService messageService,
ITestResultsMonitor testResultsMonitor,
UnitTestingOptions options)
: base(debuggerService, messageService, testResultsMonitor)
{
this.options = options;
}
protected override ProcessStartInfo GetProcessStartInfo(SelectedTests selectedTests)
{
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests, options);
app.Results = base.TestResultsMonitor.FileName;
return app.GetProcessStartInfo();
}
protected override TestResult CreateTestResultForTestFramework(TestResult testResult)
{
return new NUnitTestResult(testResult);
}
}
}

115
src/AddIns/Analysis/UnitTesting/Src/NUnitTestFramework.cs

@ -0,0 +1,115 @@ @@ -0,0 +1,115 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.UnitTesting
{
public class NUnitTestFramework : ITestFramework
{
/// <summary>
/// Determines whether the project is a test project. A project
/// is considered to be a test project if it contains a reference
/// to the NUnit.Framework assembly.
/// </summary>
public bool IsTestProject(IProject project)
{
if (project != null) {
foreach (ProjectItem projectItem in project.Items) {
ReferenceProjectItem referenceProjectItem = projectItem as ReferenceProjectItem;
if (IsNUnitFrameworkAssemblyReference(referenceProjectItem)) {
return true;
}
}
}
return false;
}
bool IsNUnitFrameworkAssemblyReference(ReferenceProjectItem referenceProjectItem)
{
if (referenceProjectItem != null) {
string name = referenceProjectItem.ShortName;
return name.Equals("NUnit.Framework", StringComparison.OrdinalIgnoreCase);
}
return false;
}
/// <summary>
/// Determines whether the class is a test fixture. A class
/// is considered to be a test class if it contains a TestFixture attribute.
/// </summary>
public bool IsTestClass(IClass c)
{
StringComparer nameComparer = GetNameComparer(c);
if (nameComparer != null) {
NUnitTestAttributeName testAttributeName = new NUnitTestAttributeName("TestFixture", nameComparer);
foreach (IAttribute attribute in c.Attributes) {
if (testAttributeName.IsEqual(attribute)) {
return true;
}
}
}
return false;
}
StringComparer GetNameComparer(IClass c)
{
if (c != null) {
IProjectContent projectContent = c.ProjectContent;
if (projectContent != null) {
LanguageProperties language = projectContent.Language;
if (language != null) {
return language.NameComparer;
}
}
}
return null;
}
/// <summary>
/// Determines whether the method is a test method. A method
/// is considered to be a test method if it contains the NUnit Test attribute.
/// If the method has parameters it cannot be a test method.
/// </summary>
public bool IsTestMethod(IMember member)
{
if (member == null) {
return false;
}
StringComparer nameComparer = GetNameComparer(member.DeclaringType);
if (nameComparer != null) {
NUnitTestAttributeName testAttribute = new NUnitTestAttributeName("Test", nameComparer);
foreach (IAttribute attribute in member.Attributes) {
if (testAttribute.IsEqual(attribute)) {
IMethod method = (IMethod)member;
if (method.Parameters.Count == 0) {
return true;
}
}
}
}
return false;
}
public bool IsBuildNeededBeforeTestRun {
get { return true; }
}
public ITestRunner CreateTestRunner()
{
return new NUnitTestRunner();
}
public ITestRunner CreateTestDebugger()
{
return new NUnitTestDebugger();
}
}
}

41
src/AddIns/Analysis/UnitTesting/Src/NUnitTestResult.cs

@ -0,0 +1,41 @@ @@ -0,0 +1,41 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.IO;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.UnitTesting
{
public class NUnitTestResult : TestResult
{
public NUnitTestResult(TestResult testResult)
: base(testResult.Name)
{
Message = testResult.Message;
ResultType = testResult.ResultType;
StackTrace = testResult.StackTrace;
}
protected override void OnStackTraceChanged()
{
FileLineReference fileLineRef = OutputTextLineParser.GetNUnitOutputFileLineReference(StackTrace, true);
if (fileLineRef != null) {
StackTraceFilePosition = CreateFilePosition(fileLineRef);
} else {
StackTraceFilePosition = FilePosition.Empty;
}
}
FilePosition CreateFilePosition(FileLineReference fileLineRef)
{
string fileName = Path.GetFullPath(fileLineRef.FileName);
return new FilePosition(fileName, fileLineRef.Line, fileLineRef.Column + 1);
}
}
}

45
src/AddIns/Analysis/UnitTesting/Src/NUnitTestRunner.cs

@ -0,0 +1,45 @@ @@ -0,0 +1,45 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Diagnostics;
using ICSharpCode.SharpDevelop.Util;
namespace ICSharpCode.UnitTesting
{
public class NUnitTestRunner : TestProcessRunnerBase
{
UnitTestingOptions options;
public NUnitTestRunner()
: this(new UnitTestProcessRunner(),
new TestResultsMonitor(),
new UnitTestingOptions())
{
}
public NUnitTestRunner(IUnitTestProcessRunner processRunner,
ITestResultsMonitor testResultsMonitor,
UnitTestingOptions options)
: base(processRunner, testResultsMonitor)
{
this.options = options;
}
protected override ProcessStartInfo GetProcessStartInfo(SelectedTests selectedTests)
{
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests, options);
app.Results = base.TestResultsMonitor.FileName;
return app.GetProcessStartInfo();
}
protected override TestResult CreateTestResultForTestFramework(TestResult testResult)
{
return new NUnitTestResult(testResult);
}
}
}

113
src/AddIns/Analysis/UnitTesting/Src/RegisteredTestFrameworks.cs

@ -0,0 +1,113 @@ @@ -0,0 +1,113 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.UnitTesting
{
public class RegisteredTestFrameworks : IRegisteredTestFrameworks
{
List<TestFrameworkDescriptor> testFrameworkDescriptors;
public const string AddInPath = "/SharpDevelop/UnitTesting/TestFrameworks";
public RegisteredTestFrameworks(IAddInTree addInTree)
{
testFrameworkDescriptors = addInTree.BuildItems<TestFrameworkDescriptor>(AddInPath, null);
}
public ITestFramework GetTestFrameworkForProject(IProject project)
{
if (project != null) {
foreach (TestFrameworkDescriptor descriptor in testFrameworkDescriptors) {
if (descriptor.IsSupportedProject(project)) {
return descriptor.TestFramework;
}
}
}
return null;
}
public bool IsTestMethod(IMember member)
{
ITestFramework testFramework = GetTestFramework(member);
if (testFramework != null) {
return testFramework.IsTestMethod(member);
}
return false;
}
ITestFramework GetTestFramework(IMember member)
{
if (member != null) {
return GetTestFramework(member.DeclaringType);
}
return null;
}
ITestFramework GetTestFramework(IClass c)
{
IProject project = GetProject(c);
return GetTestFrameworkForProject(project);
}
IProject GetProject(IClass c)
{
if (c != null) {
return c.ProjectContent.Project as IProject;
}
return null;
}
public bool IsTestClass(IClass c)
{
ITestFramework testFramework = GetTestFramework(c);
if (testFramework != null) {
return testFramework.IsTestClass(c);
}
return false;
}
public bool IsTestProject(IProject project)
{
ITestFramework testFramework = GetTestFrameworkForProject(project);
if (testFramework != null) {
return testFramework.IsTestProject(project);
}
return false;
}
public ITestRunner CreateTestRunner(IProject project)
{
ITestFramework testFramework = GetTestFrameworkForProject(project);
if (testFramework != null) {
return testFramework.CreateTestRunner();
}
return null;
}
public ITestRunner CreateTestDebugger(IProject project)
{
ITestFramework testFramework = GetTestFrameworkForProject(project);
if (testFramework != null) {
return testFramework.CreateTestDebugger();
}
return null;
}
public bool IsBuildNeededBeforeTestRunForProject(IProject project)
{
ITestFramework testFramework = GetTestFrameworkForProject(project);
if (testFramework != null) {
return testFramework.IsBuildNeededBeforeTestRun;
}
return true;
}
}
}

30
src/AddIns/Analysis/UnitTesting/Src/RunAllTestsInPadCommand.cs

@ -0,0 +1,30 @@ @@ -0,0 +1,30 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
namespace ICSharpCode.UnitTesting
{
public class RunAllTestsInPadCommand : RunTestInPadCommand
{
public RunAllTestsInPadCommand()
{
}
public RunAllTestsInPadCommand(IRunTestCommandContext context)
: base(context)
{
}
public override void Run()
{
// To make sure all tests are run we set the Owner to null.
Owner = null;
base.Run();
}
}
}

47
src/AddIns/Analysis/UnitTesting/Src/RunProjectTestsInPadCommand.cs

@ -0,0 +1,47 @@ @@ -0,0 +1,47 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.UnitTesting
{
public class RunProjectTestsInPadCommand : RunTestInPadCommand, ITestTreeView
{
public RunProjectTestsInPadCommand()
{
}
public RunProjectTestsInPadCommand(IRunTestCommandContext context)
: base(context)
{
}
public override void Run()
{
Owner = this;
base.Run();
}
public IMember SelectedMethod {
get { return null; }
}
public IClass SelectedClass {
get { return null; }
}
public IProject SelectedProject {
get { return ProjectService.CurrentProject; }
}
public string SelectedNamespace {
get { return null; }
}
}
}

61
src/AddIns/Analysis/UnitTesting/Src/RunTestCommandContext.cs

@ -0,0 +1,61 @@ @@ -0,0 +1,61 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.UnitTesting
{
public class RunTestCommandContext : IRunTestCommandContext
{
UnitTestingOptions options = new UnitTestingOptions();
IRegisteredTestFrameworks testFrameworks = TestService.RegisteredTestFrameworks;
UnitTestTaskService taskService = new UnitTestTaskService();
UnitTestWorkbench workbench = new UnitTestWorkbench();
UnitTestBuildProjectFactory buildProjectFactory = new UnitTestBuildProjectFactory();
UnitTestBuildOptions buildOptions = new UnitTestBuildOptions();
MessageViewCategory unitTestCategory = TestService.UnitTestMessageView;
UnitTestMessageService messageService = new UnitTestMessageService();
UnitTestSaveAllFilesCommand saveAllFilesCommand = new UnitTestSaveAllFilesCommand();
public IRegisteredTestFrameworks RegisteredTestFrameworks {
get { return testFrameworks; }
}
public IUnitTestTaskService TaskService {
get { return taskService; }
}
public IUnitTestWorkbench Workbench {
get { return workbench; }
}
public IBuildProjectFactory BuildProjectFactory {
get { return buildProjectFactory; }
}
public IBuildOptions BuildOptions {
get { return buildOptions; }
}
public MessageViewCategory UnitTestCategory {
get { return unitTestCategory; }
}
public IUnitTestsPad OpenUnitTestsPad {
get { return UnitTestsPad.Instance; }
}
public IUnitTestMessageService MessageService {
get { return messageService; }
}
public IUnitTestSaveAllFilesCommand SaveAllFilesCommand {
get { return saveAllFilesCommand; }
}
}
}

550
src/AddIns/Analysis/UnitTesting/Src/RunTestCommands.cs

@ -1,550 +0,0 @@ @@ -1,550 +0,0 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Commands;
using ICSharpCode.SharpDevelop.Debugging;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.SharpDevelop.Project.Commands;
using ICSharpCode.SharpDevelop.Util;
namespace ICSharpCode.UnitTesting
{
public abstract class AbstractRunTestCommand : AbstractMenuCommand
{
static MessageViewCategory testRunnerCategory;
static AbstractRunTestCommand runningTestCommand;
List<IProject> projects;
IProject currentProject;
TestResultsMonitor testResultsMonitor;
public AbstractRunTestCommand()
{
testResultsMonitor = new TestResultsMonitor();
testResultsMonitor.TestFinished += TestFinished;
}
/// <summary>
/// Gets the running test command.
/// </summary>
public static AbstractRunTestCommand RunningTestCommand {
get {
return runningTestCommand;
}
}
/// <summary>
/// Gets whether a test is currently running.
/// </summary>
public static bool IsRunningTest {
get {
return runningTestCommand != null;
}
}
public override void Run()
{
projects = new List<IProject>();
IMember m = TestableCondition.GetMember(Owner);
IClass c = (m != null) ? m.DeclaringType : TestableCondition.GetClass(Owner);
IProject project = TestableCondition.GetProject(Owner);
string namespaceFilter = TestableCondition.GetNamespace(Owner);
if (project != null) {
projects.Add(project);
} else if (UnitTestsPad.Instance != null) {
projects.AddRange(UnitTestsPad.Instance.TestTreeView.GetProjects());
}
if (projects.Count > 0) {
runningTestCommand = this;
try {
BeforeRun();
if (IsRunningTest) {
currentProject = projects[0];
Run(currentProject, namespaceFilter, c, m);
}
} catch {
runningTestCommand = null;
throw;
}
}
}
public static MessageViewCategory TestRunnerCategory {
get {
if (testRunnerCategory == null) {
MessageViewCategory.Create(ref testRunnerCategory, "UnitTesting", "${res:ICSharpCode.NUnitPad.NUnitPadContent.PadName}");
}
return testRunnerCategory;
}
}
/// <summary>
/// Stops running the tests.
/// </summary>
public void Stop()
{
runningTestCommand = null;
UpdateUnitTestsPadToolbar();
projects.Clear();
testResultsMonitor.Stop();
StopMonitoring();
OnStop();
}
/// <summary>
/// Called before all tests are run. If multiple projects are
/// to be tested this is called only once.
/// </summary>
protected virtual void OnBeforeRunTests()
{
}
/// <summary>
/// Called after all tests have been run even if there have
/// been errors. If multiple projects are to be tested this is called only once.
/// </summary>
protected virtual void OnAfterRunTests()
{
}
protected abstract void RunTests(UnitTestApplicationStartHelper helper);
/// <summary>
/// Called by derived classes when a single test run
/// is finished.
/// </summary>
protected void TestsFinished()
{
WorkbenchSingleton.AssertMainThread();
// Read the rest of the file just in case.
testResultsMonitor.Stop();
testResultsMonitor.Read();
StopMonitoring();
projects.Remove(currentProject);
if (projects.Count > 0) {
currentProject = projects[0];
Run(currentProject, null, null, null);
} else {
runningTestCommand = null;
UpdateUnitTestsPadToolbar();
if (TaskService.SomethingWentWrong && ErrorListPad.ShowAfterBuild) {
ShowErrorList();
}
OnAfterRunTests();
}
}
/// <summary>
/// Called by derived classes to show a single test result.
/// </summary>
protected void ShowResult(TestResult result)
{
if (result.IsFailure || result.IsIgnored) {
TaskService.Add(CreateTask(result));
}
UpdateTestResult(result);
}
/// <summary>
/// Called when the test run should be stopped.
/// </summary>
protected virtual void OnStop()
{
}
/// <summary>
/// Brings the specified pad to the front.
/// </summary>
protected void ShowPad(PadDescriptor padDescriptor)
{
if (padDescriptor != null) {
WorkbenchSingleton.SafeThreadAsyncCall(padDescriptor.BringPadToFront);
}
}
/// <summary>
/// Runs the tests after building the project under test.
/// </summary>
void Run(IProject project, string namespaceFilter, IClass fixture, IMember test)
{
BuildProjectBeforeTestRun build = new BuildProjectBeforeTestRun(project);
build.BuildComplete += delegate {
OnBuildComplete(build.LastBuildResults, project, namespaceFilter, fixture, test);
};
build.Run();
}
void ShowUnitTestsPad()
{
ShowPad(WorkbenchSingleton.Workbench.GetPad(typeof(UnitTestsPad)));
}
void UpdateUnitTestsPadToolbar()
{
if (UnitTestsPad.Instance != null) {
UnitTestsPad.Instance.UpdateToolbar();
}
}
/// <summary>
/// Sets the initial workbench state before starting
/// a test run.
/// </summary>
void BeforeRun()
{
TaskService.BuildMessageViewCategory.ClearText();
TaskService.InUpdate = true;
TaskService.ClearExceptCommentTasks();
TaskService.InUpdate = false;
TestRunnerCategory.ClearText();
ShowUnitTestsPad();
ShowOutputPad();
UpdateUnitTestsPadToolbar();
ResetAllTestResults();
OnBeforeRunTests();
}
/// <summary>
/// Brings output pad to the front.
/// </summary>
void ShowOutputPad()
{
ShowPad(WorkbenchSingleton.Workbench.GetPad(typeof(CompilerMessageView)));
}
Task CreateTask(TestResult result)
{
TaskType taskType = TaskType.Warning;
FileLineReference lineRef = null;
string message = String.Empty;
if (result.IsFailure) {
taskType = TaskType.Error;
lineRef = OutputTextLineParser.GetNUnitOutputFileLineReference(result.StackTrace, true);
message = GetTestResultMessage(result, "${res:NUnitPad.NUnitPadContent.TestTreeView.TestFailedMessage}");
} else if (result.IsIgnored) {
message = GetTestResultMessage(result, "${res:NUnitPad.NUnitPadContent.TestTreeView.TestNotExecutedMessage}");
}
if (lineRef == null) {
lineRef = FindTest(result.Name);
}
if (lineRef != null) {
return new Task(FileName.Create(lineRef.FileName),
message, lineRef.Column, lineRef.Line, taskType);
}
return new Task(null, message, 0, 0, taskType);
}
/// <summary>
/// Returns the test result message if there is on otherwise
/// uses the string resource to create a message.
/// </summary>
string GetTestResultMessage(TestResult result, string stringResource)
{
if (result.Message.Length > 0) {
return result.Message;
}
return StringParser.Parse(stringResource, new string[,] {{"TestCase", result.Name}});
}
/// <summary>
/// Returns the location of the specified test method in the
/// project being tested.
/// </summary>
FileLineReference FindTest(string methodName)
{
TestProject testProject = GetTestProject(currentProject);
if (testProject != null) {
TestMethod method = testProject.TestClasses.GetTestMethod(methodName);
if (method != null) {
MemberResolveResult resolveResult = new MemberResolveResult(null, null, method.Method);
FilePosition filePos = resolveResult.GetDefinitionPosition();
return new FileLineReference(filePos.FileName, filePos.Line, filePos.Column);
}
}
return null;
}
void ShowErrorList()
{
ShowPad(WorkbenchSingleton.Workbench.GetPad(typeof(ErrorListPad)));
}
/// <summary>
/// Runs the test for the project after a successful build.
/// </summary>
void OnBuildComplete(BuildResults results, IProject project, string namespaceFilter, IClass fixture, IMember test)
{
if (results.ErrorCount == 0 && IsRunningTest) {
UnitTestApplicationStartHelper helper = new UnitTestApplicationStartHelper();
UnitTestingOptions options = new UnitTestingOptions();
helper.NoThread = options.NoThread;
helper.NoLogo = options.NoLogo;
helper.NoDots = options.NoDots;
helper.Labels = options.Labels;
helper.ShadowCopy = !options.NoShadow;
if (options.CreateXmlOutputFile) {
helper.XmlOutputFile = Path.Combine(Path.GetDirectoryName(project.OutputAssemblyFullPath), project.AssemblyName + "-TestResult.xml");
}
helper.Initialize(project, namespaceFilter, fixture, test);
helper.Results = Path.GetTempFileName();
ResetTestResults(project);
testResultsMonitor.FileName = helper.Results;
testResultsMonitor.Start();
try {
RunTests(helper);
} catch {
StopMonitoring();
throw;
}
} else {
if (IsRunningTest) {
Stop();
}
if (TaskService.SomethingWentWrong && ErrorListPad.ShowAfterBuild) {
ShowErrorList();
}
}
}
/// <summary>
/// Clears the test results in the test tree view for the
/// project currently being tested.
/// </summary>
void ResetTestResults(IProject project)
{
TestProject testProject = GetTestProject(project);
if (testProject != null) {
testProject.ResetTestResults();
}
}
/// <summary>
/// Clears the test results in the test tree view for all the
/// displayed projects.
/// </summary>
void ResetAllTestResults()
{
if (UnitTestsPad.Instance != null) {
UnitTestsPad.Instance.TestTreeView.ResetTestResults();
}
}
/// <summary>
/// Gets the TestProject associated with the specified project
/// from the test tree view.
/// </summary>
TestProject GetTestProject(IProject project)
{
if (UnitTestsPad.Instance != null) {
return UnitTestsPad.Instance.TestTreeView.GetTestProject(project);
}
return null;
}
/// <summary>
/// Updates the test result in the test tree view.
/// </summary>
void UpdateTestResult(TestResult result)
{
TestProject testProject = GetTestProject(currentProject);
if (testProject != null) {
testProject.UpdateTestResult(result);
}
}
void StopMonitoring()
{
try {
File.Delete(testResultsMonitor.FileName);
} catch { }
testResultsMonitor.Dispose();
}
void TestFinished(object source, TestFinishedEventArgs e)
{
WorkbenchSingleton.SafeThreadAsyncCall(ShowResult, e.Result);
}
}
/// <summary>
/// Custom build command that makes sure errors and warnings
/// are not cleared from the Errors list before every build since
/// we may be running multiple tests after each other.
/// </summary>
public class BuildProjectBeforeTestRun : BuildProjectBeforeExecute
{
public BuildProjectBeforeTestRun(IProject targetProject)
: base(targetProject)
{
}
/// <summary>
/// Before a build do not clear the tasks, just save any
/// dirty files.
/// </summary>
public override void BeforeBuild()
{
SaveAllFiles.SaveAll();
}
}
public class RunTestInPadCommand : AbstractRunTestCommand
{
ProcessRunner runner;
public RunTestInPadCommand()
{
runner = new ProcessRunner();
runner.LogStandardOutputAndError = false;
runner.OutputLineReceived += OutputLineReceived;
runner.ProcessExited += ProcessExited;
}
protected override void RunTests(UnitTestApplicationStartHelper helper)
{
TestRunnerCategory.AppendLine(helper.GetCommandLine());
runner.Start(helper.UnitTestApplication, helper.GetArguments());
}
protected override void OnStop()
{
runner.Kill();
}
protected ProcessRunner GetProcessRunner()
{
return runner;
}
void OutputLineReceived(object source, LineReceivedEventArgs e)
{
TestRunnerCategory.AppendLine(e.Line);
}
void ProcessExited(object source, EventArgs e)
{
WorkbenchSingleton.SafeThreadAsyncCall(TestsFinished);
}
void TestFinished(object source, TestFinishedEventArgs e)
{
WorkbenchSingleton.SafeThreadAsyncCall(ShowResult, e.Result);
}
}
public class RunTestWithDebuggerCommand : AbstractRunTestCommand
{
public override void Run()
{
if (DebuggerService.IsDebuggerLoaded && DebuggerService.CurrentDebugger.IsDebugging) {
if (MessageService.AskQuestion("${res:XML.MainMenu.RunMenu.Compile.StopDebuggingQuestion}",
"${res:XML.MainMenu.RunMenu.Compile.StopDebuggingTitle}"))
{
DebuggerService.CurrentDebugger.Stop();
base.Run();
}
} else {
base.Run();
}
}
protected override void RunTests(UnitTestApplicationStartHelper helper)
{
bool running = false;
try {
TestRunnerCategory.AppendLine(helper.GetCommandLine());
ProcessStartInfo startInfo = new ProcessStartInfo(helper.UnitTestApplication);
startInfo.Arguments = helper.GetArguments();
startInfo.WorkingDirectory = UnitTestApplicationStartHelper.UnitTestApplicationDirectory;
DebuggerService.DebugStopped += DebuggerFinished;
DebuggerService.CurrentDebugger.Start(startInfo);
running = true;
} finally {
if (!running) {
DebuggerService.DebugStopped -= DebuggerFinished;
}
}
}
protected override void OnStop()
{
if (DebuggerService.CurrentDebugger.IsDebugging) {
DebuggerService.CurrentDebugger.Stop();
}
}
void DebuggerFinished(object sender, EventArgs e)
{
DebuggerService.DebugStopped -= DebuggerFinished;
WorkbenchSingleton.SafeThreadAsyncCall(TestsFinished);
}
}
public class RunAllTestsInPadCommand : RunTestInPadCommand
{
public override void Run()
{
// To make sure all tests are run we set the Owner to null.
Owner = null;
base.Run();
}
}
public class RunProjectTestsInPadCommand : RunTestInPadCommand, ITestTreeView
{
public override void Run()
{
Owner = this;
base.Run();
}
public IMember SelectedMethod {
get { return null; }
}
public IClass SelectedClass {
get { return null; }
}
public IProject SelectedProject {
get { return ProjectService.CurrentProject; }
}
public string SelectedNamespace {
get { return null; }
}
}
}

30
src/AddIns/Analysis/UnitTesting/Src/RunTestInPadCommand.cs

@ -0,0 +1,30 @@ @@ -0,0 +1,30 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.SharpDevelop.Util;
namespace ICSharpCode.UnitTesting
{
public class RunTestInPadCommand : AbstractRunTestCommand
{
public RunTestInPadCommand()
{
}
public RunTestInPadCommand(IRunTestCommandContext context)
: base(context)
{
}
protected override ITestRunner CreateTestRunner(IProject project)
{
return Context.RegisteredTestFrameworks.CreateTestRunner(project);
}
}
}

30
src/AddIns/Analysis/UnitTesting/Src/RunTestWithDebuggerCommand.cs

@ -0,0 +1,30 @@ @@ -0,0 +1,30 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Diagnostics;
using ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.UnitTesting
{
public class RunTestWithDebuggerCommand : AbstractRunTestCommand
{
public RunTestWithDebuggerCommand()
{
}
public RunTestWithDebuggerCommand(IRunTestCommandContext context)
: base(context)
{
}
protected override ITestRunner CreateTestRunner(IProject project)
{
return Context.RegisteredTestFrameworks.CreateTestDebugger(project);
}
}
}

96
src/AddIns/Analysis/UnitTesting/Src/SelectedTests.cs

@ -0,0 +1,96 @@ @@ -0,0 +1,96 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.UnitTesting
{
public class SelectedTests
{
string namespaceFilter;
IClass c;
IMember method;
List<IProject> projects = new List<IProject>();
public SelectedTests(IProject project, string namespaceFilter, IClass c, IMember method)
{
this.namespaceFilter = namespaceFilter;
this.c = c;
this.method = method;
if (project != null) {
projects.Add(project);
}
}
public SelectedTests(IProject project)
: this(project, null, null, null)
{
}
public SelectedTests(object owner, IProject[] selectedProjects)
{
IProject project = TestableCondition.GetProject(owner);
if (project != null) {
projects.Add(project);
} else {
projects.AddRange(selectedProjects);
}
method = TestableCondition.GetMember(owner);
c = GetClass(method, owner);
namespaceFilter = TestableCondition.GetNamespace(owner);
}
static IClass GetClass(IMember member, Object owner)
{
if (member != null) {
return member.DeclaringType;
}
return TestableCondition.GetClass(owner);
}
public bool HasProjects {
get { return projects.Count > 0; }
}
public void RemoveFirstProject()
{
if (HasProjects) {
projects.RemoveAt(0);
}
}
public IList<IProject> Projects {
get { return projects; }
}
public IProject Project {
get {
if (projects.Count > 0) {
return projects[0];
}
return null;
}
}
public string NamespaceFilter {
get { return namespaceFilter; }
}
public IClass Class {
get { return c; }
}
public IMember Method {
get { return method; }
}
}
}

12
src/AddIns/Analysis/UnitTesting/Src/TestAttributeName.cs

@ -6,10 +6,11 @@ @@ -6,10 +6,11 @@
// </file>
using System;
using ICSharpCode.SharpDevelop.Dom;
namespace ICSharpCode.UnitTesting
{
public class TestAttributeName
public class NUnitTestAttributeName
{
string name = String.Empty;
string qualifiedName = String.Empty;
@ -17,13 +18,13 @@ namespace ICSharpCode.UnitTesting @@ -17,13 +18,13 @@ namespace ICSharpCode.UnitTesting
StringComparer nameComparer;
/// <summary>
/// Creates a new instance of the Test Attribute class.
/// Creates a new instance of the NUnit Test Attribute class.
/// </summary>
/// <param name="name">The name of the attribute (e.g. Test) not
/// the full name of the attribute (e.g. TestAttribute).</param>
/// <param name="nameComparer">The string comparer to use
/// when comparing attribute names.</param>
public TestAttributeName(string name, StringComparer nameComparer)
public NUnitTestAttributeName(string name, StringComparer nameComparer)
{
this.name = name;
this.nameComparer = nameComparer;
@ -44,5 +45,10 @@ namespace ICSharpCode.UnitTesting @@ -44,5 +45,10 @@ namespace ICSharpCode.UnitTesting
}
return false;
}
public bool IsEqual(IAttribute attribute)
{
return IsEqual(attribute.AttributeType.FullyQualifiedName);
}
}
}

55
src/AddIns/Analysis/UnitTesting/Src/TestClass.cs

@ -13,24 +13,24 @@ using ICSharpCode.SharpDevelop.Dom; @@ -13,24 +13,24 @@ using ICSharpCode.SharpDevelop.Dom;
namespace ICSharpCode.UnitTesting
{
/// <summary>
/// Represents a class that can be tested. In order for a
/// class to be considered to be testable it needs to have the
/// [TestFixture] attribute.
/// Represents a class that can be tested.
/// </summary>
public class TestClass
{
IClass c;
TestMethodCollection testMethods;
TestResultType testResultType;
IRegisteredTestFrameworks testFrameworks;
/// <summary>
/// Raised when the test class result is changed.
/// </summary>
public event EventHandler ResultChanged;
public TestClass(IClass c)
public TestClass(IClass c, IRegisteredTestFrameworks testFrameworks)
{
this.c = c;
this.testFrameworks = testFrameworks;
}
/// <summary>
@ -40,42 +40,6 @@ namespace ICSharpCode.UnitTesting @@ -40,42 +40,6 @@ namespace ICSharpCode.UnitTesting
get { return c; }
}
/// <summary>
/// Determines whether the class is a test fixture. A class
/// is considered to be a test class if it contains certain
/// test attributes.
/// </summary>
public static bool IsTestClass(IClass c)
{
StringComparer nameComparer = GetNameComparer(c);
if (nameComparer != null) {
TestAttributeName testAttributeName = new TestAttributeName("TestFixture", nameComparer);
foreach (IAttribute attribute in c.Attributes) {
if (testAttributeName.IsEqual(attribute.AttributeType.FullyQualifiedName)) {
return true;
}
}
}
return false;
}
/// <summary>
/// Returns the name comparer for the specified class.
/// </summary>
public static StringComparer GetNameComparer(IClass c)
{
if (c != null) {
IProjectContent projectContent = c.ProjectContent;
if (projectContent != null) {
LanguageProperties language = projectContent.Language;
if (language != null) {
return language.NameComparer;
}
}
}
return null;
}
/// <summary>
/// Gets the test classes that exist in the specified namespace.
/// </summary>
@ -311,11 +275,11 @@ namespace ICSharpCode.UnitTesting @@ -311,11 +275,11 @@ namespace ICSharpCode.UnitTesting
/// <summary>
/// Gets the test methods for the specified class.
/// </summary>
static TestMethodCollection GetTestMethods(IClass c)
TestMethodCollection GetTestMethods(IClass c)
{
TestMethodCollection testMethods = new TestMethodCollection();
foreach (IMethod method in c.Methods) {
if (TestMethod.IsTestMethod(method)) {
if (IsTestMethod(method)) {
if (!testMethods.Contains(method.Name)) {
testMethods.Add(new TestMethod(method));
}
@ -326,7 +290,7 @@ namespace ICSharpCode.UnitTesting @@ -326,7 +290,7 @@ namespace ICSharpCode.UnitTesting
IClass declaringType = c;
while (c.BaseClass != null) {
foreach (IMethod method in c.BaseClass.Methods) {
if (TestMethod.IsTestMethod(method)) {
if (IsTestMethod(method)) {
BaseTestMethod baseTestMethod = new BaseTestMethod(declaringType, method);
TestMethod testMethod = new TestMethod(c.BaseClass.Name, baseTestMethod);
if (method.IsVirtual) {
@ -345,6 +309,11 @@ namespace ICSharpCode.UnitTesting @@ -345,6 +309,11 @@ namespace ICSharpCode.UnitTesting
return testMethods;
}
bool IsTestMethod(IMember method)
{
return testFrameworks.IsTestMethod(method);
}
/// <summary>
/// Updates the test class's test result after the test method's
/// test result has changed.

112
src/AddIns/Analysis/UnitTesting/Src/TestDebuggerBase.cs

@ -0,0 +1,112 @@ @@ -0,0 +1,112 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Diagnostics;
using ICSharpCode.SharpDevelop.Debugging;
namespace ICSharpCode.UnitTesting
{
public abstract class TestDebuggerBase : TestRunnerBase
{
IUnitTestDebuggerService debuggerService;
IUnitTestMessageService messageService;
IDebugger debugger;
ITestResultsMonitor testResultsMonitor;
public TestDebuggerBase()
: this(new UnitTestDebuggerService(),
new UnitTestMessageService(),
new TestResultsMonitor())
{
}
public TestDebuggerBase(IUnitTestDebuggerService debuggerService,
IUnitTestMessageService messageService,
ITestResultsMonitor testResultsMonitor)
{
this.debuggerService = debuggerService;
this.messageService = messageService;
this.testResultsMonitor = testResultsMonitor;
this.debugger = debuggerService.CurrentDebugger;
testResultsMonitor.TestFinished += OnTestFinished;
}
protected ITestResultsMonitor TestResultsMonitor {
get { return testResultsMonitor; }
}
public override void Start(SelectedTests selectedTests)
{
ProcessStartInfo startInfo = GetProcessStartInfo(selectedTests);
if (IsDebuggerRunning) {
if (CanStopDebugging()) {
debugger.Stop();
Start(startInfo);
}
} else {
Start(startInfo);
}
}
public bool IsDebuggerRunning {
get { return debuggerService.IsDebuggerLoaded && debugger.IsDebugging; }
}
bool CanStopDebugging()
{
string question = "${res:XML.MainMenu.RunMenu.Compile.StopDebuggingQuestion}";
string caption = "${res:XML.MainMenu.RunMenu.Compile.StopDebuggingTitle}";
return messageService.AskQuestion(question, caption);
}
void Start(ProcessStartInfo startInfo)
{
testResultsMonitor.Start();
StartDebugger(startInfo);
}
void StartDebugger(ProcessStartInfo startInfo)
{
LogCommandLine(startInfo);
bool running = false;
debugger.DebugStopped += DebugStopped;
try {
debugger.Start(startInfo);
running = true;
} finally {
if (!running) {
debugger.DebugStopped -= DebugStopped;
}
}
}
void DebugStopped(object source, EventArgs e)
{
debugger.DebugStopped -= DebugStopped;
OnAllTestsFinished(source, e);
}
public override void Stop()
{
if (debugger.IsDebugging) {
debugger.Stop();
}
testResultsMonitor.Stop();
testResultsMonitor.Read();
}
public override void Dispose()
{
Stop();
testResultsMonitor.Dispose();
}
}
}

6
src/AddIns/Analysis/UnitTesting/Src/TestFinishedEventArgs.cs

@ -9,6 +9,8 @@ using System; @@ -9,6 +9,8 @@ using System;
namespace ICSharpCode.UnitTesting
{
public delegate void TestFinishedEventHandler(object source, TestFinishedEventArgs e);
public class TestFinishedEventArgs : EventArgs
{
TestResult result;
@ -19,9 +21,7 @@ namespace ICSharpCode.UnitTesting @@ -19,9 +21,7 @@ namespace ICSharpCode.UnitTesting
}
public TestResult Result {
get {
return result;
}
get { return result; }
}
}
}

25
src/AddIns/Analysis/UnitTesting/Src/TestFramework.cs

@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.UnitTesting
{
public interface ITestFramework
{
bool IsTestMethod(IMember member);
bool IsTestClass(IClass c);
bool IsTestProject(IProject project);
ITestRunner CreateTestRunner();
ITestRunner CreateTestDebugger();
bool IsBuildNeededBeforeTestRun { get; }
}
}

81
src/AddIns/Analysis/UnitTesting/Src/TestFrameworkDescriptor.cs

@ -0,0 +1,81 @@ @@ -0,0 +1,81 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using System.IO;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.UnitTesting
{
public class TestFrameworkDescriptor
{
Properties properties;
ITestFrameworkFactory factory;
ITestFramework testFramework;
List<string> supportedProjectFileExtensions = new List<string>();
public TestFrameworkDescriptor(Properties properties, ITestFrameworkFactory factory)
{
this.properties = properties;
this.factory = factory;
GetSupportedProjectFileExtensions();
}
void GetSupportedProjectFileExtensions()
{
string extensions = properties["supportedProjects"];
foreach (string extension in extensions.Split(';')) {
supportedProjectFileExtensions.Add(extension.ToLowerInvariant().Trim());
}
}
public string Id {
get { return properties["id"]; }
}
public ITestFramework TestFramework {
get {
CreateTestFrameworkIfNotCreated();
return testFramework;
}
}
void CreateTestFrameworkIfNotCreated()
{
if (testFramework == null) {
testFramework = factory.Create(ClassName);
}
}
string ClassName {
get { return properties["class"]; }
}
public bool IsSupportedProject(IProject project)
{
string extension = GetProjectFileExtension(project);
return IsSupportedProjectFileExtension(extension);
}
string GetProjectFileExtension(IProject project)
{
if (project != null) {
return Path.GetExtension(project.FileName).ToLowerInvariant();
}
return null;
}
bool IsSupportedProjectFileExtension(string extension)
{
return supportedProjectFileExtensions.Contains(extension);
}
}
}

34
src/AddIns/Analysis/UnitTesting/Src/TestFrameworkDoozer.cs

@ -0,0 +1,34 @@ @@ -0,0 +1,34 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections;
using ICSharpCode.Core;
namespace ICSharpCode.UnitTesting
{
public class TestFrameworkDoozer : IDoozer
{
public TestFrameworkDoozer()
{
}
public bool HandleConditions {
get { return false; }
}
public object BuildItem(object caller, Codon codon, ArrayList subItems)
{
return BuildItem(codon, new TestFrameworkFactory(codon.AddIn));
}
public TestFrameworkDescriptor BuildItem(Codon codon, ITestFrameworkFactory factory)
{
return new TestFrameworkDescriptor(codon.Properties, factory);
}
}
}

27
src/AddIns/Analysis/UnitTesting/Src/TestFrameworkFactory.cs

@ -0,0 +1,27 @@ @@ -0,0 +1,27 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.Core;
namespace ICSharpCode.UnitTesting
{
public class TestFrameworkFactory : ITestFrameworkFactory
{
AddIn addin;
public TestFrameworkFactory(AddIn addin)
{
this.addin = addin;
}
public ITestFramework Create(string className)
{
return addin.CreateObject(className) as ITestFramework;
}
}
}

38
src/AddIns/Analysis/UnitTesting/Src/TestMethod.cs

@ -11,8 +11,7 @@ using ICSharpCode.SharpDevelop.Dom; @@ -11,8 +11,7 @@ using ICSharpCode.SharpDevelop.Dom;
namespace ICSharpCode.UnitTesting
{
/// <summary>
/// Represents a method that has the [Test] attribute and
/// can be tested.
/// Represents a method that can be tested.
/// </summary>
public class TestMethod
{
@ -56,9 +55,7 @@ namespace ICSharpCode.UnitTesting @@ -56,9 +55,7 @@ namespace ICSharpCode.UnitTesting
/// Gets the underlying IMethod for this TestMethod.
/// </summary>
public IMethod Method {
get {
return method;
}
get { return method; }
}
/// <summary>
@ -74,9 +71,7 @@ namespace ICSharpCode.UnitTesting @@ -74,9 +71,7 @@ namespace ICSharpCode.UnitTesting
/// Gets the test result for this method.
/// </summary>
public TestResultType Result {
get {
return testResultType;
}
get { return testResultType; }
set {
TestResultType previousTestResultType = testResultType;
testResultType = value;
@ -98,33 +93,6 @@ namespace ICSharpCode.UnitTesting @@ -98,33 +93,6 @@ namespace ICSharpCode.UnitTesting
}
}
/// <summary>
/// Determines whether the method is a test method. A method
/// is considered to be a test method if it contains certain
/// test attributes. If the method has parameters it cannot
/// be a test method.
/// </summary>
public static bool IsTestMethod(IMember member)
{
if (member == null) {
return false;
}
StringComparer nameComparer = TestClass.GetNameComparer(member.DeclaringType);
if (nameComparer != null) {
TestAttributeName testAttribute = new TestAttributeName("Test", nameComparer);
foreach (IAttribute attribute in member.Attributes) {
if (testAttribute.IsEqual(attribute.AttributeType.FullyQualifiedName)) {
IMethod method = (IMethod)member;
if (method.Parameters.Count == 0) {
return true;
}
}
}
}
return false;
}
/// <summary>
/// Returns the method name from a fully qualified name
/// of the form:

82
src/AddIns/Analysis/UnitTesting/Src/TestProcessRunnerBase.cs

@ -0,0 +1,82 @@ @@ -0,0 +1,82 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Diagnostics;
using ICSharpCode.SharpDevelop.Util;
namespace ICSharpCode.UnitTesting
{
public class TestProcessRunnerBase : TestRunnerBase
{
IUnitTestProcessRunner processRunner;
ITestResultsMonitor testResultsMonitor;
public TestProcessRunnerBase()
: this(new UnitTestProcessRunner(),
new TestResultsMonitor())
{
}
public TestProcessRunnerBase(IUnitTestProcessRunner processRunner,
ITestResultsMonitor testResultsMonitor)
{
this.processRunner = processRunner;
this.testResultsMonitor = testResultsMonitor;
processRunner.LogStandardOutputAndError = false;
processRunner.OutputLineReceived += OutputLineReceived;
processRunner.ErrorLineReceived += OutputLineReceived;
processRunner.ProcessExited += OnAllTestsFinished;
testResultsMonitor.TestFinished += OnTestFinished;
}
protected ITestResultsMonitor TestResultsMonitor {
get { return testResultsMonitor; }
}
// public override event EventHandler AllTestsFinished {
// add { processRunner.ProcessExited += value; }
// remove { processRunner.ProcessExited -= value; }
// }
void OutputLineReceived(object source, LineReceivedEventArgs e)
{
OnMessageReceived(e.Line);
}
public override void Start(SelectedTests selectedTests)
{
ProcessStartInfo startInfo = GetProcessStartInfo(selectedTests);
Start(startInfo);
}
void Start(ProcessStartInfo processStartInfo)
{
LogCommandLine(processStartInfo);
testResultsMonitor.Start();
processRunner.WorkingDirectory = processStartInfo.WorkingDirectory;
processRunner.Start(processStartInfo.FileName, processStartInfo.Arguments);
}
public override void Stop()
{
processRunner.Kill();
testResultsMonitor.Stop();
testResultsMonitor.Read();
}
public override void Dispose()
{
testResultsMonitor.Dispose();
testResultsMonitor.TestFinished -= OnTestFinished;
processRunner.ErrorLineReceived -= OutputLineReceived;
processRunner.OutputLineReceived -= OutputLineReceived;
}
}
}

68
src/AddIns/Analysis/UnitTesting/Src/TestProject.cs

@ -23,53 +23,19 @@ namespace ICSharpCode.UnitTesting @@ -23,53 +23,19 @@ namespace ICSharpCode.UnitTesting
IProjectContent projectContent;
TestClassCollection testClasses;
List<string> rootNamespaces;
IRegisteredTestFrameworks testFrameworks;
public TestProject(IProject project, IProjectContent projectContent)
public TestProject(IProject project, IProjectContent projectContent, IRegisteredTestFrameworks testFrameworks)
{
this.project = project;
this.projectContent = projectContent;
this.testFrameworks = testFrameworks;
}
/// <summary>
/// Returns the underlying project.
/// </summary>
public IProject Project {
get { return project; }
}
/// <summary>
/// Determines whether the project is a test project. A project
/// is considered to be a test project if it contains a reference
/// to the NUnit.Framework assembly.
/// </summary>
public static bool IsTestProject(IProject project)
{
if (project != null) {
foreach (ProjectItem projectItem in project.Items) {
ReferenceProjectItem referenceProjectItem = projectItem as ReferenceProjectItem;
if (referenceProjectItem != null) {
if (IsTestFrameworkReference(referenceProjectItem)) {
return true;
}
}
}
}
return false;
}
/// <summary>
/// Determines whether the specified reference is a reference to
/// a test framework. Currently only references to the
/// NUnit.Framework return true.
/// </summary>
public static bool IsTestFrameworkReference(ReferenceProjectItem referenceProjectItem)
{
if (referenceProjectItem != null) {
return string.Equals(referenceProjectItem.ShortName, "NUnit.Framework", StringComparison.OrdinalIgnoreCase);
}
return false;
}
/// <summary>
/// Gets the test classes in this project.
/// </summary>
@ -209,12 +175,17 @@ namespace ICSharpCode.UnitTesting @@ -209,12 +175,17 @@ namespace ICSharpCode.UnitTesting
/// </summary>
void AddNewTestClass(IClass c)
{
if (TestClass.IsTestClass(c)) {
TestClass testClass = new TestClass(c);
if (IsTestClass(c)) {
TestClass testClass = CreateTestClass(c);
TestClasses.Add(testClass);
}
}
TestClass CreateTestClass(IClass c)
{
return new TestClass(c, testFrameworks);
}
/// <summary>
/// Updates the test class methods based on the newly parsed class
/// information.
@ -222,7 +193,7 @@ namespace ICSharpCode.UnitTesting @@ -222,7 +193,7 @@ namespace ICSharpCode.UnitTesting
void UpdateTestClass(IClass c)
{
if (TestClasses.Contains(c.DotNetName)) {
if (TestClass.IsTestClass(c)) {
if (IsTestClass(c)) {
TestClass testClass = TestClasses[c.DotNetName];
testClass.UpdateClass(c);
} else {
@ -243,27 +214,32 @@ namespace ICSharpCode.UnitTesting @@ -243,27 +214,32 @@ namespace ICSharpCode.UnitTesting
{
testClasses = new TestClassCollection();
foreach (IClass c in projectContent.Classes) {
if (TestClass.IsTestClass(c)) {
if (IsTestClass(c)) {
if (!testClasses.Contains(c.FullyQualifiedName)) {
testClasses.Add(new TestClass(c));
testClasses.Add(CreateTestClass(c));
}
}
foreach (IClass innerClass in c.InnerClasses) {
if (TestClass.IsTestClass(innerClass)) {
if (IsTestClass(innerClass)) {
if (!testClasses.Contains(innerClass.DotNetName)) {
testClasses.Add(new TestClass(innerClass));
testClasses.Add(CreateTestClass(innerClass));
}
}
}
}
}
bool IsTestClass(IClass c)
{
return testFrameworks.IsTestClass(c);
}
void GetRootNamespaces()
{
rootNamespaces = new List<string>();
foreach (TestClass c in TestClasses) {
string rootNamespace = c.RootNamespace;
if (rootNamespace.Length > 0 && !rootNamespaces.Contains(rootNamespace)) {
if ((rootNamespace.Length > 0) && !rootNamespaces.Contains(rootNamespace)) {
rootNamespaces.Add(rootNamespace);
}
}
@ -277,7 +253,7 @@ namespace ICSharpCode.UnitTesting @@ -277,7 +253,7 @@ namespace ICSharpCode.UnitTesting
IClass GetExistingTestClassInProject(IClass c)
{
foreach (IClass existingClass in projectContent.Classes) {
if (TestClass.IsTestClass(existingClass)) {
if (IsTestClass(existingClass)) {
if (existingClass.DotNetName == c.DotNetName) {
return existingClass;
}

58
src/AddIns/Analysis/UnitTesting/Src/TestResult.cs

@ -6,6 +6,7 @@ @@ -6,6 +6,7 @@
// </file>
using System;
using ICSharpCode.SharpDevelop.Dom;
namespace ICSharpCode.UnitTesting
{
@ -40,6 +41,7 @@ namespace ICSharpCode.UnitTesting @@ -40,6 +41,7 @@ namespace ICSharpCode.UnitTesting
string message = String.Empty;
string stackTrace = String.Empty;
TestResultType resultType = TestResultType.None;
FilePosition stackTraceFilePosition = FilePosition.Empty;
public TestResult(string name)
{
@ -47,60 +49,48 @@ namespace ICSharpCode.UnitTesting @@ -47,60 +49,48 @@ namespace ICSharpCode.UnitTesting
}
public string Name {
get {
return name;
}
get { return name; }
}
public bool IsSuccess {
get {
return resultType == TestResultType.Success;
}
set {
resultType = TestResultType.Success;
}
get { return resultType == TestResultType.Success; }
}
public bool IsFailure {
get {
return resultType == TestResultType.Failure;
}
set {
resultType = TestResultType.Failure;
}
get { return resultType == TestResultType.Failure; }
}
public bool IsIgnored {
get {
return resultType == TestResultType.Ignored;
}
set {
resultType = TestResultType.Ignored;
}
get { return resultType == TestResultType.Ignored; }
}
public TestResultType ResultType {
get {
return resultType;
}
get { return resultType; }
set { resultType = value; }
}
public string Message {
get {
return message;
}
set {
message = value;
}
get { return message; }
set { message = value; }
}
public string StackTrace {
get {
return stackTrace;
}
get { return stackTrace; }
set {
stackTrace = value;
if (stackTrace != value) {
stackTrace = value;
OnStackTraceChanged();
}
}
}
protected virtual void OnStackTraceChanged()
{
}
public FilePosition StackTraceFilePosition {
get { return stackTraceFilePosition; }
set { stackTraceFilePosition = value; }
}
}
}

102
src/AddIns/Analysis/UnitTesting/Src/TestResultTask.cs

@ -0,0 +1,102 @@ @@ -0,0 +1,102 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.IO;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.UnitTesting
{
public class TestResultTask
{
TestResultTask()
{
}
public static Task Create(TestResult result, TestProject project)
{
TaskType taskType = TaskType.Warning;
FileLineReference lineRef = null;
string message = String.Empty;
if (result.IsFailure) {
taskType = TaskType.Error;
if (!result.StackTraceFilePosition.IsEmpty) {
lineRef = new FileLineReference(result.StackTraceFilePosition.FileName, result.StackTraceFilePosition.Line - 1, result.StackTraceFilePosition.Column - 1);
}
message = GetTestFailedMessage(result);
} else if (result.IsIgnored) {
message = GetTestIgnoredMessage(result);
}
if (lineRef == null) {
lineRef = FindTest(result.Name, project);
}
FileName fileName = null;
if (lineRef != null) {
fileName = new FileName(Path.GetFullPath(lineRef.FileName));
int line = lineRef.Line + 1;
return new Task(fileName, message, lineRef.Column, line, taskType);
}
return new Task(fileName, message, 0, 0, taskType);
}
static string GetTestFailedMessage(TestResult result)
{
string resource = "${res:NUnitPad.NUnitPadContent.TestTreeView.TestFailedMessage}";
return GetTestResultMessage(result, resource);
}
static string GetTestIgnoredMessage(TestResult result)
{
string resource = "${res:NUnitPad.NUnitPadContent.TestTreeView.TestNotExecutedMessage}";
return GetTestResultMessage(result, resource);
}
/// <summary>
/// Returns the test result message if there is on otherwise
/// uses the string resource to create a message.
/// </summary>
static string GetTestResultMessage(TestResult result, string stringResource)
{
if (result.Message.Length > 0) {
return result.Message;
}
return GetTestResultMessageFromResource(result, stringResource);
}
static string GetTestResultMessageFromResource(TestResult result, string stringResource)
{
string [,] customTags = new string[,] {{"TestCase", result.Name}};
return StringParser.Parse(stringResource, customTags);
}
/// <summary>
/// Returns the location of the specified test method in the
/// project being tested.
/// </summary>
static FileLineReference FindTest(string methodName, TestProject testProject)
{
if (testProject != null) {
TestMethod testMethod = testProject.TestClasses.GetTestMethod(methodName);
if (testMethod != null) {
return FindTest(testMethod);
}
}
return null;
}
static FileLineReference FindTest(TestMethod testMethod)
{
MemberResolveResult resolveResult = new MemberResolveResult(null, null, testMethod.Method);
FilePosition filePos = resolveResult.GetDefinitionPosition();
return new FileLineReference(filePos.FileName, filePos.Line - 1, filePos.Column - 1);
}
}
}

21
src/AddIns/Analysis/UnitTesting/Src/TestResultsMonitor.cs

@ -15,7 +15,7 @@ namespace ICSharpCode.UnitTesting @@ -15,7 +15,7 @@ namespace ICSharpCode.UnitTesting
/// Watches for new test results as they occur. Test results
/// are written to a file and read in by this class.
/// </summary>
public class TestResultsMonitor : IDisposable
public class TestResultsMonitor : ITestResultsMonitor
{
FileInfo fileInfo;
TestResultsReader testResultsReader;
@ -25,8 +25,6 @@ namespace ICSharpCode.UnitTesting @@ -25,8 +25,6 @@ namespace ICSharpCode.UnitTesting
const int BytesBufferLength = 1024;
byte[] bytes = new byte[BytesBufferLength];
public delegate void TestFinishedEventHandler(object source, TestFinishedEventArgs e);
/// <summary>
/// Raised when a single test has been completed.
/// </summary>
@ -39,6 +37,7 @@ namespace ICSharpCode.UnitTesting @@ -39,6 +37,7 @@ namespace ICSharpCode.UnitTesting
}
public TestResultsMonitor()
: this(Path.GetTempFileName())
{
ResetFilePosition();
}
@ -47,12 +46,8 @@ namespace ICSharpCode.UnitTesting @@ -47,12 +46,8 @@ namespace ICSharpCode.UnitTesting
/// Gets or sets the test results filename.
/// </summary>
public string FileName {
get {
return fileInfo.FullName;
}
set {
fileInfo = new FileInfo(value);
}
get { return fileInfo.FullName; }
set { fileInfo = new FileInfo(value); }
}
/// <summary>
@ -108,6 +103,10 @@ namespace ICSharpCode.UnitTesting @@ -108,6 +103,10 @@ namespace ICSharpCode.UnitTesting
public void Dispose()
{
Stop();
try {
File.Delete(FileName);
} catch { }
}
void FileCreated(object source, FileSystemEventArgs e)
@ -124,7 +123,7 @@ namespace ICSharpCode.UnitTesting @@ -124,7 +123,7 @@ namespace ICSharpCode.UnitTesting
void OnTestResultsReceived(TestResult[] results)
{
if (results.Length > 0 && TestFinished != null) {
if ((results.Length > 0) && (TestFinished != null)) {
foreach (TestResult result in results) {
TestFinished(this, new TestFinishedEventArgs(result));
}
@ -150,7 +149,7 @@ namespace ICSharpCode.UnitTesting @@ -150,7 +149,7 @@ namespace ICSharpCode.UnitTesting
filePosition += bytesRead;
text.Append(UTF8Encoding.UTF8.GetString(bytes, 0, bytesRead));
}
} while (bytesRead > 0 && filePosition < fs.Length);
} while ((bytesRead > 0) && (filePosition < fs.Length));
}
}
} catch (FileNotFoundException) {

8
src/AddIns/Analysis/UnitTesting/Src/TestResultsReader.cs

@ -147,12 +147,12 @@ namespace ICSharpCode.UnitTesting @@ -147,12 +147,12 @@ namespace ICSharpCode.UnitTesting
void UpdateTestSuccess()
{
string value = valueBuilder.ToString();
if (value =="Success") {
result.IsSuccess = true;
if (value == "Success") {
result.ResultType = TestResultType.Success;
} else if (value == "Failure") {
result.IsFailure = true;
result.ResultType = TestResultType.Failure;
} else {
result.IsIgnored = true;
result.ResultType = TestResultType.Ignored;
}
}
}

72
src/AddIns/Analysis/UnitTesting/Src/TestRunnerBase.cs

@ -0,0 +1,72 @@ @@ -0,0 +1,72 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Diagnostics;
namespace ICSharpCode.UnitTesting
{
public abstract class TestRunnerBase : ITestRunner
{
public TestRunnerBase()
{
}
protected virtual ProcessStartInfo GetProcessStartInfo(SelectedTests selectedTests)
{
return new ProcessStartInfo();
}
protected void LogCommandLine(ProcessStartInfo startInfo)
{
string commandLine = GetCommandLine(startInfo);
OnMessageReceived(commandLine);
}
protected string GetCommandLine(ProcessStartInfo startInfo)
{
return String.Format("\"{0}\" {1}", startInfo.FileName, startInfo.Arguments);
}
public event EventHandler AllTestsFinished;
protected void OnAllTestsFinished(object source, EventArgs e)
{
if (AllTestsFinished != null) {
AllTestsFinished(source, e);
}
}
public event TestFinishedEventHandler TestFinished;
protected void OnTestFinished(object source, TestFinishedEventArgs e)
{
if (TestFinished != null) {
TestResult testResult = CreateTestResultForTestFramework(e.Result);
TestFinished(source, new TestFinishedEventArgs(testResult));
}
}
protected virtual TestResult CreateTestResultForTestFramework(TestResult testResult)
{
return testResult;
}
public event MessageReceivedEventHandler MessageReceived;
protected virtual void OnMessageReceived(string message)
{
if (MessageReceived != null) {
MessageReceived(this, new MessageReceivedEventArgs(message));
}
}
public abstract void Dispose();
public abstract void Stop();
public abstract void Start(SelectedTests selectedTests);
}
}

51
src/AddIns/Analysis/UnitTesting/Src/TestService.cs

@ -0,0 +1,51 @@ @@ -0,0 +1,51 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.UnitTesting
{
public static class TestService
{
static IRegisteredTestFrameworks testFrameworks;
static MessageViewCategory unitTestMessageView;
public static IRegisteredTestFrameworks RegisteredTestFrameworks {
get {
CreateRegisteredTestFrameworks();
return testFrameworks;
}
set { testFrameworks = value; }
}
static void CreateRegisteredTestFrameworks()
{
if (testFrameworks == null) {
UnitTestAddInTree addInTree = new UnitTestAddInTree();
testFrameworks = new RegisteredTestFrameworks(addInTree);
}
}
public static MessageViewCategory UnitTestMessageView {
get {
if (unitTestMessageView == null) {
CreateUnitTestCategory();
}
return unitTestMessageView;
}
}
static void CreateUnitTestCategory()
{
MessageViewCategory.Create(ref unitTestMessageView,
"UnitTesting",
"${res:ICSharpCode.NUnitPad.NUnitPadContent.PadName}");
}
}
}

142
src/AddIns/Analysis/UnitTesting/Src/TestTreeView.cs

@ -37,9 +37,11 @@ namespace ICSharpCode.UnitTesting @@ -37,9 +37,11 @@ namespace ICSharpCode.UnitTesting
/// only one test project then no such node will be added.
/// </summary>
AllTestsTreeNode allTestsNode;
IRegisteredTestFrameworks testFrameworks;
public TestTreeView()
public TestTreeView(IRegisteredTestFrameworks testFrameworks)
{
this.testFrameworks = testFrameworks;
ImageList = TestTreeViewImageList.ImageList;
CanClearSelection = false;
}
@ -50,7 +52,7 @@ namespace ICSharpCode.UnitTesting @@ -50,7 +52,7 @@ namespace ICSharpCode.UnitTesting
public Enum InternalState {
get {
TestTreeNode selectedNode = SelectedNode as TestTreeNode;
if (selectedNode is TestClassTreeNode || selectedNode is TestMethodTreeNode) {
if ((selectedNode is TestClassTreeNode) || (selectedNode is TestMethodTreeNode)) {
return TestTreeViewState.SourceCodeItemSelected;
}
return TestTreeViewState.None;
@ -81,7 +83,7 @@ namespace ICSharpCode.UnitTesting @@ -81,7 +83,7 @@ namespace ICSharpCode.UnitTesting
/// <summary>
/// Adds the project to the test tree view if the project
/// has a reference to a supported test framework.
/// is a test project.
/// </summary>
/// <remarks>
/// If the project is already in the tree then it will
@ -90,24 +92,58 @@ namespace ICSharpCode.UnitTesting @@ -90,24 +92,58 @@ namespace ICSharpCode.UnitTesting
/// </remarks>
public void AddProject(IProject project)
{
if (TestProject.IsTestProject(project)) {
if (IsTestProject(project)) {
if (GetProjectTreeNode(project) == null) {
// Add a new tree node.
IProjectContent projectContent = GetProjectContent(project);
if (projectContent != null) {
TestProject testProject = new TestProject(project, projectContent);
TestProjectTreeNode node = new TestProjectTreeNode(testProject);
if (Nodes.Count == 0) {
node.AddTo(this);
} else {
AllTestsTreeNode allTestsNode = GetAllTestsNode();
allTestsNode.AddProjectNode(node);
}
// Sort the nodes.
SortNodes(Nodes, true);
}
AddProjectTreeNode(project);
}
}
}
bool IsTestProject(IProject project)
{
return testFrameworks.IsTestProject(project);
}
void AddProjectTreeNode(IProject project)
{
TestProjectTreeNode node = CreateProjectTreeNode(project);
if (node != null) {
AddProjectTreeNodeToTree(node);
SortNodes(Nodes, true);
}
}
TestProjectTreeNode CreateProjectTreeNode(IProject project)
{
IProjectContent projectContent = GetProjectContent(project);
if (projectContent != null) {
TestProject testProject = new TestProject(project, projectContent, testFrameworks);
return new TestProjectTreeNode(testProject);
}
return null;
}
void AddProjectTreeNodeToTree(TestProjectTreeNode node)
{
if (Nodes.Count == 0) {
node.AddTo(this);
} else {
AllTestsTreeNode allTestsNode = GetAllTestsNode();
allTestsNode.AddProjectNode(node);
}
}
public void RemoveSolutionFolder(ISolutionFolder solutionFolder)
{
IProject project = solutionFolder as IProject;
if (project != null) {
RemoveProject(project);
}
ISolutionFolderContainer solutionFolderContainer = solutionFolder as ISolutionFolderContainer;
if (solutionFolderContainer != null) {
foreach (ISolutionFolder subSolutionFolder in solutionFolderContainer.Folders) {
RemoveSolutionFolder(subSolutionFolder);
}
}
}
@ -119,11 +155,15 @@ namespace ICSharpCode.UnitTesting @@ -119,11 +155,15 @@ namespace ICSharpCode.UnitTesting
{
TestProjectTreeNode projectNode = GetProjectTreeNode(project);
RemoveProjectNode(projectNode);
RemoveAllTestsNodeIfOnlyOneProjectLeft();
}
// Remove the All Tests node if it exists and there
// is only one project tree node left.
if (allTestsNode != null && GetProjectNodes().Count == 1) {
RemoveAllTestsNode();
void RemoveAllTestsNodeIfOnlyOneProjectLeft()
{
if (allTestsNode != null) {
if (GetProjectNodes().Count == 1) {
RemoveAllTestsNode();
}
}
}
@ -133,8 +173,6 @@ namespace ICSharpCode.UnitTesting @@ -133,8 +173,6 @@ namespace ICSharpCode.UnitTesting
public IProject[] GetProjects()
{
List<IProject> projects = new List<IProject>();
// Get the project information.
foreach (TestProjectTreeNode projectNode in GetProjectNodes()) {
projects.Add(projectNode.Project);
}
@ -172,12 +210,8 @@ namespace ICSharpCode.UnitTesting @@ -172,12 +210,8 @@ namespace ICSharpCode.UnitTesting
public IClass SelectedClass {
get {
TestClassTreeNode classNode = SelectedNode as TestClassTreeNode;
if (classNode == null) {
TestMethodTreeNode methodNode = SelectedNode as TestMethodTreeNode;
if (methodNode != null) {
classNode = methodNode.Parent as TestClassTreeNode;
}
classNode = GetClassNodeFromSelectedMethodNode();
}
if (classNode != null) {
@ -187,6 +221,15 @@ namespace ICSharpCode.UnitTesting @@ -187,6 +221,15 @@ namespace ICSharpCode.UnitTesting
}
}
TestClassTreeNode GetClassNodeFromSelectedMethodNode()
{
TestMethodTreeNode methodNode = SelectedNode as TestMethodTreeNode;
if (methodNode != null) {
return methodNode.Parent as TestClassTreeNode;
}
return null;
}
/// <summary>
/// Gets the project associated with the currently selected
/// tree node.
@ -261,25 +304,6 @@ namespace ICSharpCode.UnitTesting @@ -261,25 +304,6 @@ namespace ICSharpCode.UnitTesting
return ParserService.GetProjectContent(project);
}
/// <summary>
/// Adds or removes a project from the test tree view based on
/// whether a reference to a testing framework has been added or
/// removed.
/// </summary>
public void ProjectReferencesChanged(IProject project)
{
TestProjectTreeNode projectNode = GetProjectTreeNode(project);
if (TestProject.IsTestProject(project)) {
if (projectNode == null) {
TestProject testProject = new TestProject(project, GetProjectContent(project));
projectNode = new TestProjectTreeNode(testProject);
projectNode.AddTo(this);
}
} else {
RemoveProjectNode(projectNode);
}
}
/// <summary>
/// A tree node has been selected. Here we make sure the tree node
/// uses the context menu strip that the tree view is using. This
@ -375,7 +399,6 @@ namespace ICSharpCode.UnitTesting @@ -375,7 +399,6 @@ namespace ICSharpCode.UnitTesting
/// </summary>
void RemoveAllTestsNode()
{
// Remove the all tests node.
allTestsNode.Remove();
// Copy project nodes to the root.
@ -383,7 +406,6 @@ namespace ICSharpCode.UnitTesting @@ -383,7 +406,6 @@ namespace ICSharpCode.UnitTesting
Nodes.Add(node);
}
// Dispose the all tests node.
AllTestsNodeDisposed(null, null);
}
@ -397,5 +419,21 @@ namespace ICSharpCode.UnitTesting @@ -397,5 +419,21 @@ namespace ICSharpCode.UnitTesting
allTestsNode.Disposed -= AllTestsNodeDisposed;
allTestsNode = null;
}
/// <summary>
/// Adds the test project to the test tree view if it is now recognised as a
/// test project and is not already in the test tree.
/// </summary>
public void ProjectItemAdded(ProjectItem projectItem)
{
AddProject(projectItem.Project);
}
public void ProjectItemRemoved(ProjectItem projectItem)
{
if (!testFrameworks.IsTestProject(projectItem.Project)) {
RemoveProject(projectItem.Project);
}
}
}
}

42
src/AddIns/Analysis/UnitTesting/Src/TestableCondition.cs

@ -19,6 +19,18 @@ namespace ICSharpCode.UnitTesting @@ -19,6 +19,18 @@ namespace ICSharpCode.UnitTesting
/// </summary>
public class TestableCondition : IConditionEvaluator
{
IRegisteredTestFrameworks testFrameworks;
public TestableCondition(IRegisteredTestFrameworks testFrameworks)
{
this.testFrameworks = testFrameworks;
}
public TestableCondition()
: this(TestService.RegisteredTestFrameworks)
{
}
public static IMember GetMember(object caller)
{
ITestTreeView testTreeView = caller as ITestTreeView;
@ -61,9 +73,22 @@ namespace ICSharpCode.UnitTesting @@ -61,9 +73,22 @@ namespace ICSharpCode.UnitTesting
if (testTreeView != null) {
return testTreeView.SelectedProject;
}
IClass c = GetClassFromMemberOrCaller(caller);
return GetProject(c);
}
static IClass GetClassFromMemberOrCaller(object caller)
{
IMember m = GetMember(caller);
IClass c = (m != null) ? m.DeclaringType : GetClass(caller);
if (c != null && c.ProjectContent != null) {
if (m != null) {
return m.DeclaringType;
}
return GetClass(caller);
}
static IProject GetProject(IClass c)
{
if (c != null) {
return (IProject)c.ProjectContent.Project;
}
return null;
@ -85,13 +110,18 @@ namespace ICSharpCode.UnitTesting @@ -85,13 +110,18 @@ namespace ICSharpCode.UnitTesting
{
IMember m = GetMember(caller);
if (m != null) {
return TestMethod.IsTestMethod(m);
return testFrameworks.IsTestMethod(m);
}
IClass c = GetClass(caller);
if (c == null || c.ProjectContent == null || c.ProjectContent.Project == null) {
return false;
if (ClassHasProject(c)) {
return testFrameworks.IsTestClass(c);
}
return TestClass.IsTestClass(c);
return false;
}
static bool ClassHasProject(IClass c)
{
return (c != null) && (c.ProjectContent.Project != null);
}
}
}

21
src/AddIns/Analysis/UnitTesting/Src/UnitTestAddInTree.cs

@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using ICSharpCode.Core;
namespace ICSharpCode.UnitTesting
{
public class UnitTestAddInTree : IAddInTree
{
public List<T> BuildItems<T>(string path, object caller)
{
return AddInTree.BuildItems<T>(path, caller);
}
}
}

19
src/AddIns/Analysis/UnitTesting/Src/UnitTestBuildOptions.cs

@ -0,0 +1,19 @@ @@ -0,0 +1,19 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.UnitTesting
{
public class UnitTestBuildOptions : IBuildOptions
{
public bool ShowErrorListAfterBuild {
get { return BuildOptions.ShowErrorListAfterBuild; }
}
}
}

20
src/AddIns/Analysis/UnitTesting/Src/UnitTestBuildProjectFactory.cs

@ -0,0 +1,20 @@ @@ -0,0 +1,20 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.UnitTesting
{
public class UnitTestBuildProjectFactory : IBuildProjectFactory
{
public BuildProjectBeforeTestRun CreateBuildProjectBeforeTestRun(IProject project)
{
return new BuildProjectBeforeTestRun(project);
}
}
}

48
src/AddIns/Analysis/UnitTesting/Src/UnitTestCommands.cs

@ -27,28 +27,42 @@ namespace ICSharpCode.UnitTesting @@ -27,28 +27,42 @@ namespace ICSharpCode.UnitTesting
public class AddNUnitReferenceCommand : AbstractMenuCommand
{
public override void Run()
public void Run(IProject project)
{
if (ProjectService.CurrentProject != null) {
ProjectService.AddProjectItem(ProjectService.CurrentProject, new ReferenceProjectItem(ProjectService.CurrentProject, "nunit.framework"));
ProjectService.CurrentProject.Save();
if (project != null) {
ReferenceProjectItem nunitRef = new ReferenceProjectItem(project, "nunit.framework");
ProjectService.AddProjectItem(project, nunitRef);
project.Save();
}
}
public override void Run()
{
Run(ProjectService.CurrentProject);
}
}
public class GotoDefinitionCommand : AbstractMenuCommand
{
IUnitTestFileService fileService;
public GotoDefinitionCommand()
: this(new UnitTestFileService())
{
}
public GotoDefinitionCommand(IUnitTestFileService fileService)
{
this.fileService = fileService;
}
public override void Run()
{
ITestTreeView treeView = Owner as ITestTreeView;
if (treeView != null) {
IMember member = treeView.SelectedMethod;
IMember member = GetMember(treeView);
IClass c = treeView.SelectedClass;
if (member != null) {
BaseTestMethod baseTestMethod = member as BaseTestMethod;
if (baseTestMethod != null) {
member = baseTestMethod.Method;
}
GotoMember(member);
} else if (c != null) {
GotoClass(c);
@ -56,6 +70,18 @@ namespace ICSharpCode.UnitTesting @@ -56,6 +70,18 @@ namespace ICSharpCode.UnitTesting
}
}
IMember GetMember(ITestTreeView treeView)
{
IMember member = treeView.SelectedMethod;
if (member != null) {
BaseTestMethod baseTestMethod = member as BaseTestMethod;
if (baseTestMethod != null) {
return baseTestMethod.Method;
}
}
return member;
}
void GotoMember(IMember member)
{
MemberResolveResult resolveResult = new MemberResolveResult(null, null, member);
@ -71,9 +97,9 @@ namespace ICSharpCode.UnitTesting @@ -71,9 +97,9 @@ namespace ICSharpCode.UnitTesting
void GotoFilePosition(FilePosition filePosition)
{
if (filePosition.Position.IsEmpty) {
FileService.OpenFile(filePosition.FileName);
fileService.OpenFile(filePosition.FileName);
} else {
FileService.JumpToFilePosition(filePosition.FileName, filePosition.Line, filePosition.Column);
fileService.JumpToFilePosition(filePosition.FileName, filePosition.Line - 1, filePosition.Column - 1);
}
}
}

23
src/AddIns/Analysis/UnitTesting/Src/UnitTestDebuggerService.cs

@ -0,0 +1,23 @@ @@ -0,0 +1,23 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.SharpDevelop.Debugging;
namespace ICSharpCode.UnitTesting
{
public class UnitTestDebuggerService : IUnitTestDebuggerService
{
public bool IsDebuggerLoaded {
get { return DebuggerService.IsDebuggerLoaded; }
}
public IDebugger CurrentDebugger {
get { return DebuggerService.CurrentDebugger; }
}
}
}

25
src/AddIns/Analysis/UnitTesting/Src/UnitTestFileService.cs

@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.SharpDevelop;
namespace ICSharpCode.UnitTesting
{
public class UnitTestFileService : IUnitTestFileService
{
public void OpenFile(string fileName)
{
FileService.OpenFile(fileName);
}
public void JumpToFilePosition(string fileName, int line, int column)
{
FileService.JumpToFilePosition(fileName, line, column);
}
}
}

20
src/AddIns/Analysis/UnitTesting/Src/UnitTestMessageService.cs

@ -0,0 +1,20 @@ @@ -0,0 +1,20 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.Core;
namespace ICSharpCode.UnitTesting
{
public class UnitTestMessageService : IUnitTestMessageService
{
public bool AskQuestion(string question, string caption)
{
return MessageService.AskQuestion(question, caption);
}
}
}

57
src/AddIns/Analysis/UnitTesting/Src/UnitTestProcessRunner.cs

@ -0,0 +1,57 @@ @@ -0,0 +1,57 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.SharpDevelop.Util;
namespace ICSharpCode.UnitTesting
{
public class UnitTestProcessRunner : IUnitTestProcessRunner
{
ProcessRunner runner;
public event LineReceivedEventHandler OutputLineReceived {
add { runner.OutputLineReceived += value; }
remove { runner.OutputLineReceived -= value; }
}
public event LineReceivedEventHandler ErrorLineReceived {
add { runner.ErrorLineReceived += value; }
remove { runner.ErrorLineReceived -= value; }
}
public event EventHandler ProcessExited {
add { runner.ProcessExited += value; }
remove { runner.ProcessExited -= value; }
}
public UnitTestProcessRunner()
{
runner = new ProcessRunner();
}
public bool LogStandardOutputAndError {
get { return runner.LogStandardOutputAndError; }
set { runner.LogStandardOutputAndError = value; }
}
public string WorkingDirectory {
get { return runner.WorkingDirectory; }
set { runner.WorkingDirectory = value; }
}
public void Start(string command, string arguments)
{
runner.Start(command, arguments);
}
public void Kill()
{
runner.Kill();
}
}
}

19
src/AddIns/Analysis/UnitTesting/Src/UnitTestSaveAllFilesCommand.cs

@ -0,0 +1,19 @@ @@ -0,0 +1,19 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
namespace ICSharpCode.UnitTesting
{
public class UnitTestSaveAllFilesCommand : IUnitTestSaveAllFilesCommand
{
public void SaveAllFiles()
{
ICSharpCode.SharpDevelop.Commands.SaveAllFiles.SaveAll();
}
}
}

39
src/AddIns/Analysis/UnitTesting/Src/UnitTestTaskService.cs

@ -0,0 +1,39 @@ @@ -0,0 +1,39 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.UnitTesting
{
public class UnitTestTaskService : IUnitTestTaskService
{
public void ClearExceptCommentTasks()
{
TaskService.ClearExceptCommentTasks();
}
public bool InUpdate {
get { return TaskService.InUpdate; }
set { TaskService.InUpdate = value; }
}
public MessageViewCategory BuildMessageViewCategory {
get { return TaskService.BuildMessageViewCategory; }
}
public void Add(Task task)
{
TaskService.Add(task);
}
public bool SomethingWentWrong {
get { return TaskService.SomethingWentWrong; }
}
}
}

31
src/AddIns/Analysis/UnitTesting/Src/UnitTestWorkbench.cs

@ -0,0 +1,31 @@ @@ -0,0 +1,31 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.UnitTesting
{
public class UnitTestWorkbench : IUnitTestWorkbench
{
public PadDescriptor GetPad(Type type)
{
return WorkbenchSingleton.Workbench.GetPad(type);
}
public void SafeThreadAsyncCall(Action method)
{
WorkbenchSingleton.SafeThreadAsyncCall(method);
}
public void SafeThreadAsyncCall<A>(Action<A> method, A arg1)
{
WorkbenchSingleton.SafeThreadAsyncCall(method, arg1);
}
}
}

79
src/AddIns/Analysis/UnitTesting/Src/UnitTestsPad.cs

@ -18,7 +18,7 @@ using ICSharpCode.SharpDevelop.Project; @@ -18,7 +18,7 @@ using ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.UnitTesting
{
public class UnitTestsPad : AbstractPadContent
public class UnitTestsPad : AbstractPadContent, IUnitTestsPad
{
TestTreeView treeView;
bool disposed;
@ -28,11 +28,16 @@ namespace ICSharpCode.UnitTesting @@ -28,11 +28,16 @@ namespace ICSharpCode.UnitTesting
static UnitTestsPad instance;
public UnitTestsPad()
: this(TestService.RegisteredTestFrameworks)
{
}
public UnitTestsPad(IRegisteredTestFrameworks testFrameworks)
{
instance = this;
panel = new Panel();
treeView = CreateTestTreeView();
treeView = CreateTestTreeView(testFrameworks);
treeView.Dock = DockStyle.Fill;
treeView.DoubleClick += TestTreeViewDoubleClick;
treeView.KeyPress += TestTreeViewKeyPress;
@ -49,7 +54,6 @@ namespace ICSharpCode.UnitTesting @@ -49,7 +54,6 @@ namespace ICSharpCode.UnitTesting
OnAddedLoadSolutionProjectsThreadEndedHandler();
// Display currently open solution.
if (!IsParserLoadingSolution) {
Solution openSolution = GetOpenSolution();
if (openSolution != null) {
@ -68,15 +72,11 @@ namespace ICSharpCode.UnitTesting @@ -68,15 +72,11 @@ namespace ICSharpCode.UnitTesting
}
public static UnitTestsPad Instance {
get {
return instance;
}
get { return instance; }
}
public override object Control {
get {
return panel;
}
get { return panel; }
}
public override void Dispose()
@ -97,9 +97,22 @@ namespace ICSharpCode.UnitTesting @@ -97,9 +97,22 @@ namespace ICSharpCode.UnitTesting
}
public TestTreeView TestTreeView {
get {
return treeView;
}
get { return treeView; }
}
public void ResetTestResults()
{
treeView.ResetTestResults();
}
public IProject[] GetProjects()
{
return treeView.GetProjects();
}
public TestProject GetTestProject(IProject project)
{
return treeView.GetTestProject(project);
}
/// <summary>
@ -137,15 +150,7 @@ namespace ICSharpCode.UnitTesting @@ -137,15 +150,7 @@ namespace ICSharpCode.UnitTesting
protected void SolutionFolderRemoved(ISolutionFolder solutionFolder)
{
IProject project = solutionFolder as IProject;
if (project != null) {
treeView.RemoveProject(project);
}
if (solutionFolder is ISolutionFolderContainer) {
// recurse into child folders that were also removed
((ISolutionFolderContainer)solutionFolder).Folders.ForEach(SolutionFolderRemoved);
}
treeView.RemoveSolutionFolder(solutionFolder);
}
/// <summary>
@ -164,23 +169,12 @@ namespace ICSharpCode.UnitTesting @@ -164,23 +169,12 @@ namespace ICSharpCode.UnitTesting
/// </summary>
protected void ProjectItemRemoved(ProjectItem projectItem)
{
if (IsTestFrameworkReferenceProjectItem(projectItem)) {
if (!TestProject.IsTestProject(projectItem.Project)) {
treeView.RemoveProject(projectItem.Project);
}
}
treeView.ProjectItemRemoved(projectItem);
}
/// <summary>
/// Adds the test project to the test tree view if it has
/// a reference to a unit testing framework and is not
/// already in the test tree.
/// </summary>
protected void ProjectItemAdded(ProjectItem projectItem)
{
if (IsTestFrameworkReferenceProjectItem(projectItem)) {
treeView.AddProject(projectItem.Project);
}
treeView.ProjectItemAdded(projectItem);
}
/// <summary>
@ -213,9 +207,9 @@ namespace ICSharpCode.UnitTesting @@ -213,9 +207,9 @@ namespace ICSharpCode.UnitTesting
/// Virtual method so we can override this method and return
/// a dummy TestTreeView when testing.
/// </summary>
protected virtual TestTreeView CreateTestTreeView()
protected virtual TestTreeView CreateTestTreeView(IRegisteredTestFrameworks testFrameworks)
{
return new TestTreeView();
return new TestTreeView(testFrameworks);
}
/// <summary>
@ -231,9 +225,7 @@ namespace ICSharpCode.UnitTesting @@ -231,9 +225,7 @@ namespace ICSharpCode.UnitTesting
/// solution.
/// </summary>
protected virtual bool IsParserLoadingSolution {
get {
return ParserService.LoadSolutionProjectsThreadRunning;
}
get { return ParserService.LoadSolutionProjectsThreadRunning; }
}
/// <summary>
@ -320,15 +312,6 @@ namespace ICSharpCode.UnitTesting @@ -320,15 +312,6 @@ namespace ICSharpCode.UnitTesting
command.Run();
}
bool IsTestFrameworkReferenceProjectItem(ProjectItem projectItem)
{
ReferenceProjectItem referenceProjectItem = projectItem as ReferenceProjectItem;
if (referenceProjectItem != null) {
return TestProject.IsTestFrameworkReference(referenceProjectItem);
}
return false;
}
void ProjectItemAdded(object source, ProjectItemEventArgs e)
{
ProjectItemAdded(e.ProjectItem);

47
src/AddIns/Analysis/UnitTesting/Test/Frameworks/CreateNUnitTestRunnerTestFixture.cs

@ -0,0 +1,47 @@ @@ -0,0 +1,47 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.Core;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
namespace UnitTesting.Tests.Frameworks
{
[TestFixture]
public class CreateNUnitTestRunnerTestFixture
{
[TestFixtureSetUp]
public void SetUpFixture()
{
if (!PropertyService.Initialized) {
PropertyService.InitializeService(String.Empty, String.Empty, String.Empty);
}
}
[Test]
public void NUnitTestFrameworkCreateTestRunnerReturnsNUnitTestRunner()
{
NUnitTestFramework testFramework = new NUnitTestFramework();
Assert.IsInstanceOf(typeof(NUnitTestRunner), testFramework.CreateTestRunner());
}
[Test]
public void NUnitTestFrameworkCreateTestDebuggerReturnsNUnitTestDebugger()
{
NUnitTestFramework testFramework = new NUnitTestFramework();
Assert.IsInstanceOf(typeof(NUnitTestDebugger), testFramework.CreateTestDebugger());
}
[Test]
public void IsBuildNeededBeforeTestRunReturnsTrue()
{
NUnitTestFramework testFramework = new NUnitTestFramework();
Assert.IsTrue(testFramework.IsBuildNeededBeforeTestRun);
}
}
}

266
src/AddIns/Analysis/UnitTesting/Test/Frameworks/NUnitConsoleCommandLineTests.cs

@ -0,0 +1,266 @@ @@ -0,0 +1,266 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests.Frameworks
{
[TestFixture]
public class NUnitConsoleCommandLineTests
{
CompilableProject project;
[SetUp]
public void SetUp()
{
project = new MockCSharpProject();
project.FileName = @"C:\Projects\MyTests\MyTests.csproj";
project.AssemblyName = "MyTests";
project.OutputType = OutputType.Library;
project.SetProperty("OutputPath", null);
}
[Test]
public void TestResultsFile()
{
SelectedTests selectedTests = new SelectedTests(project);
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests);
app.NoLogo = false;
app.ShadowCopy = true;
app.Results = @"C:\results.txt";
string expectedCommandLine = "\"C:\\Projects\\MyTests\\MyTests.dll\" /results=\"C:\\results.txt\"";
Assert.AreEqual(expectedCommandLine, app.GetArguments());
}
[Test]
public void NoLogo()
{
SelectedTests selectedTests = new SelectedTests(project);
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests);
app.NoLogo = true;
app.ShadowCopy = true;
string expectedCommandLine = "\"C:\\Projects\\MyTests\\MyTests.dll\" /nologo";
Assert.AreEqual(expectedCommandLine, app.GetArguments());
}
[Test]
public void NoShadowCopy()
{
SelectedTests selectedTests = new SelectedTests(project);
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests);
app.NoLogo = false;
app.ShadowCopy = false;
string expectedCommandLine = "\"C:\\Projects\\MyTests\\MyTests.dll\" /noshadow";
Assert.AreEqual(expectedCommandLine, app.GetArguments());
}
[Test]
public void NoThread()
{
SelectedTests selectedTests = new SelectedTests(project);
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests);
app.NoLogo = false;
app.ShadowCopy = true;
app.NoThread = true;
string expectedCommandLine = "\"C:\\Projects\\MyTests\\MyTests.dll\" /nothread";
Assert.AreEqual(expectedCommandLine, app.GetArguments());
}
[Test]
public void NoDots()
{
SelectedTests selectedTests = new SelectedTests(project);
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests);
app.NoLogo = false;
app.ShadowCopy = true;
app.NoDots = true;
string expectedCommandLine = "\"C:\\Projects\\MyTests\\MyTests.dll\" /nodots";
Assert.AreEqual(expectedCommandLine, app.GetArguments());
}
[Test]
public void Labels()
{
SelectedTests selectedTests = new SelectedTests(project);
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests);
app.NoLogo = false;
app.ShadowCopy = true;
app.Labels = true;
string expectedCommandLine = "\"C:\\Projects\\MyTests\\MyTests.dll\" /labels";
Assert.AreEqual(expectedCommandLine, app.GetArguments());
}
[Test]
public void TestFixture()
{
SelectedTests selectedTests = new SelectedTests(project);
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests);
app.NoLogo = false;
app.ShadowCopy = true;
app.Fixture = "TestFixture";
string expectedCommandLine = "\"C:\\Projects\\MyTests\\MyTests.dll\" /run=\"TestFixture\"";
Assert.AreEqual(expectedCommandLine, app.GetArguments());
}
[Test]
public void TestNamespace()
{
SelectedTests selectedTests = new SelectedTests(project);
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests);
app.NoLogo = false;
app.ShadowCopy = true;
app.NamespaceFilter = "TestFixture";
string expectedCommandLine = "\"C:\\Projects\\MyTests\\MyTests.dll\" /run=\"TestFixture\"";
Assert.AreEqual(expectedCommandLine, app.GetArguments());
}
[Test]
public void XmlOutputFile()
{
SelectedTests selectedTests = new SelectedTests(project);
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests);
app.NoLogo = false;
app.ShadowCopy = true;
app.XmlOutputFile = @"C:\NUnit.xml";
string expectedCommandLine = "\"C:\\Projects\\MyTests\\MyTests.dll\" /xml=\"C:\\NUnit.xml\"";
Assert.AreEqual(expectedCommandLine, app.GetArguments());
}
[Test]
public void TestMethod()
{
SelectedTests selectedTests = new SelectedTests(project);
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests);
app.NoLogo = false;
app.ShadowCopy = true;
app.Fixture = "TestFixture";
app.Test = "Test";
string expectedCommandLine = "\"C:\\Projects\\MyTests\\MyTests.dll\" /run=\"TestFixture.Test\"";
Assert.AreEqual(expectedCommandLine, app.GetArguments());
}
[Test]
public void TestMethodSpecifiedInInitialize()
{
MockClass testFixture = new MockClass("TestFixture");
MockMethod testMethod = new MockMethod(testFixture, "Test");
SelectedTests selectedTests = new SelectedTests(project, null, testFixture, testMethod);
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests);
app.NoLogo = false;
app.ShadowCopy = true;
string expectedCommandLine = "\"C:\\Projects\\MyTests\\MyTests.dll\" /run=\"TestFixture.Test\"";
Assert.AreEqual(expectedCommandLine, app.GetArguments());
}
[Test]
public void TestNamespaceSpecifiedInInitialize()
{
SelectedTests selectedTests = new SelectedTests(project, "Project.MyTests", null, null);
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests);
app.NoLogo = false;
app.ShadowCopy = true;
string expectedCommandLine = "\"C:\\Projects\\MyTests\\MyTests.dll\" /run=\"Project.MyTests\"";
Assert.AreEqual(expectedCommandLine, app.GetArguments());
}
[Test]
public void FullCommandLine()
{
SelectedTests selectedTests = new SelectedTests(project);
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests);
app.NoLogo = true;
app.ShadowCopy = true;
FileUtility.ApplicationRootPath = @"C:\SharpDevelop";
string expectedFullCommandLine =
"\"C:\\SharpDevelop\\bin\\Tools\\NUnit\\nunit-console-x86.exe\" " +
"\"C:\\Projects\\MyTests\\MyTests.dll\" " +
"/nologo";
Assert.AreEqual(expectedFullCommandLine, app.GetCommandLine());
}
/// <summary>
/// Tests that a space is appended between the items added
/// to the UnitTestApplicationStartapp.Assemblies
/// when the command line is generated.
/// </summary>
[Test]
public void SecondAssemblySpecified()
{
SelectedTests selectedTests = new SelectedTests(project);
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests);
app.Assemblies.Add("SecondAssembly.dll");
app.NoLogo = false;
app.ShadowCopy = true;
app.Results = @"C:\results.txt";
string expectedCommandLine =
"\"C:\\Projects\\MyTests\\MyTests.dll\" " +
"\"SecondAssembly.dll\" " +
"/results=\"C:\\results.txt\"";
Assert.AreEqual(expectedCommandLine, app.GetArguments());
}
[Test]
public void GetProject()
{
SelectedTests selectedTests = new SelectedTests(project);
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests);
Assert.AreSame(project, app.Project);
}
[Test]
public void TestInnerClassSpecifiedInInitialize()
{
MockClass testFixture = new MockClass("MyTests.TestFixture.InnerTest", "MyTests.TestFixture+InnerTest");
SelectedTests selectedTests = new SelectedTests(project, null, testFixture, null);
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests);
app.NoLogo = false;
app.ShadowCopy = true;
string expectedCommandLine = "\"C:\\Projects\\MyTests\\MyTests.dll\" " +
"/run=\"MyTests.TestFixture+InnerTest\"";
Assert.AreEqual(expectedCommandLine, app.GetArguments());
}
[Test]
public void XmlOutputFileNameSpecifiedOnCommandLine()
{
UnitTestingOptions options = new UnitTestingOptions(new Properties());
options.CreateXmlOutputFile = true;
MockClass testFixture = new MockClass("MyTests.TestFixture.MyTest");
SelectedTests selectedTests = new SelectedTests(project, null, testFixture, null);
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests, options);
app.NoLogo = false;
app.ShadowCopy = true;
string expectedCommandLine =
"\"C:\\Projects\\MyTests\\MyTests.dll\" " +
"/xml=\"C:\\Projects\\MyTests\\MyTests-TestResult.xml\" " +
"/run=\"MyTests.TestFixture.MyTest\"";
Assert.AreEqual(expectedCommandLine, app.GetArguments());
}
}
}

36
src/AddIns/Analysis/UnitTesting/Test/NUnitConsoleExeSelectedTestFixture.cs → src/AddIns/Analysis/UnitTesting/Test/Frameworks/NUnitConsoleExeSelectedTestFixture.cs

@ -12,7 +12,7 @@ using NUnit.Framework; @@ -12,7 +12,7 @@ using NUnit.Framework;
using ICSharpCode.UnitTesting;
using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests
namespace UnitTesting.Tests.Frameworks
{
/// <summary>
/// If the project explicitly targets 32 bit (x86) architecture then nunit-console-x86.exe should be
@ -23,7 +23,7 @@ namespace UnitTesting.Tests @@ -23,7 +23,7 @@ namespace UnitTesting.Tests
{
string oldRootPath;
[TestFixtureSetUpAttribute]
[TestFixtureSetUp]
public void SetUpFixture()
{
oldRootPath = FileUtility.ApplicationRootPath;
@ -40,12 +40,11 @@ namespace UnitTesting.Tests @@ -40,12 +40,11 @@ namespace UnitTesting.Tests
public void NothingSpecified()
{
MockCSharpProject project = new MockCSharpProject();
UnitTestApplicationStartHelper helper = new UnitTestApplicationStartHelper();
helper.Initialize(project, null);
Assert.AreEqual(@"D:\SharpDevelop\bin\Tools\NUnit\nunit-console-dotnet2-x86.exe", helper.UnitTestApplication);
SelectedTests selectedTests = new SelectedTests(project);
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests);
Assert.AreEqual(@"D:\SharpDevelop\bin\Tools\NUnit\nunit-console-x86.exe", app.FileName);
}
[Test]
public void TargetCpuAnyCPUDotnet2()
{
@ -55,9 +54,9 @@ namespace UnitTesting.Tests @@ -55,9 +54,9 @@ namespace UnitTesting.Tests
project.SetProperty("PlatformTarget", "AnyCPU");
project.SetProperty("TargetFrameworkVersion", "v3.5");
UnitTestApplicationStartHelper helper = new UnitTestApplicationStartHelper();
helper.Initialize(project, null);
Assert.AreEqual(@"D:\SharpDevelop\bin\Tools\NUnit\nunit-console-dotnet2.exe", helper.UnitTestApplication);
SelectedTests selectedTests = new SelectedTests(project);
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests);
Assert.AreEqual(@"D:\SharpDevelop\bin\Tools\NUnit\nunit-console-dotnet2.exe", app.FileName);
}
[Test]
@ -69,9 +68,9 @@ namespace UnitTesting.Tests @@ -69,9 +68,9 @@ namespace UnitTesting.Tests
project.SetProperty("PlatformTarget", "x86");
project.SetProperty("TargetFrameworkVersion", "v3.5");
UnitTestApplicationStartHelper helper = new UnitTestApplicationStartHelper();
helper.Initialize(project, null);
Assert.AreEqual(@"D:\SharpDevelop\bin\Tools\NUnit\nunit-console-dotnet2-x86.exe", helper.UnitTestApplication);
SelectedTests selectedTests = new SelectedTests(project);
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests);
Assert.AreEqual(@"D:\SharpDevelop\bin\Tools\NUnit\nunit-console-dotnet2-x86.exe", app.FileName);
}
[Test]
@ -81,22 +80,21 @@ namespace UnitTesting.Tests @@ -81,22 +80,21 @@ namespace UnitTesting.Tests
project.ActiveConfiguration = "Debug";
project.ActivePlatform = "AnyCPU";
project.SetProperty("PlatformTarget", "x86");
project.SetProperty("TargetFrameworkVersion", "v4.0");
UnitTestApplicationStartHelper helper = new UnitTestApplicationStartHelper();
helper.Initialize(project, null);
Assert.AreEqual(@"D:\SharpDevelop\bin\Tools\NUnit\nunit-console-x86.exe", helper.UnitTestApplication);
SelectedTests selectedTests = new SelectedTests(project);
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests);
Assert.AreEqual(@"D:\SharpDevelop\bin\Tools\NUnit\nunit-console-x86.exe", app.FileName);
}
[Test]
public void NotMSBuildBasedProject()
{
MissingProject project = new MissingProject(@"C:\Projects\Test.proj", "Test");
UnitTestApplicationStartHelper helper = new UnitTestApplicationStartHelper();
helper.Initialize(project, null);
SelectedTests selectedTests = new SelectedTests(project);
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests);
Assert.AreEqual(project.GetType().BaseType, typeof(AbstractProject), "MissingProject should be derived from AbstractProject.");
Assert.AreEqual(@"D:\SharpDevelop\bin\Tools\NUnit\nunit-console.exe", helper.UnitTestApplication);
Assert.AreEqual(@"D:\SharpDevelop\bin\Tools\NUnit\nunit-console.exe", app.FileName);
}
}
}

62
src/AddIns/Analysis/UnitTesting/Test/Frameworks/NUnitConsoleProcessStartInfoTestFixture.cs

@ -0,0 +1,62 @@ @@ -0,0 +1,62 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Diagnostics;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests.Frameworks
{
[TestFixture]
public class NUnitConsoleProcessStartInfoTestFixture
{
ProcessStartInfo info;
[TestFixtureSetUp]
public void SetUpFixture()
{
FileUtility.ApplicationRootPath = @"C:\SharpDevelop";
}
[SetUp]
public void Init()
{
MockCSharpProject project = new MockCSharpProject();
SelectedTests selectedTests = new SelectedTests(project);
NUnitConsoleApplication app = new NUnitConsoleApplication(selectedTests);
info = app.GetProcessStartInfo();
}
[Test]
public void WorkingDirectoryIsNUnitConsoleApplicationDirectory()
{
string expectedDirectory = @"C:\SharpDevelop\bin\Tools\NUnit";
Assert.AreEqual(expectedDirectory, info.WorkingDirectory);
}
[Test]
public void FileNameIsNUnitConsoleExe()
{
string expectedFileName = @"C:\SharpDevelop\bin\Tools\NUnit\nunit-console-x86.exe";
Assert.AreEqual(expectedFileName, info.FileName);
}
[Test]
public void CommandLineArgumentsAreNUnitConsoleExeCommandLineArguments()
{
string expectedCommandLine =
"\"c:\\projects\\MyTests\\bin\\Debug\\MyTests.dll\"";
Assert.AreEqual(expectedCommandLine, info.Arguments);
}
}
}

90
src/AddIns/Analysis/UnitTesting/Test/Frameworks/NUnitTestFrameworkIsTestClassTests.cs

@ -0,0 +1,90 @@ @@ -0,0 +1,90 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests.Frameworks
{
[TestFixture]
public class NUnitTestFrameworkIsTestClassTests
{
NUnitTestFramework testFramework;
[SetUp]
public void Init()
{
testFramework = new NUnitTestFramework();
}
[Test]
public void IsTestClassReturnsFalseHasClassHasNoAttributes()
{
MockClass mockClass = MockClass.CreateMockClassWithoutAnyAttributes();
Assert.IsFalse(testFramework.IsTestClass(mockClass));
}
[Test]
public void IsTestClassReturnsTrueHasClassHasTestFixtureAttributeMissingAttributePart()
{
MockAttribute testAttribute = new MockAttribute("TestFixture");
MockClass mockClass = MockClass.CreateMockClassWithAttribute(testAttribute);
Assert.IsTrue(testFramework.IsTestClass(mockClass));
}
[Test]
public void IsTestClassReturnsTrueHasClassHasTestFixtureAttribute()
{
MockAttribute testFixtureAttribute = new MockAttribute("TestFixtureAttribute");
MockClass mockClass = MockClass.CreateMockClassWithAttribute(testFixtureAttribute);
Assert.IsTrue(testFramework.IsTestClass(mockClass));
}
[Test]
public void IsTestClassReturnsTrueHasClassHasFullyQualifiedNUnitTestFixtureAttribute()
{
MockAttribute testFixtureAttribute = new MockAttribute("NUnit.Framework.TestFixtureAttribute");
MockClass mockClass = MockClass.CreateMockClassWithAttribute(testFixtureAttribute);
Assert.IsTrue(testFramework.IsTestClass(mockClass));
}
[Test]
public void IsTestClassReturnsFalseWhenClassIsNull()
{
Assert.IsFalse(testFramework.IsTestClass(null));
}
[Test]
public void IsTestClassReturnsFalseWhenProjectContentLanguageIsNull()
{
IProject project = new MockCSharpProject();
MockProjectContent mockProjectContent = new MockProjectContent();
mockProjectContent.Project = project;
MockClass mockClass = new MockClass(mockProjectContent);
Assert.IsFalse(testFramework.IsTestClass(mockClass));
}
[Test]
public void IsTestClassReturnsFalseWhenProjectContentLanguageNameComparerIsNull()
{
IProject project = new MockCSharpProject();
MockProjectContent mockProjectContent = new MockProjectContent();
mockProjectContent.Project = project;
mockProjectContent.Language = new LanguageProperties(null);
MockClass mockClass = new MockClass(mockProjectContent);
mockClass.Attributes.Add(new MockAttribute("Test"));
Assert.IsFalse(testFramework.IsTestClass(mockClass));
}
}
}

113
src/AddIns/Analysis/UnitTesting/Test/Frameworks/NUnitTestFrameworkIsTestMethodTests.cs

@ -0,0 +1,113 @@ @@ -0,0 +1,113 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests.Frameworks
{
[TestFixture]
public class NUnitTestFrameworkIsTestMethodTests
{
NUnitTestFramework testFramework;
[SetUp]
public void Init()
{
testFramework = new NUnitTestFramework();
}
[Test]
public void IsTestMethodReturnsFalseWhenMethodHasNoAttributes()
{
MockMethod mockMethod = MockMethod.CreateMockMethodWithoutAnyAttributes();
Assert.IsFalse(testFramework.IsTestMethod(mockMethod));
}
[Test]
public void IsTestMethodReturnsTrueWhenMethodHasTestAttributeWithoutAttributePart()
{
MockAttribute testAttribute = new MockAttribute("Test");
MockMethod mockMethod = MockMethod.CreateMockMethodWithAttribute(testAttribute);
Assert.IsTrue(testFramework.IsTestMethod(mockMethod));
}
[Test]
public void IsTestMethodReturnsTrueWhenMethodHasTestAttributeAttribute()
{
MockAttribute testAttribute = new MockAttribute("TestAttribute");
MockMethod mockMethod = MockMethod.CreateMockMethodWithAttribute(testAttribute);
Assert.IsTrue(testFramework.IsTestMethod(mockMethod));
}
[Test]
public void IsTestMethodReturnsTrueWhenMethodHasFullyQualifiedNUnitTestAttribute()
{
MockAttribute testAttribute = new MockAttribute("NUnit.Framework.TestAttribute");
MockMethod mockMethod = MockMethod.CreateMockMethodWithAttribute(testAttribute);
Assert.IsTrue(testFramework.IsTestMethod(mockMethod));
}
[Test]
public void IsTestMethodReturnsFalseWhenMethodIsNull()
{
Assert.IsFalse(testFramework.IsTestMethod(null));
}
[Test]
public void IsTestMethodReturnsFalseWhenProjectContentLanguageHasNullNameComparer()
{
MockClass mockClass = MockClass.CreateMockClassWithoutAnyAttributes();
mockClass.MockProjectContent.Language = new LanguageProperties(null);
MockMethod mockMethod = new MockMethod(mockClass);
mockMethod.Attributes.Add(new MockAttribute("Test"));
Assert.IsFalse(testFramework.IsTestMethod(mockMethod));
}
/// <summary>
/// Even if the project is null the method should be
/// flagged as a TestMethod.
/// </summary>
[Test]
public void IsTestMethodReturnsTrueWhenProjectIsNull()
{
MockAttribute testAttribute = new MockAttribute("Test");
MockMethod mockMethod = MockMethod.CreateMockMethodWithAttribute(testAttribute);
MockProjectContent mockProjectContent = (MockProjectContent)mockMethod.DeclaringType.ProjectContent;
mockProjectContent.Project = null;
Assert.IsTrue(testFramework.IsTestMethod(mockMethod));
}
[Test]
public void IsTestMethodReturnsFalseWhenMethodHasNullLanguage()
{
MockClass mockClass = MockClass.CreateMockClassWithoutAnyAttributes();
mockClass.MockProjectContent.Language = null;
MockMethod mockMethod = new MockMethod(mockClass);
Assert.IsFalse(testFramework.IsTestMethod(mockMethod));
}
[Test]
public void IsTestMethodReturnsFalseWhenMethodHasHasParameters()
{
MockAttribute testAttribute = new MockAttribute("Test");
MockMethod mockMethod = MockMethod.CreateMockMethodWithAttribute(testAttribute);
MockParameter mockParameter = new MockParameter();
mockMethod.Parameters.Add(mockParameter);
Assert.IsFalse(testFramework.IsTestMethod(mockMethod));
}
}
}

96
src/AddIns/Analysis/UnitTesting/Test/Frameworks/NUnitTestFrameworkIsTestProjectTests.cs

@ -0,0 +1,96 @@ @@ -0,0 +1,96 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests.Frameworks
{
[TestFixture]
public class NUnitTestFrameworkIsTestProjectTests
{
NUnitTestFramework testFramework;
[SetUp]
public void Init()
{
testFramework = new NUnitTestFramework();
}
[Test]
public void NUnitTestFrameworkImplementsITestFramework()
{
Assert.IsNotNull(testFramework as ITestFramework);
}
[Test]
public void IsTestProjectReturnsFalseForNullProject()
{
Assert.IsFalse(testFramework.IsTestProject(null));
}
[Test]
public void IsTestProjectReturnsTrueForProjectWithNUnitFrameworkAssemblyReference()
{
MockCSharpProject project = new MockCSharpProject();
ReferenceProjectItem systemRef = new ReferenceProjectItem(project, "System");
ProjectService.AddProjectItem(project, systemRef);
ReferenceProjectItem nunitFrameworkRef = new ReferenceProjectItem(project, "NUnit.Framework");
ProjectService.AddProjectItem(project, nunitFrameworkRef);
Assert.IsTrue(testFramework.IsTestProject(project));
}
[Test]
public void IsTestProjectReturnsFalseForProjectWithoutNUnitFrameworkAssemblyReference()
{
MockCSharpProject project = new MockCSharpProject();
Assert.IsFalse(testFramework.IsTestProject(project));
}
[Test]
public void IsTestProjectReturnsTrueForProjectWithNUnitFrameworkAssemblyReferenceIgnoringCase()
{
MockCSharpProject project = new MockCSharpProject();
ReferenceProjectItem nunitFrameworkRef = new ReferenceProjectItem(project, "NUNIT.FRAMEWORK");
ProjectService.AddProjectItem(project, nunitFrameworkRef);
Assert.IsTrue(testFramework.IsTestProject(project));
}
[Test]
public void IsTestProjectReturnsTrueForProjectWithNUnitFrameworkAssemblyReferenceIgnoringNonReferenceProjectItems()
{
MockCSharpProject project = new MockCSharpProject();
FileProjectItem fileItem = new FileProjectItem(project, ItemType.Compile, "test.cs");
ProjectService.AddProjectItem(project, fileItem);
ReferenceProjectItem nunitFrameworkRef = new ReferenceProjectItem(project, "nunit.framework");
ProjectService.AddProjectItem(project, nunitFrameworkRef);
Assert.IsTrue(testFramework.IsTestProject(project));
}
[Test]
public void IsTestProjectReturnsTrueForProjectWithNUnitFrameworkAssemblyReferenceUsingFullName()
{
MockCSharpProject project = new MockCSharpProject();
string assemblyName = "nunit.framework, Version=2.5.3.9345, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77";
ReferenceProjectItem nunitFrameworkRef = new ReferenceProjectItem(project, assemblyName);
ProjectService.AddProjectItem(project, nunitFrameworkRef);
Assert.IsTrue(testFramework.IsTestProject(project));
}
}
}

74
src/AddIns/Analysis/UnitTesting/Test/Frameworks/NUnitTestResultFailureTestFixture.cs

@ -0,0 +1,74 @@ @@ -0,0 +1,74 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
namespace UnitTesting.Tests.Tree
{
[TestFixture]
public class NUnitTestResultFailureTestFixture
{
NUnitTestResult nunitTestResult;
[SetUp]
public void Init()
{
TestResult testResult = new TestResult("MyNamespace.MyTests");
testResult.ResultType = TestResultType.Failure;
testResult.Message = "Test failed";
testResult.StackTrace =
"Test Error : MyTest.Test\r\n" +
"at TestResultTask.Create() in c:\\projects\\SharpDevelop\\TestResultTask.cs:line 45\r\n" +
"at MyTest.Test() in c:\\myprojects\\test\\..\\test\\mytest.cs:line 28\r\n" +
"";
nunitTestResult = new NUnitTestResult(testResult);
}
[Test]
public void TestResultTypeIsFailure()
{
Assert.AreEqual(TestResultType.Failure, nunitTestResult.ResultType);
}
[Test]
public void TestResultMessageIsTestFailed()
{
Assert.AreEqual("Test failed", nunitTestResult.Message);
}
[Test]
public void StackTraceFilePositionFileNameMatchesLastFileNameInStackTrace()
{
string expectedFileName = @"c:\myprojects\test\mytest.cs";
Assert.AreEqual(expectedFileName, nunitTestResult.StackTraceFilePosition.FileName);
}
[Test]
public void StackTraceFilePositionLineNumberIs28WhichIsEqualToReportedNUnitErrorLine()
{
Assert.AreEqual(28, nunitTestResult.StackTraceFilePosition.Line);
}
[Test]
public void StackTraceFilePositionColumnNumberIsOne()
{
Assert.AreEqual(1, nunitTestResult.StackTraceFilePosition.Column);
}
[Test]
public void ChangingStackTraceToEmptyStringSetsStackTraceFilePositionToEmpty()
{
nunitTestResult.StackTraceFilePosition = new FilePosition("test.cs", 10, 2);
nunitTestResult.StackTrace = String.Empty;
Assert.IsTrue(nunitTestResult.StackTraceFilePosition.IsEmpty);
}
}
}

240
src/AddIns/Analysis/UnitTesting/Test/Frameworks/RegisteredTestFrameworksTestFixture.cs

@ -0,0 +1,240 @@ @@ -0,0 +1,240 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using ICSharpCode.Core;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests.Frameworks
{
[TestFixture]
public class RegisteredTestFrameworksTestFixture
{
RegisteredTestFrameworks testFrameworks;
MockTestFramework nunitTestFramework;
MockTestFramework mbUnitTestFramework;
[SetUp]
public void Init()
{
List<TestFrameworkDescriptor> descriptors = new List<TestFrameworkDescriptor>();
MockTestFrameworkFactory factory = new MockTestFrameworkFactory();
Properties mbUnitProperties = new Properties();
mbUnitProperties["id"] = "mbunit";
mbUnitProperties["class"] = "MBUnitTestFramework";
mbUnitProperties["supportedProjects"] = ".vbproj";
mbUnitTestFramework = new MockTestFramework();
factory.Add("MBUnitTestFramework", mbUnitTestFramework);
Properties nunitProperties = new Properties();
nunitProperties["id"] = "nunit";
nunitProperties["class"] = "NUnitTestFramework";
nunitProperties["supportedProjects"] = ".csproj";
nunitTestFramework = new MockTestFramework();
factory.Add("NUnitTestFramework", nunitTestFramework);
TestFrameworkDescriptor mbUnitDescriptor = new TestFrameworkDescriptor(mbUnitProperties, factory);
TestFrameworkDescriptor nunitDescriptor = new TestFrameworkDescriptor(nunitProperties, factory);
descriptors.Add(mbUnitDescriptor);
descriptors.Add(nunitDescriptor);
MockAddInTree addinTree = new MockAddInTree();
addinTree.AddItems("/SharpDevelop/UnitTesting/TestFrameworks", descriptors);
testFrameworks = new RegisteredTestFrameworks(addinTree);
}
[Test]
public void NUnitTestFrameworkRegisteredForUseWithProjectsWithCSharpProjectFileExtension()
{
MockCSharpProject project = new MockCSharpProject();
project.FileName = @"d:\projects\test\MyProj.csproj";
Assert.AreEqual(nunitTestFramework, testFrameworks.GetTestFrameworkForProject(project));
}
[Test]
public void MbUnitTestFrameworkRegisteredForUseWithProjectsWithVBNetProjectFileExtension()
{
MockCSharpProject project = new MockCSharpProject();
project.FileName = @"d:\projects\test\MyProj.vbproj";
Assert.AreEqual(mbUnitTestFramework, testFrameworks.GetTestFrameworkForProject(project));
}
[Test]
public void IsTestMethodReturnsFalseForUnknownMbUnitFrameworkTestMethod()
{
MockMethod method = MockMethod.CreateMockMethodWithoutAnyAttributes();
method.MockDeclaringType.MockProjectContent.ProjectAsIProject.FileName = @"d:\projects\test.vbproj";
Assert.IsFalse(testFrameworks.IsTestMethod(method));
}
[Test]
public void IsTestMethodReturnsTrueForKnownMbUnitFrameworkTestMethod()
{
MockMethod method = MockMethod.CreateMockMethodWithoutAnyAttributes();
method.MockDeclaringType.MockProjectContent.ProjectAsIProject.FileName = @"d:\projects\test.vbproj";
mbUnitTestFramework.AddTestMethod(method);
Assert.IsTrue(testFrameworks.IsTestMethod(method));
}
[Test]
public void IsTestMethodDoesNotThrowNullReferenceExceptionWhenNoTestFrameworkSupportsProject()
{
MockMethod method = MockMethod.CreateMockMethodWithoutAnyAttributes();
method.MockDeclaringType.MockProjectContent.ProjectAsIProject.FileName = @"d:\projects\test.unknown";
Assert.IsFalse(testFrameworks.IsTestMethod(method));
}
[Test]
public void IsTestMethodDoesNotThrowNullReferenceWhenNullPassedToMethod()
{
Assert.IsFalse(testFrameworks.IsTestMethod(null));
}
[Test]
public void IsTestClassReturnsFalseForUnknownMbUnitFrameworkTestClass()
{
MockClass c = MockClass.CreateMockClassWithoutAnyAttributes();
c.MockProjectContent.ProjectAsIProject.FileName = @"d:\projects\test.vbproj";
Assert.IsFalse(testFrameworks.IsTestClass(c));
}
[Test]
public void IsTestClassReturnsTrueForKnownMbUnitFrameworkTestClass()
{
MockClass c = MockClass.CreateMockClassWithoutAnyAttributes();
c.MockProjectContent.ProjectAsIProject.FileName = @"d:\projects\test.vbproj";
mbUnitTestFramework.AddTestClass(c);
Assert.IsTrue(testFrameworks.IsTestClass(c));
}
[Test]
public void IsTestClassDoesNotThrowNullReferenceExceptionWhenNoTestFrameworkSupportsProject()
{
MockClass c = MockClass.CreateMockClassWithoutAnyAttributes();
c.MockProjectContent.ProjectAsIProject.FileName = @"d:\projects\test.unknown";
Assert.IsFalse(testFrameworks.IsTestClass(c));
}
[Test]
public void IsTestClassDoesNotThrowNullReferenceWhenNullPassedToMethod()
{
Assert.IsFalse(testFrameworks.IsTestClass(null));
}
[Test]
public void IsTestProjectReturnsFalseForUnknownMbUnitFrameworkTestProject()
{
MockCSharpProject project = new MockCSharpProject();
project.FileName = @"d:\projects\test.vbproj";
Assert.IsFalse(testFrameworks.IsTestProject(project));
}
[Test]
public void IsTestProjectReturnsTrueForKnownMbUnitFrameworkTestProject()
{
MockCSharpProject project = new MockCSharpProject();
project.FileName = @"d:\projects\test.vbproj";
mbUnitTestFramework.AddTestProject(project);
Assert.IsTrue(testFrameworks.IsTestProject(project));
}
[Test]
public void IsTestProjectDoesNotThrowNullReferenceExceptionWhenNoTestFrameworkSupportsProject()
{
MockCSharpProject project = new MockCSharpProject();
project.FileName = @"d:\projects\test.unknown";
Assert.IsFalse(testFrameworks.IsTestProject(project));
}
[Test]
public void IsTestProjectDoesNotThrowNullReferenceWhenNullPassedToMethod()
{
Assert.IsFalse(testFrameworks.IsTestProject(null));
}
[Test]
public void CreateTestRunnerReturnsNewTestRunnerFromCorrectTestFramework()
{
MockCSharpProject project = new MockCSharpProject();
project.FileName = @"d:\projects\test.csproj";
ITestRunner testRunner = testFrameworks.CreateTestRunner(project);
ITestRunner[] expectedTestRunners = new ITestRunner[] { testRunner };
Assert.AreEqual(expectedTestRunners, nunitTestFramework.TestRunnersCreated.ToArray());
}
[Test]
public void CreateTestRunnerDoesNotThrowNullRefExceptionWhenUnknownProjectPassedToCreateTestRunnerMethod()
{
MockCSharpProject project = new MockCSharpProject();
project.FileName = @"d:\projects\test.unknown";
Assert.IsNull(testFrameworks.CreateTestRunner(project));
}
[Test]
public void CreateTestDebuggerReturnsNewTestRunnerFromCorrectTestFramework()
{
MockCSharpProject project = new MockCSharpProject();
project.FileName = @"d:\projects\test.csproj";
ITestRunner testDebugger = testFrameworks.CreateTestDebugger(project);
ITestRunner[] expectedTestRunners = new ITestRunner[] { testDebugger };
Assert.AreEqual(expectedTestRunners, nunitTestFramework.TestDebuggersCreated.ToArray());
}
[Test]
public void CreateTestDebuggerDoesNotThrowNullRefExceptionWhenUnknownProjectPassedToCreateTestRunnerMethod()
{
MockCSharpProject project = new MockCSharpProject();
project.FileName = @"d:\projects\test.unknown";
Assert.IsNull(testFrameworks.CreateTestDebugger(project));
}
[Test]
public void IsBuildNeededBeforeTestRunReturnsTrueWhenTestFrameworkIsBuildNeededBeforeTestRunSetToTrue()
{
MockCSharpProject project = new MockCSharpProject();
project.FileName = @"d:\projects\test.csproj";
nunitTestFramework.IsBuildNeededBeforeTestRun = true;
Assert.IsTrue(testFrameworks.IsBuildNeededBeforeTestRunForProject(project));
}
[Test]
public void IsBuildNeededBeforeTestRunReturnsFalseWhenTestFrameworkIsBuildNeededBeforeTestRunSetToFalse()
{
MockCSharpProject project = new MockCSharpProject();
project.FileName = @"d:\projects\test.csproj";
nunitTestFramework.IsBuildNeededBeforeTestRun = false;
Assert.IsFalse(testFrameworks.IsBuildNeededBeforeTestRunForProject(project));
}
}
}

50
src/AddIns/Analysis/UnitTesting/Test/Frameworks/TestFrameworkDescriptorIgnoresProjectFileExtensionWhitespaceTestFixture.cs

@ -0,0 +1,50 @@ @@ -0,0 +1,50 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.Core;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests.Frameworks
{
[TestFixture]
public class TestFrameworkDescriptorIgnoresProjectFileExtensionWhitespaceTestFixture
{
TestFrameworkDescriptor descriptor;
[SetUp]
public void Init()
{
MockTestFrameworkFactory factory = new MockTestFrameworkFactory();
Properties properties = new Properties();
properties["id"] = "nunit";
properties["supportedProjects"] = " .csproj; .vbproj ";
descriptor = new TestFrameworkDescriptor(properties, factory);
}
[Test]
public void IsSupportedProjectReturnsTrueForCSharpProject()
{
MockCSharpProject project = new MockCSharpProject();
project.FileName = @"d:\projects\myproj.csproj";
Assert.IsTrue(descriptor.IsSupportedProject(project));
}
[Test]
public void IsSupportedProjectReturnsTrueForVBNetProject()
{
MockCSharpProject project = new MockCSharpProject();
project.FileName = @"d:\projects\myproj.vbproj";
Assert.IsTrue(descriptor.IsSupportedProject(project));
}
}
}

50
src/AddIns/Analysis/UnitTesting/Test/Frameworks/TestFrameworkDescriptorSupportsCSharpAndVBNetProjectsTestFixture.cs

@ -0,0 +1,50 @@ @@ -0,0 +1,50 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.Core;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests.Frameworks
{
[TestFixture]
public class TestFrameworkDescriptorSupportsCSharpAndVBNetProjectsTestFixture
{
TestFrameworkDescriptor descriptor;
[SetUp]
public void Init()
{
MockTestFrameworkFactory factory = new MockTestFrameworkFactory();
Properties properties = new Properties();
properties["id"] = "nunit";
properties["supportedProjects"] = ".csproj;.vbproj";
descriptor = new TestFrameworkDescriptor(properties, factory);
}
[Test]
public void IsSupportedProjectReturnsTrueForCSharpProject()
{
MockCSharpProject project = new MockCSharpProject();
project.FileName = @"d:\projects\myproj.csproj";
Assert.IsTrue(descriptor.IsSupportedProject(project));
}
[Test]
public void IsSupportedProjectReturnsTrueForVBNetProject()
{
MockCSharpProject project = new MockCSharpProject();
project.FileName = @"d:\projects\myproj.vbproj";
Assert.IsTrue(descriptor.IsSupportedProject(project));
}
}
}

65
src/AddIns/Analysis/UnitTesting/Test/Frameworks/TestFrameworkDescriptorSupportsCSharpProjectsTestFixture.cs

@ -0,0 +1,65 @@ @@ -0,0 +1,65 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.Core;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests.Frameworks
{
[TestFixture]
public class TestFrameworkDescriptorSupportsCSharpProjectsTestFixture
{
TestFrameworkDescriptor descriptor;
[SetUp]
public void Init()
{
MockTestFrameworkFactory factory = new MockTestFrameworkFactory();
Properties properties = new Properties();
properties["id"] = "nunit";
properties["supportedProjects"] = ".csproj";
descriptor = new TestFrameworkDescriptor(properties, factory);
}
[Test]
public void IsSupportedProjectReturnsTrueForCSharpProject()
{
MockCSharpProject project = new MockCSharpProject();
project.FileName = @"d:\projects\myproj.csproj";
Assert.IsTrue(descriptor.IsSupportedProject(project));
}
[Test]
public void IsSupportedProjectReturnsFalseForVBNetProject()
{
MockCSharpProject project = new MockCSharpProject();
project.FileName = @"d:\projects\myproj.vbproj";
Assert.IsFalse(descriptor.IsSupportedProject(project));
}
[Test]
public void IsSupportedProjectReturnsFalseForNullProject()
{
Assert.IsFalse(descriptor.IsSupportedProject(null));
}
[Test]
public void IsSupportedProjectReturnsTrueForCSharpProjectFileExtensionInUpperCase()
{
MockCSharpProject project = new MockCSharpProject();
project.FileName = @"d:\projects\myproj.CSPROJ";
Assert.IsTrue(descriptor.IsSupportedProject(project));
}
}
}

50
src/AddIns/Analysis/UnitTesting/Test/Frameworks/TestFrameworkDescriptorSupportsUpperCaseProjectFileExtensionsTestFixture.cs

@ -0,0 +1,50 @@ @@ -0,0 +1,50 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.Core;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests.Frameworks
{
[TestFixture]
public class TestFrameworkDescriptorSupportsUpperCaseProjectFileExtensionsTestFixture
{
TestFrameworkDescriptor descriptor;
[SetUp]
public void Init()
{
MockTestFrameworkFactory factory = new MockTestFrameworkFactory();
Properties properties = new Properties();
properties["id"] = "nunit";
properties["supportedProjects"] = ".CSPROJ;.VBPROJ";
descriptor = new TestFrameworkDescriptor(properties, factory);
}
[Test]
public void IsSupportedProjectReturnsTrueForCSharpProject()
{
MockCSharpProject project = new MockCSharpProject();
project.FileName = @"d:\projects\myproj.csproj";
Assert.IsTrue(descriptor.IsSupportedProject(project));
}
[Test]
public void IsSupportedProjectReturnsTrueForVBNetProject()
{
MockCSharpProject project = new MockCSharpProject();
project.FileName = @"d:\projects\myproj.vbproj";
Assert.IsTrue(descriptor.IsSupportedProject(project));
}
}
}

77
src/AddIns/Analysis/UnitTesting/Test/Frameworks/TestFrameworkDoozerTestFixture.cs

@ -0,0 +1,77 @@ @@ -0,0 +1,77 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using ICSharpCode.Core;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests.Frameworks
{
[TestFixture]
public class TestFrameworkDoozerTestFixture
{
TestFrameworkDescriptor descriptor;
TestFrameworkDoozer doozer;
MockTestFramework mockTestFramework;
MockTestFrameworkFactory mockTestFrameworkFactory;
[SetUp]
public void Init()
{
Properties properties = new Properties();
properties["id"] = "Default";
properties["class"] = "UnitTesting.Tests.Utils.MockTestFramework";
Codon codon = new Codon(null, "TestFramework", properties, null);
mockTestFrameworkFactory = new MockTestFrameworkFactory();
mockTestFramework = new MockTestFramework();
mockTestFrameworkFactory.Add("UnitTesting.Tests.Utils.MockTestFramework", mockTestFramework);
doozer = new TestFrameworkDoozer();
descriptor = doozer.BuildItem(codon, mockTestFrameworkFactory);
}
[Test]
public void TestFrameworkDescriptorIdIsDefault()
{
Assert.AreEqual("Default", descriptor.Id);
}
[Test]
public void TestFrameworkDoozerImplementsIDoozer()
{
Assert.IsNotNull(doozer as IDoozer);
}
[Test]
public void TestFrameworkDoozerDoesNotHandleConditions()
{
Assert.IsFalse(doozer.HandleConditions);
}
[Test]
public void TestFrameworkDescriptorTestFrameworkPropertyReturnsMockTestFrameworkObject()
{
Assert.IsTrue(descriptor.TestFramework is MockTestFramework);
}
[Test]
public void TestFrameworkDescriptorTestFrameworkPropertyOnlyCreatesOneObject()
{
ITestFramework testFramework = descriptor.TestFramework;
testFramework = descriptor.TestFramework;
List<string> expectedClassNames = new List<string>();
expectedClassNames.Add("UnitTesting.Tests.Utils.MockTestFramework");
Assert.AreEqual(expectedClassNames, mockTestFrameworkFactory.ClassNamesPassedToCreateMethod);
}
}
}

2
src/AddIns/Analysis/UnitTesting/Test/TestResultsReaderTests.cs → src/AddIns/Analysis/UnitTesting/Test/Frameworks/TestResultsReaderTests.cs

@ -10,7 +10,7 @@ using System.Collections.Generic; @@ -10,7 +10,7 @@ using System.Collections.Generic;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
namespace UnitTesting.Tests
namespace UnitTesting.Tests.Frameworks
{
[TestFixture]
public class TestResultsReaderTests

84
src/AddIns/Analysis/UnitTesting/Test/Frameworks/TestableConditionIsValidForClassNodeTestFixture.cs

@ -0,0 +1,84 @@ @@ -0,0 +1,84 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Gui.ClassBrowser;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests.Frameworks
{
[TestFixture]
public class TestableConditionIsValidForClassNodeTestFixture
{
TestableCondition testableCondition;
MockClass classWithTestAttribute;
ClassNode classNodeForClassWithTestAttribute;
MockRegisteredTestFrameworks testFrameworks;
[TestFixtureSetUp]
public void SetUpFixture()
{
ResourceManager.Initialize();
}
[SetUp]
public void Init()
{
MockAttribute testAttribute = new MockAttribute("Test");
classWithTestAttribute = MockClass.CreateMockClassWithAttribute(testAttribute);
IProject project = classWithTestAttribute.MockProjectContent.ProjectAsIProject;
classNodeForClassWithTestAttribute = new ClassNode(project, classWithTestAttribute);
testFrameworks = new MockRegisteredTestFrameworks();
testFrameworks.AddTestClass(classWithTestAttribute);
testableCondition = new TestableCondition(testFrameworks);
}
[Test]
public void IsValidReturnsTrueForClassWithTestAttribute()
{
Assert.IsTrue(testableCondition.IsValid(classNodeForClassWithTestAttribute, null));
}
[Test]
public void IsValidReturnsFalseForClassWithoutAnyAttributes()
{
MockClass c = MockClass.CreateMockClassWithoutAnyAttributes();
IProject project = c.MockProjectContent.ProjectAsIProject;
ClassNode classNode = new ClassNode(project, c);
Assert.IsFalse(testableCondition.IsValid(classNode, null));
}
[Test]
public void TestClassPassedToRegisteredTestFrameworksIsTestClass()
{
MockClass c = MockClass.CreateMockClassWithoutAnyAttributes();
IProject project = c.MockProjectContent.ProjectAsIProject;
ClassNode classNode = new ClassNode(project, c);
testableCondition.IsValid(classNode, null);
Assert.AreEqual(c, testFrameworks.IsTestClassParameterUsed);
}
/// <summary>
/// When class.ProjectContent.Project == null the
/// TestableCondition.IsValid should return false.
/// </summary>
[Test]
public void IsValidReturnFalseWhenProjectIsNull()
{
classWithTestAttribute.MockProjectContent.Project = null;
Assert.IsFalse(testableCondition.IsValid(classNodeForClassWithTestAttribute, null));
}
}
}

67
src/AddIns/Analysis/UnitTesting/Test/Frameworks/TestableConditionIsValidMethodTestFixture.cs

@ -0,0 +1,67 @@ @@ -0,0 +1,67 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using ICSharpCode.Core;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests.Frameworks
{
[TestFixture]
public class TestableConditionIsValidForMemberNodeTestFixture
{
TestableCondition testableCondition;
MockMethod methodWithTestAttribute;
MockMemberNode memberNodeForMethodWithTestAttribute;
MockRegisteredTestFrameworks testFrameworks;
[TestFixtureSetUp]
public void SetUpFixture()
{
ResourceManager.Initialize();
}
[SetUp]
public void Init()
{
MockAttribute testAttribute = new MockAttribute("Test");
methodWithTestAttribute = MockMethod.CreateMockMethodWithAttribute(testAttribute);
memberNodeForMethodWithTestAttribute = new MockMemberNode(methodWithTestAttribute);
testFrameworks = new MockRegisteredTestFrameworks();
testFrameworks.AddTestMethod(methodWithTestAttribute);
testableCondition = new TestableCondition(testFrameworks);
}
[Test]
public void IsValidReturnsTrueForMethodWithTestAttribute()
{
Assert.IsTrue(testableCondition.IsValid(memberNodeForMethodWithTestAttribute, null));
}
[Test]
public void IsValidReturnsFalseForMethodWithoutAnyAttributes()
{
MockMethod method = MockMethod.CreateMockMethodWithoutAnyAttributes();
MockMemberNode memberNode = new MockMemberNode(method);
Assert.IsFalse(testableCondition.IsValid(memberNode, null));
}
[Test]
public void TestMethodPassedToRegisteredTestFrameworksIsTestMethod()
{
MockMethod method = MockMethod.CreateMockMethodWithoutAnyAttributes();
MockMemberNode memberNode = new MockMemberNode(method);
testableCondition.IsValid(memberNode, null);
Assert.AreEqual(method, testFrameworks.IsTestMethodMemberParameterUsed);
}
}
}

2
src/AddIns/Analysis/UnitTesting/Test/UnitTestingOptionsPanelTestFixture.cs → src/AddIns/Analysis/UnitTesting/Test/Frameworks/UnitTestingOptionsPanelTestFixture.cs

@ -14,7 +14,7 @@ using ICSharpCode.UnitTesting; @@ -14,7 +14,7 @@ using ICSharpCode.UnitTesting;
using NUnit.Framework;
using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests
namespace UnitTesting.Tests.Frameworks
{
/// <summary>
/// Tests the UnitTestingOptionsPanel.

2
src/AddIns/Analysis/UnitTesting/Test/UnitTestingOptionsTestFixture.cs → src/AddIns/Analysis/UnitTesting/Test/Frameworks/UnitTestingOptionsTestFixture.cs

@ -10,7 +10,7 @@ using ICSharpCode.Core; @@ -10,7 +10,7 @@ using ICSharpCode.Core;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
namespace UnitTesting.Tests
namespace UnitTesting.Tests.Frameworks
{
/// <summary>
/// Tests the UnitTestingOptions class.

21
src/AddIns/Analysis/UnitTesting/Test/Project/AbstractBaseClassWithTestMethodsTestFixture.cs

@ -46,32 +46,29 @@ namespace UnitTesting.Tests.Project @@ -46,32 +46,29 @@ namespace UnitTesting.Tests.Project
public void SetUp()
{
MockProjectContent projectContent = new MockProjectContent();
projectContent.Language = LanguageProperties.None;
// Create the base test class.
MockClass baseClass = new MockClass("ICSharpCode.SharpDevelop.Tests.ReflectionOrCecilLayerTests");
baseClass.ProjectContent = projectContent;
MockMethod baseMethod = new MockMethod("InheritanceTests");
MockClass baseClass = new MockClass(projectContent, "ICSharpCode.SharpDevelop.Tests.ReflectionOrCecilLayerTests");
MockMethod baseMethod = new MockMethod(baseClass, "InheritanceTests");
baseMethod.Attributes.Add(new MockAttribute("Test"));
baseMethod.DeclaringType = baseClass;
baseClass.Methods.Add(baseMethod);
// Add a second method that does not have a Test attribute.
baseMethod = new MockMethod("NonTestMethod");
baseMethod.DeclaringType = baseClass;
baseMethod = new MockMethod(baseClass, "NonTestMethod");
baseClass.Methods.Add(baseMethod);
// Create the derived test class.
c = new MockClass("ICSharpCode.SharpDevelop.Tests.CecilLayerTests");
c = new MockClass(projectContent, "ICSharpCode.SharpDevelop.Tests.CecilLayerTests");
c.SetDotNetName(c.FullyQualifiedName);
c.Attributes.Add(new MockAttribute("TestFixture"));
c.ProjectContent = projectContent;
projectContent.Classes.Add(c);
// Set derived class's base class.
c.BaseClass = baseClass;
c.AddBaseClass(baseClass);
// Create TestClass.
testClass = new TestClass(c);
MockTestFrameworksWithNUnitFrameworkSupport testFrameworks = new MockTestFrameworksWithNUnitFrameworkSupport();
testClass = new TestClass(c, testFrameworks);
}
[Test]
@ -106,7 +103,7 @@ namespace UnitTesting.Tests.Project @@ -106,7 +103,7 @@ namespace UnitTesting.Tests.Project
testClasses.Add(testClass);
TestResult testResult = new TestResult("ICSharpCode.SharpDevelop.Tests.CecilLayerTests.InheritanceTests");
testResult.IsFailure = true;
testResult.ResultType = TestResultType.Failure;
testClasses.UpdateTestResult(testResult);
Assert.AreEqual(TestResultType.Failure, testClass.Result);

2
src/AddIns/Analysis/UnitTesting/Test/Project/BaseTestMethodTestFixture.cs

@ -31,7 +31,7 @@ namespace UnitTesting.Tests.Project @@ -31,7 +31,7 @@ namespace UnitTesting.Tests.Project
public void SetUpFixture()
{
mockClass = new MockClass("Tests.MyTestFixture");
mockMethod = new MockMethod("MyMethod");
mockMethod = new MockMethod(mockClass, "MyMethod");
mockMethodRegion = new DomRegion(0, 0, 0, 10);
mockMethod.Region = mockMethodRegion;

17
src/AddIns/Analysis/UnitTesting/Test/Project/ClassRootNamespaceTests.cs

@ -18,12 +18,19 @@ namespace UnitTesting.Tests.Project @@ -18,12 +18,19 @@ namespace UnitTesting.Tests.Project
[TestFixture]
public class ClassRootNamespaceTests
{
MockTestFrameworksWithNUnitFrameworkSupport testFrameworks;
[SetUp]
public void Init()
{
testFrameworks = new MockTestFrameworksWithNUnitFrameworkSupport();
}
[Test]
public void OneParentNamespace()
{
MockClass mockClass = new MockClass("TestRootNamespace.MyFixture");
mockClass.Namespace = "TestRootNamespace";
TestClass testClass = new TestClass(mockClass);
TestClass testClass = new TestClass(mockClass, testFrameworks);
Assert.AreEqual("TestRootNamespace", testClass.RootNamespace);
}
@ -31,8 +38,7 @@ namespace UnitTesting.Tests.Project @@ -31,8 +38,7 @@ namespace UnitTesting.Tests.Project
public void TwoParentNamespaces()
{
MockClass mockClass = new MockClass("TestRootNamespace.Tests.MyFixture");
mockClass.Namespace = "TestRootNamespace.Tests";
TestClass testClass = new TestClass(mockClass);
TestClass testClass = new TestClass(mockClass, testFrameworks);
Assert.AreEqual("TestRootNamespace", testClass.RootNamespace);
}
@ -40,8 +46,7 @@ namespace UnitTesting.Tests.Project @@ -40,8 +46,7 @@ namespace UnitTesting.Tests.Project
public void NoNamespace()
{
MockClass mockClass = new MockClass("MyFixture");
mockClass.Namespace = String.Empty;
TestClass testClass = new TestClass(mockClass);
TestClass testClass = new TestClass(mockClass, testFrameworks);
Assert.AreEqual(String.Empty, testClass.RootNamespace);
}
}

4
src/AddIns/Analysis/UnitTesting/Test/Project/ClassWithTwoChildNamespacesTestFixture.cs

@ -16,12 +16,14 @@ namespace UnitTesting.Tests.Project @@ -16,12 +16,14 @@ namespace UnitTesting.Tests.Project
public class ClassWithTwoChildNamespacesTestsFixture
{
TestClass c;
MockTestFrameworksWithNUnitFrameworkSupport testFrameworks;
[SetUp]
public void Init()
{
testFrameworks = new MockTestFrameworksWithNUnitFrameworkSupport();
MockClass mockClass = new MockClass("UnitTesting.Tests.MyTestFixture");
c = new TestClass(mockClass);
c = new TestClass(mockClass, testFrameworks);
}
[Test]

26
src/AddIns/Analysis/UnitTesting/Test/Project/DuplicateClassNameChangedTestFixture.cs

@ -28,6 +28,7 @@ namespace UnitTesting.Tests.Project @@ -28,6 +28,7 @@ namespace UnitTesting.Tests.Project
TestProject testProject;
IProject project;
MockProjectContent projectContent;
MockTestFrameworksWithNUnitFrameworkSupport testFrameworks;
[SetUp]
public void Init()
@ -41,28 +42,24 @@ namespace UnitTesting.Tests.Project @@ -41,28 +42,24 @@ namespace UnitTesting.Tests.Project
// Add a test class.
projectContent = new MockProjectContent();
projectContent.Language = LanguageProperties.None;
MockClass c = new MockClass("RootNamespace.MyTestFixture");
MockClass c = new MockClass(projectContent, "RootNamespace.MyTestFixture");
c.Attributes.Add(new MockAttribute("TestFixture"));
c.ProjectContent = projectContent;
c.SetCompoundClass(c);
MockMethod test1Method = new MockMethod("Test1");
test1Method .DeclaringType = c;
test1Method .Attributes.Add(new MockAttribute("Test"));
MockMethod test1Method = new MockMethod(c, "Test1");
test1Method.Attributes.Add(new MockAttribute("Test"));
c.Methods.Add(test1Method);
// Test 2 method is from a duplicate test class.
MockMethod test2Method = new MockMethod("Test2");
test2Method.DeclaringType = c;
MockMethod test2Method = new MockMethod(c, "Test2");
test2Method.Attributes.Add(new MockAttribute("Test"));
c.Methods.Add(test2Method);
projectContent.Classes.Add(c);
testProject = new TestProject(project, projectContent);
testFrameworks = new MockTestFrameworksWithNUnitFrameworkSupport();
testProject = new TestProject(project, projectContent, testFrameworks);
// Make sure test methods are created, otherwise
// the Test2 method will never be looked at due to lazy evaluation
// of test method.s
// of test method.
int count = testProject.TestClasses[0].TestMethods.Count;
// Change the name of the second test class.
@ -70,13 +67,10 @@ namespace UnitTesting.Tests.Project @@ -70,13 +67,10 @@ namespace UnitTesting.Tests.Project
oldUnit.Classes.Add(c);
c.Methods.Remove(test2Method); // Remove duplicate test class method.
// Create new compilation unit with inner class that has its method renamed.
DefaultCompilationUnit newUnit = new DefaultCompilationUnit(projectContent);
MockClass newTestClass = new MockClass("RootNamespace.MyNewTestFixture");
newTestClass.ProjectContent = projectContent;
MockClass newTestClass = new MockClass(projectContent, "RootNamespace.MyNewTestFixture");
newTestClass.Attributes.Add(new MockAttribute("TestFixture"));
newTestClass.SetCompoundClass(newTestClass);
projectContent.Classes.Add(newTestClass);
newTestClass.Methods.Add(test2Method);
newUnit.Classes.Add(newTestClass);
@ -104,7 +98,7 @@ namespace UnitTesting.Tests.Project @@ -104,7 +98,7 @@ namespace UnitTesting.Tests.Project
/// <summary>
/// This test ensures that the existing class in the project content is used to update
/// the test methods. So the any methods from the duplicate test class are removed.
/// the test methods. So any methods from the duplicate test class are removed.
/// </summary>
[Test]
public void OldTestClassHasOneMethod()

10
src/AddIns/Analysis/UnitTesting/Test/Project/DuplicateClassNameTestFixture.cs

@ -26,6 +26,7 @@ namespace UnitTesting.Tests.Project @@ -26,6 +26,7 @@ namespace UnitTesting.Tests.Project
TestProject testProject;
IProject project;
MockProjectContent projectContent;
MockTestFrameworksWithNUnitFrameworkSupport testFrameworks;
[SetUp]
public void Init()
@ -40,18 +41,17 @@ namespace UnitTesting.Tests.Project @@ -40,18 +41,17 @@ namespace UnitTesting.Tests.Project
// Add a test class.
projectContent = new MockProjectContent();
projectContent.Language = LanguageProperties.None;
MockClass c = new MockClass("RootNamespace.MyTestFixture");
MockClass c = new MockClass(projectContent, "RootNamespace.MyTestFixture");
c.Attributes.Add(new MockAttribute("TestFixture"));
c.ProjectContent = projectContent;
projectContent.Classes.Add(c);
// Add a second class with the same name.
MockClass secondTestClass = new MockClass("RootNamespace.MyTestFixture");
secondTestClass.ProjectContent = projectContent;
MockClass secondTestClass = new MockClass(projectContent, "RootNamespace.MyTestFixture");
secondTestClass.Attributes.Add(new MockAttribute("TestFixture"));
projectContent.Classes.Add(secondTestClass);
testProject = new TestProject(project, projectContent);
testFrameworks = new MockTestFrameworksWithNUnitFrameworkSupport();
testProject = new TestProject(project, projectContent, testFrameworks);
}
/// <summary>

16
src/AddIns/Analysis/UnitTesting/Test/Project/DuplicateMethodNameTestFixture.cs

@ -23,38 +23,38 @@ namespace UnitTesting.Tests.Project @@ -23,38 +23,38 @@ namespace UnitTesting.Tests.Project
public class DuplicateMethodNameTestFixture
{
TestClass testClass;
MockTestFrameworksWithNUnitFrameworkSupport testFrameworks;
[SetUp]
public void Init()
{
testFrameworks = new MockTestFrameworksWithNUnitFrameworkSupport();
// Add a test class.
MockProjectContent projectContent = new MockProjectContent();
projectContent.Language = LanguageProperties.None;
MockClass c = new MockClass("RootNamespace.MyTestFixture");
MockClass c = new MockClass(projectContent, "RootNamespace.MyTestFixture");
c.Attributes.Add(new MockAttribute("TestFixture"));
c.ProjectContent = projectContent;
projectContent.Classes.Add(c);
// Add first method.
MockMethod method = new MockMethod("MyTest");
MockMethod method = new MockMethod(c, "MyTest");
method.Attributes.Add(new MockAttribute("Test"));
method.DeclaringType = c;
c.Methods.Add(method);
// Add duplicate method.
c.Methods.Add(method);
// Add a base class that has duplicate methods.
MockClass baseClass = new MockClass("RootNamespace.MyTestFixtureBase");
MockClass baseClass = new MockClass(projectContent, "RootNamespace.MyTestFixtureBase");
baseClass.Attributes.Add(new MockAttribute("TestFixture"));
baseClass.ProjectContent = projectContent;
projectContent.Classes.Add(baseClass);
c.BaseClass = baseClass;
c.AddBaseClass(baseClass);
baseClass.Methods.Add(method);
baseClass.Methods.Add(method);
// Create test class.
testClass = new TestClass(c);
testClass = new TestClass(c, testFrameworks);
}
/// <summary>

13
src/AddIns/Analysis/UnitTesting/Test/Project/DuplicateProjectRootNamespaceTestFixture.cs

@ -22,6 +22,7 @@ namespace UnitTesting.Tests.Project @@ -22,6 +22,7 @@ namespace UnitTesting.Tests.Project
public class DuplicateProjectRootNamespaceTestFixture
{
TestProject testProject;
MockTestFrameworksWithNUnitFrameworkSupport testFrameworks;
[SetUp]
public void Init()
@ -36,20 +37,16 @@ namespace UnitTesting.Tests.Project @@ -36,20 +37,16 @@ namespace UnitTesting.Tests.Project
// Add a test class with a TestFixture attributes.
MockProjectContent projectContent = new MockProjectContent();
projectContent.Language = LanguageProperties.None;
MockClass c = new MockClass("RootNamespace.MyTestFixture");
c.Namespace = "RootNamespace";
MockClass c = new MockClass(projectContent, "RootNamespace.MyTestFixture");
c.Attributes.Add(new MockAttribute("TestFixture"));
c.ProjectContent = projectContent;
projectContent.Classes.Add(c);
// Add a second class the same root namespace.
c = new MockClass("RootNamespace.MyTestFixture2");
c.Namespace = "RootNamespace";
c = new MockClass(projectContent, "RootNamespace.MyTestFixture2");
c.Attributes.Add(new MockAttribute("TestFixture"));
c.ProjectContent = projectContent;
projectContent.Classes.Add(c);
testProject = new TestProject(project, projectContent);
testFrameworks = new MockTestFrameworksWithNUnitFrameworkSupport();
testProject = new TestProject(project, projectContent, testFrameworks);
}
[Test]

24
src/AddIns/Analysis/UnitTesting/Test/Project/EmptyProjectTestFixture.cs

@ -22,6 +22,7 @@ namespace UnitTesting.Tests.Project @@ -22,6 +22,7 @@ namespace UnitTesting.Tests.Project
{
TestProject testProject;
MockProjectContent projectContent;
MockTestFrameworksWithNUnitFrameworkSupport testFrameworks;
[SetUp]
public void Init()
@ -36,7 +37,8 @@ namespace UnitTesting.Tests.Project @@ -36,7 +37,8 @@ namespace UnitTesting.Tests.Project
projectContent = new MockProjectContent();
projectContent.Language = LanguageProperties.None;
testProject = new TestProject(project, projectContent);
testFrameworks = new MockTestFrameworksWithNUnitFrameworkSupport();
testProject = new TestProject(project, projectContent, testFrameworks);
}
/// <summary>
@ -48,10 +50,8 @@ namespace UnitTesting.Tests.Project @@ -48,10 +50,8 @@ namespace UnitTesting.Tests.Project
{
// Create new compilation unit with extra class.
DefaultCompilationUnit newUnit = new DefaultCompilationUnit(projectContent);
MockClass newClass = new MockClass("RootNamespace.MyNewTestFixture");
MockClass newClass = new MockClass(projectContent, "RootNamespace.MyNewTestFixture");
newClass.Attributes.Add(new MockAttribute("TestFixture"));
newClass.ProjectContent = projectContent;
newClass.SetCompoundClass(newClass);
newUnit.Classes.Add(newClass);
// Update TestProject's parse info.
@ -71,18 +71,14 @@ namespace UnitTesting.Tests.Project @@ -71,18 +71,14 @@ namespace UnitTesting.Tests.Project
// Create an old compilation unit with the test class
// but without a [TestFixture] attribute.
DefaultCompilationUnit oldUnit = new DefaultCompilationUnit(projectContent);
MockClass newClass = new MockClass("RootNamespace.MyNewTestFixture");
newClass.ProjectContent = projectContent;
newClass.SetCompoundClass(newClass);
MockClass newClass = new MockClass(projectContent, "RootNamespace.MyNewTestFixture");
oldUnit.Classes.Add(newClass);
// Create a new compilation unit with the test class
// having a [TestFixture] attribute.
DefaultCompilationUnit newUnit = new DefaultCompilationUnit(projectContent);
newClass = new MockClass("RootNamespace.MyNewTestFixture");
newClass = new MockClass(projectContent, "RootNamespace.MyNewTestFixture");
newClass.Attributes.Add(new MockAttribute("TestFixture"));
newClass.ProjectContent = projectContent;
newClass.SetCompoundClass(newClass);
newUnit.Classes.Add(newClass);
// Update TestProject's parse info.
@ -106,18 +102,14 @@ namespace UnitTesting.Tests.Project @@ -106,18 +102,14 @@ namespace UnitTesting.Tests.Project
// Create an old compilation unit with the test class
// having a [TestFixture] attribute.
DefaultCompilationUnit oldUnit = new DefaultCompilationUnit(projectContent);
MockClass newClass = new MockClass("RootNamespace.MyNewTestFixture");
MockClass newClass = new MockClass(projectContent, "RootNamespace.MyNewTestFixture");
newClass.Attributes.Add(new MockAttribute("TestFixture"));
newClass.ProjectContent = projectContent;
newClass.SetCompoundClass(newClass);
oldUnit.Classes.Add(newClass);
// Create a new compilation unit with the test class
// but without a [TestFixture] attribute.
DefaultCompilationUnit newUnit = new DefaultCompilationUnit(projectContent);
newClass = new MockClass("RootNamespace.MyNewTestFixture");
newClass.ProjectContent = projectContent;
newClass.SetCompoundClass(newClass);
newClass = new MockClass(projectContent, "RootNamespace.MyNewTestFixture");
newUnit.Classes.Add(newClass);
// Update TestProject's parse info.

12
src/AddIns/Analysis/UnitTesting/Test/Project/EmptyRootNamespaceTestFixture.cs

@ -22,6 +22,7 @@ namespace UnitTesting.Tests.Project @@ -22,6 +22,7 @@ namespace UnitTesting.Tests.Project
public class EmptyRootNamespaceTestFixture
{
TestProject testProject;
MockTestFrameworksWithNUnitFrameworkSupport testFrameworks;
[SetUp]
public void Init()
@ -36,20 +37,17 @@ namespace UnitTesting.Tests.Project @@ -36,20 +37,17 @@ namespace UnitTesting.Tests.Project
// Add a test class with a TestFixture attributes.
MockProjectContent projectContent = new MockProjectContent();
projectContent.Language = LanguageProperties.None;
MockClass c = new MockClass("RootNamespace.MyTestFixture");
c.Namespace = "RootNamespace";
MockClass c = new MockClass(projectContent, "RootNamespace.MyTestFixture");
c.Attributes.Add(new MockAttribute("TestFixture"));
c.ProjectContent = projectContent;
projectContent.Classes.Add(c);
// Add a second class no root namespace.
c = new MockClass("MyTestFixture2");
c.Namespace = String.Empty;
c = new MockClass(projectContent, "MyTestFixture2");
c.Attributes.Add(new MockAttribute("TestFixture"));
c.ProjectContent = projectContent;
projectContent.Classes.Add(c);
testProject = new TestProject(project, projectContent);
testFrameworks = new MockTestFrameworksWithNUnitFrameworkSupport();
testProject = new TestProject(project, projectContent, testFrameworks);
}
[Test]

13
src/AddIns/Analysis/UnitTesting/Test/Project/InnerClassMethodRenamedTestFixture.cs

@ -31,23 +31,18 @@ namespace UnitTesting.Tests.Project @@ -31,23 +31,18 @@ namespace UnitTesting.Tests.Project
// Create new compilation unit with inner class that has its method renamed.
DefaultCompilationUnit newUnit = new DefaultCompilationUnit(projectContent);
MockClass newOuterClass = new MockClass("MyTests.A");
newOuterClass.ProjectContent = projectContent;
MockClass newOuterClass = new MockClass(projectContent, "MyTests.A");
projectContent.Classes.Add(newOuterClass);
newOuterClass.SetCompoundClass(newOuterClass);
newUnit.Classes.Add(newOuterClass);
// Create the inner test class.
MockClass newInnerClass = new MockClass("MyTests.A.InnerATest", "MyTests.A+InnerATest");
MockClass newInnerClass = new MockClass(projectContent, "MyTests.A.InnerATest", outerClass);
newInnerClass.SetDotNetName("MyTests.A+InnerATest");
newInnerClass.Attributes.Add(new MockAttribute("TestFixture"));
newInnerClass.ProjectContent = projectContent;
newInnerClass.DeclaringType = outerClass; // Declaring type is outer class.
newInnerClass.SetCompoundClass(newInnerClass);
newOuterClass.InnerClasses.Add(newInnerClass);
MockMethod method = new MockMethod("FooBarRenamed");
MockMethod method = new MockMethod(newInnerClass, "FooBarRenamed");
method.Attributes.Add(new MockAttribute("Test"));
method.DeclaringType = newInnerClass;
newInnerClass.Methods.Add(method);
outerClass.InnerClasses.Add(newInnerClass);

8
src/AddIns/Analysis/UnitTesting/Test/Project/InnerClassNameChangesTestFixture.cs

@ -30,18 +30,14 @@ namespace UnitTesting.Tests.Project @@ -30,18 +30,14 @@ namespace UnitTesting.Tests.Project
// Create new compilation unit with extra class.
DefaultCompilationUnit newUnit = new DefaultCompilationUnit(projectContent);
MockClass newOuterClass = new MockClass("MyTests.A");
newOuterClass.ProjectContent = projectContent;
MockClass newOuterClass = new MockClass(projectContent, "MyTests.A");
projectContent.Classes.Add(newOuterClass);
newOuterClass.SetCompoundClass(newOuterClass);
newUnit.Classes.Add(newOuterClass);
// Create the inner test class.
// Note the use of the DotNetName "MyTests.A+InnerTest".
MockClass newInnerClass = new MockClass("MyTests.A.InnerATestMod", "MyTests.A+InnerATestMod");
MockClass newInnerClass = new MockClass(projectContent, "MyTests.A.InnerATestMod", "MyTests.A+InnerATestMod", outerClass);
newInnerClass.Attributes.Add(new MockAttribute("TestFixture"));
newInnerClass.ProjectContent = projectContent;
newInnerClass.DeclaringType = outerClass; // Declaring type is outer class.
newOuterClass.InnerClasses.Add(newInnerClass);
// Update TestProject's parse info.

9
src/AddIns/Analysis/UnitTesting/Test/Project/InnerClassTestFixtureAttributeRemovedTestFixture.cs

@ -29,17 +29,12 @@ namespace UnitTesting.Tests.Project @@ -29,17 +29,12 @@ namespace UnitTesting.Tests.Project
// Create new compilation unit with inner class that no longer has the TestFixture attribute.
DefaultCompilationUnit newUnit = new DefaultCompilationUnit(projectContent);
MockClass newOuterClass = new MockClass("MyTests.A");
newOuterClass.ProjectContent = projectContent;
MockClass newOuterClass = new MockClass(projectContent, "MyTests.A");
projectContent.Classes.Add(newOuterClass);
newOuterClass.SetCompoundClass(newOuterClass);
newUnit.Classes.Add(newOuterClass);
// Create the inner test class.
MockClass newInnerClass = new MockClass("MyTests.A.InnerATest", "MyTests.A+InnerATest");
newInnerClass.ProjectContent = projectContent;
newInnerClass.DeclaringType = outerClass; // Declaring type is outer class.
newInnerClass.SetCompoundClass(newInnerClass);
MockClass newInnerClass = new MockClass(projectContent, "MyTests.A.InnerATest", "MyTests.A+InnerATest", outerClass);
newOuterClass.InnerClasses.Add(newInnerClass);
// Update TestProject's parse info.

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save