Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2039 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
103 changed files with 9818 additions and 1114 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,37 +0,0 @@
@@ -1,37 +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.Runtime.Serialization; |
||||
|
||||
namespace ICSharpCode.CodeCoverage |
||||
{ |
||||
/// <summary>
|
||||
/// The exception that is thrown when a non-fatal
|
||||
/// error occurs in the code coverage add-in.
|
||||
/// </summary>
|
||||
[Serializable()] |
||||
public class CodeCoverageException : Exception |
||||
{ |
||||
public CodeCoverageException() |
||||
{ |
||||
} |
||||
|
||||
public CodeCoverageException(string message) |
||||
: base(message) |
||||
{ |
||||
} |
||||
|
||||
public CodeCoverageException(string message, Exception innerException) : base(message, innerException) |
||||
{ |
||||
} |
||||
|
||||
protected CodeCoverageException(SerializationInfo info, StreamingContext context) : base(info, context) |
||||
{ |
||||
} |
||||
} |
||||
} |
@ -1,101 +0,0 @@
@@ -1,101 +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.IO; |
||||
using System.Resources; |
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.UnitTesting; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.CodeCoverage.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class NUnitResultsTestFixture |
||||
{ |
||||
Task errorTask; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
// Add NUnitPad TestFailedMessage string resource since this resource
|
||||
// contains a format string that has parameters that are otherwise not
|
||||
// set.
|
||||
ResourceManager resourceManager = new ResourceManager("ICSharpCode.CodeCoverage.Tests.Strings", GetType().Assembly); |
||||
ResourceService.RegisterNeutralStrings(resourceManager); |
||||
|
||||
NUnitResults results = new NUnitResults(new StringReader(GetNUnitResultsXml())); |
||||
errorTask = results.Tasks[0]; |
||||
} |
||||
|
||||
[Test] |
||||
public void IsErrorTask() |
||||
{ |
||||
Assert.AreEqual(TaskType.Error, errorTask.TaskType); |
||||
} |
||||
|
||||
[Test] |
||||
public void ErrorTaskFileName() |
||||
{ |
||||
Assert.IsTrue(FileUtility.IsEqualFileName(@"c:\test\NunitFoo\NunitFoo.Tests\FooTest.cs", errorTask.FileName)); |
||||
} |
||||
|
||||
[Test] |
||||
public void ErrorTaskLine() |
||||
{ |
||||
Assert.AreEqual(21, errorTask.Line); |
||||
} |
||||
|
||||
[Test] |
||||
public void ErrorTaskColumn() |
||||
{ |
||||
Assert.AreEqual(0, errorTask.Column); |
||||
} |
||||
|
||||
[Test] |
||||
public void TaskDescription() |
||||
{ |
||||
string description = StringParser.Parse("${res:NUnitPad.NUnitPadContent.TestTreeView.TestFailedMessage}", new string[,] { |
||||
{"TestCase", "NunitFoo.Tests.FooTest.Foo"}, |
||||
{"Message", "Foo failed"} |
||||
}); |
||||
|
||||
Assert.AreEqual(description, errorTask.Description); |
||||
} |
||||
|
||||
string GetNUnitResultsXml() |
||||
{ |
||||
return "<test-results name=\"C:\\test\\NunitFoo\\NunitFoo.Tests\\bin\\Debug\\NunitFoo.Tests.dll\" total=\"2\" failures=\"1\" not-run=\"0\" date=\"2006-01-31\" time=\"01:18:33\">\r\n" + |
||||
" <test-suite name=\"C:\\test\\NunitFoo\\NunitFoo.Tests\\bin\\Debug\\NunitFoo.Tests.dll\" success=\"False\" time=\"0.040\" asserts=\"0\">\r\n" + |
||||
" <results>\r\n" + |
||||
" <test-suite name=\"NunitFoo\" success=\"False\" time=\"0.040\" asserts=\"0\">\r\n" + |
||||
" <results>\r\n" + |
||||
" <test-suite name=\"Tests\" success=\"False\" time=\"0.040\" asserts=\"0\">\r\n" + |
||||
" <results>\r\n" + |
||||
" <test-suite name=\"FooTest\" success=\"False\" time=\"0.030\" asserts=\"0\">\r\n" + |
||||
" <results>\r\n" + |
||||
" <test-case name=\"NunitFoo.Tests.FooTest.Foo\" executed=\"True\" success=\"False\" time=\"0.010\" asserts=\"0\">\r\n" + |
||||
" <failure>\r\n" + |
||||
" <message><![CDATA[Foo failed]]></message>\r\n" + |
||||
" <stack-trace><![CDATA[ at NunitFoo.Tests.FooTest.Foo() in c:\\test\\NunitFoo\\NunitFoo.Tests\\FooTest.cs:line 22\r\n" + |
||||
"]]></stack-trace>\r\n" + |
||||
" </failure>\r\n" + |
||||
" </test-case>\r\n" + |
||||
" </results>\r\n" + |
||||
" </test-suite>\r\n" + |
||||
" </results>\r\n" + |
||||
" </test-suite>\r\n" + |
||||
" </results>\r\n" + |
||||
" </test-suite>\r\n" + |
||||
" </results>\r\n" + |
||||
" </test-suite>\r\n" + |
||||
"</test-results>"; |
||||
} |
||||
} |
||||
} |
After Width: | Height: | Size: 440 B |
After Width: | Height: | Size: 497 B |
After Width: | Height: | Size: 445 B |
After Width: | Height: | Size: 499 B |
@ -0,0 +1,32 @@
@@ -0,0 +1,32 @@
|
||||
// <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 System; |
||||
|
||||
namespace ICSharpCode.UnitTesting |
||||
{ |
||||
public interface ITestTreeView |
||||
{ |
||||
/// <summary>
|
||||
/// Gets the selected method in the test tree view.
|
||||
/// </summary>
|
||||
IMember SelectedMethod {get;} |
||||
|
||||
/// <summary>
|
||||
/// Gets the selected class in the test tree view.
|
||||
/// </summary>
|
||||
IClass SelectedClass {get;} |
||||
|
||||
/// <summary>
|
||||
/// Gets the selected project for the selected node
|
||||
/// in the test tree view.
|
||||
/// </summary>
|
||||
IProject SelectedProject {get;} |
||||
} |
||||
} |
@ -1,102 +0,0 @@
@@ -1,102 +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.IO; |
||||
using System.Xml; |
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop; |
||||
|
||||
namespace ICSharpCode.UnitTesting |
||||
{ |
||||
/// <summary>
|
||||
/// Reads the NUnit results file.
|
||||
/// </summary>
|
||||
public class NUnitResults |
||||
{ |
||||
static readonly string TestCaseElementName = "test-case"; |
||||
static readonly string MessageElementName = "message"; |
||||
static readonly string StackTraceElementName= "stack-trace"; |
||||
|
||||
readonly List<Task> tasks = new List<Task>(); |
||||
|
||||
public List<Task> Tasks { |
||||
get { |
||||
return tasks; |
||||
} |
||||
} |
||||
|
||||
public NUnitResults(string fileName) : this(new StreamReader(fileName, true)) |
||||
{ |
||||
} |
||||
|
||||
public NUnitResults(TextReader reader) : this(new XmlTextReader(reader)) |
||||
{ |
||||
} |
||||
|
||||
public NUnitResults(XmlReader reader) |
||||
{ |
||||
using (reader) { |
||||
ReadResults(reader); |
||||
} |
||||
} |
||||
|
||||
void ReadResults(XmlReader reader) |
||||
{ |
||||
while (reader.Read()) { |
||||
if (reader.NodeType == XmlNodeType.Element) { |
||||
if (reader.Name == TestCaseElementName) { |
||||
if (bool.Parse(reader.GetAttribute("executed")) == false) { |
||||
// test was ignored.
|
||||
AddTest(reader, TaskType.Warning, "${res:NUnitPad.NUnitPadContent.TestTreeView.TestNotExecutedMessage}"); |
||||
} else if (bool.Parse(reader.GetAttribute("success")) == false) { |
||||
// test failed.
|
||||
AddTest(reader, TaskType.Error, "${res:NUnitPad.NUnitPadContent.TestTreeView.TestFailedMessage}"); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
void AddTest(XmlReader reader, TaskType type, string message) |
||||
{ |
||||
string testName = reader.GetAttribute("name"); |
||||
string msg, stackTrace; |
||||
GetDescription(reader, out msg, out stackTrace); |
||||
|
||||
message = StringParser.Parse(message, new string[,] { |
||||
{"TestCase", testName}, |
||||
{"Message", msg} |
||||
}); |
||||
Task task = TestTreeView.CreateTask(type, message, testName, stackTrace); |
||||
if (task != null) { |
||||
tasks.Add(task); |
||||
} |
||||
} |
||||
|
||||
void GetDescription(XmlReader reader, out string message, out string stackTrace) |
||||
{ |
||||
message = ""; |
||||
stackTrace = ""; |
||||
while (reader.Read()) { |
||||
if (reader.NodeType == XmlNodeType.Element) { |
||||
if (reader.Name == MessageElementName) { |
||||
message = reader.ReadElementString(); |
||||
} else if (reader.Name == StackTraceElementName) { |
||||
stackTrace = reader.ReadElementString(); |
||||
} |
||||
} else if (reader.NodeType == XmlNodeType.EndElement) { |
||||
if (reader.Name == TestCaseElementName) { |
||||
return; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,216 +0,0 @@
@@ -1,216 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Windows.Forms; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
|
||||
namespace ICSharpCode.UnitTesting |
||||
{ |
||||
public class PadContent : AbstractPadContent |
||||
{ |
||||
public static PadContent Instance { |
||||
get { |
||||
PadDescriptor descriptor = WorkbenchSingleton.Workbench.GetPad(typeof(PadContent)); |
||||
return (PadContent)descriptor.PadContent; |
||||
} |
||||
} |
||||
|
||||
public static void BringToFront() |
||||
{ |
||||
WorkbenchSingleton.Workbench.GetPad(typeof(PadContent)).BringPadToFront(); |
||||
} |
||||
|
||||
TestTreeView treeView; |
||||
ToolStrip toolStrip; |
||||
Control ctl; |
||||
|
||||
public TestTreeView TreeView { |
||||
get { |
||||
return treeView; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Creates a new TestPad object
|
||||
/// </summary>
|
||||
public PadContent() |
||||
{ |
||||
ctl = new Panel(); |
||||
treeView = new TestTreeView(); |
||||
treeView.Dock = DockStyle.Fill; |
||||
treeView.RunStarted += ThreadedUpdateToolbar; |
||||
treeView.RunFinished += ThreadedUpdateToolbar; |
||||
treeView.RunFinished += delegate { |
||||
WorkbenchSingleton.SafeThreadAsyncCall(ShowErrorList); |
||||
}; |
||||
|
||||
ctl.Controls.Add(treeView); |
||||
toolStrip = ToolbarService.CreateToolStrip(this, "/SharpDevelop/Pads/UnitTestingPad/Toolbar"); |
||||
toolStrip.GripStyle = ToolStripGripStyle.Hidden; |
||||
ctl.Controls.Add(toolStrip); |
||||
|
||||
ProjectService.SolutionLoaded += OnSolutionLoaded; |
||||
ProjectService.SolutionClosed += OnSolutionClosed; |
||||
ProjectService.EndBuild += OnEndBuild; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Cleans up all used resources
|
||||
/// </summary>
|
||||
public override void Dispose() |
||||
{ |
||||
ProjectService.SolutionLoaded -= OnSolutionLoaded; |
||||
ProjectService.SolutionClosed -= OnSolutionClosed; |
||||
ProjectService.EndBuild -= OnEndBuild; |
||||
ctl.Dispose(); |
||||
} |
||||
|
||||
void OnSolutionLoaded(object sender, EventArgs e) |
||||
{ |
||||
UpdateToolbar(); |
||||
} |
||||
|
||||
void OnSolutionClosed(object sender, EventArgs e) |
||||
{ |
||||
treeView.UnloadTestAssemblies(); |
||||
UpdateToolbar(); |
||||
} |
||||
|
||||
void OnEndBuild(object sender, EventArgs e) |
||||
{ |
||||
if (autoLoadItems) { |
||||
ReloadAssemblyList(null); |
||||
} |
||||
} |
||||
|
||||
bool autoLoadItems; |
||||
|
||||
public void RunTests() |
||||
{ |
||||
LoadAssemblyList(treeView.RunTests); |
||||
} |
||||
|
||||
public void UnloadTests() |
||||
{ |
||||
autoLoadItems = false; |
||||
treeView.UnloadTestAssemblies(); |
||||
UpdateToolbar(); |
||||
} |
||||
|
||||
public bool IsRunningTests { |
||||
get { |
||||
return treeView.IsTestRunning; |
||||
} |
||||
} |
||||
|
||||
public void StopTests() |
||||
{ |
||||
treeView.StopTests(); |
||||
UpdateToolbar(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Loads the assemblies if they are not already loaded.
|
||||
/// </summary>
|
||||
public void LoadAssemblyList(Action callback) |
||||
{ |
||||
if (autoLoadItems) { |
||||
if (callback != null) |
||||
WorkbenchSingleton.SafeThreadAsyncCall(callback); |
||||
} else { |
||||
ReloadAssemblyList(callback); |
||||
} |
||||
} |
||||
|
||||
public void ReloadAssemblyList(Action callback) |
||||
{ |
||||
autoLoadItems = true; |
||||
treeView.UnloadTestAssemblies(); |
||||
|
||||
treeView.StartAddingAssemblies(); |
||||
foreach (IProject project in ProjectService.OpenSolution.Projects) { |
||||
bool referenceFound = false; |
||||
foreach (ProjectItem item in project.Items) { |
||||
ReferenceProjectItem reference = item as ReferenceProjectItem; |
||||
if (reference != null) { |
||||
string include = reference.Include; |
||||
if (reference is ProjectReferenceProjectItem) { |
||||
include = ((ProjectReferenceProjectItem)reference).ProjectName; |
||||
} |
||||
if (include.IndexOf(',') > 0) { |
||||
include = include.Substring(0, include.IndexOf(',')); |
||||
} |
||||
if (include.Length > 5) { |
||||
if (include.Substring(include.Length - 4).Equals(".dll", StringComparison.OrdinalIgnoreCase)) |
||||
include = include.Substring(0, include.Length - 4); |
||||
} |
||||
if (string.Equals(include, "nunit.framework", StringComparison.OrdinalIgnoreCase)) |
||||
//|| string.Equals(include, "mbunit.framework", StringComparison.OrdinalIgnoreCase))
|
||||
{ |
||||
referenceFound = true; |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
if (referenceFound) { |
||||
string outputAssembly = project.OutputAssemblyFullPath; |
||||
LoggingService.Debug("UnitTestingPad: Load " + outputAssembly); |
||||
treeView.AddAssembly(project, outputAssembly); |
||||
} |
||||
} |
||||
treeView.FinishAddingAssemblies(); |
||||
if (callback != null) |
||||
WorkbenchSingleton.SafeThreadAsyncCall(callback); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// The <see cref="System.Windows.Forms.Control"/> representing the pad
|
||||
/// </summary>
|
||||
public override Control Control { |
||||
get { |
||||
return ctl; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Refreshes the pad
|
||||
/// </summary>
|
||||
public override void RedrawContent() |
||||
{ |
||||
} |
||||
|
||||
void ThreadedUpdateToolbar(object sender, EventArgs e) |
||||
{ |
||||
WorkbenchSingleton.SafeThreadAsyncCall(UpdateToolbar); |
||||
} |
||||
|
||||
void UpdateToolbar() |
||||
{ |
||||
ToolbarService.UpdateToolbar(toolStrip); |
||||
} |
||||
|
||||
void ShowErrorList() |
||||
{ |
||||
if (TaskService.SomethingWentWrong && ErrorListPad.ShowAfterBuild) { |
||||
WorkbenchSingleton.Workbench.GetPad(typeof(ErrorListPad)).BringPadToFront(); |
||||
} |
||||
} |
||||
|
||||
public void RunTest(IProject project, IClass fixture, IMember test) |
||||
{ |
||||
LoadAssemblyList(delegate { |
||||
treeView.SelectTest(project, fixture, test); |
||||
treeView.RunTests(); |
||||
}); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,48 @@
@@ -0,0 +1,48 @@
|
||||
// <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 TestAttributeName |
||||
{ |
||||
string name = String.Empty; |
||||
string qualifiedName = String.Empty; |
||||
string fullyQualifiedName = String.Empty; |
||||
StringComparer nameComparer; |
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the 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) |
||||
{ |
||||
this.name = name; |
||||
this.nameComparer = nameComparer; |
||||
qualifiedName = String.Concat(name, "Attribute"); |
||||
fullyQualifiedName = String.Concat("NUnit.Framework.", name, "Attribute"); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified attribute name is a
|
||||
/// match to this attribute.
|
||||
/// </summary>
|
||||
public bool IsEqual(string attributeName) |
||||
{ |
||||
if (nameComparer.Equals(attributeName, name) || |
||||
nameComparer.Equals(attributeName, qualifiedName) || |
||||
nameComparer.Equals(attributeName, fullyQualifiedName)) { |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,427 @@
@@ -0,0 +1,427 @@
|
||||
// <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; |
||||
|
||||
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.
|
||||
/// </summary>
|
||||
public class TestClass |
||||
{ |
||||
IClass c; |
||||
TestMethodCollection testMethods; |
||||
TestResultType testResultType; |
||||
|
||||
/// <summary>
|
||||
/// Raised when the test class result is changed.
|
||||
/// </summary>
|
||||
public event EventHandler ResultChanged; |
||||
|
||||
public TestClass(IClass c) |
||||
{ |
||||
this.c = c; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the underlying IClass for this test class.
|
||||
/// </summary>
|
||||
public IClass Class { |
||||
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.Name)) { |
||||
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>
|
||||
public static TestClass[] GetTestClasses(ICollection<TestClass> classes, string ns) |
||||
{ |
||||
List<TestClass> matchedClasses = new List<TestClass>(); |
||||
foreach (TestClass c in classes) { |
||||
if (c.Namespace == ns) { |
||||
matchedClasses.Add(c); |
||||
} |
||||
} |
||||
return matchedClasses.ToArray(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the test classes that namespaces starts with the specified
|
||||
/// string.
|
||||
/// </summary>
|
||||
public static TestClass[] GetAllTestClasses(ICollection<TestClass> classes, string namespaceStartsWith) |
||||
{ |
||||
List<TestClass> matchedClasses = new List<TestClass>(); |
||||
foreach (TestClass c in classes) { |
||||
if (c.Namespace.StartsWith(namespaceStartsWith)) { |
||||
matchedClasses.Add(c); |
||||
} |
||||
} |
||||
return matchedClasses.ToArray(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets all child namespaces that starts with the specified string.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If the starts with string is 'ICSharpCode' and there is a code coverage
|
||||
/// method with a namespace of 'ICSharpCode.XmlEditor.Tests', then this
|
||||
/// method will return 'XmlEditor' as one of its strings.
|
||||
/// </remarks>
|
||||
public static string[] GetChildNamespaces(ICollection<TestClass> classes, string parentNamespace) { |
||||
List<string> items = new List<string>(); |
||||
foreach (TestClass c in classes) { |
||||
string ns = c.GetChildNamespace(parentNamespace); |
||||
if (ns.Length > 0) { |
||||
if (!items.Contains(ns)) { |
||||
items.Add(ns); |
||||
} |
||||
} |
||||
} |
||||
return items.ToArray(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the class.
|
||||
/// </summary>
|
||||
public string Name { |
||||
get { |
||||
return c.Name; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the fully qualified name of the class.
|
||||
/// </summary>
|
||||
public string QualifiedName { |
||||
get { |
||||
return c.FullyQualifiedName; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the namespace of this class.
|
||||
/// </summary>
|
||||
public string Namespace { |
||||
get { |
||||
return c.Namespace; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the root namespace for this class.
|
||||
/// </summary>
|
||||
public string RootNamespace { |
||||
get { |
||||
return GetRootNamespace(c.Namespace); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the test result for this class.
|
||||
/// </summary>
|
||||
public TestResultType Result { |
||||
get { |
||||
return testResultType; |
||||
} |
||||
set { |
||||
TestResultType previousTestResultType = testResultType; |
||||
testResultType = value; |
||||
if (previousTestResultType != testResultType) { |
||||
OnResultChanged(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the child namespace from the specified namespace
|
||||
/// based on the parent namespace.
|
||||
/// </summary>
|
||||
/// <param name="parentNamespace">Can contain multiple namespaces
|
||||
/// (e.g. ICSharpCode.XmlEditor).</param>
|
||||
public static string GetChildNamespace(string ns, string parentNamespace) |
||||
{ |
||||
if (parentNamespace.Length > 0) { |
||||
if (ns.StartsWith(String.Concat(parentNamespace, "."))) { |
||||
string end = ns.Substring(parentNamespace.Length + 1); |
||||
return GetRootNamespace(end); |
||||
} |
||||
return String.Empty; |
||||
} |
||||
return ns; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the child namespace based on the parent namespace
|
||||
/// from this class.
|
||||
/// </summary>
|
||||
/// <param name="parentNamespace">Can contain multiple namespaces
|
||||
/// (e.g. ICSharpCode.XmlEditor).</param>
|
||||
public string GetChildNamespace(string parentNamespace) |
||||
{ |
||||
return GetChildNamespace(Namespace, parentNamespace); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the test methods in this class.
|
||||
/// </summary>
|
||||
public TestMethodCollection TestMethods { |
||||
get { |
||||
if (testMethods == null) { |
||||
GetTestMethods(); |
||||
} |
||||
return testMethods; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the test method with the specified name.
|
||||
/// </summary>
|
||||
/// <returns>Null if the method cannot be found.</returns>
|
||||
public TestMethod GetTestMethod(string name) |
||||
{ |
||||
if (TestMethods.Contains(name)) { |
||||
return TestMethods[name]; |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Updates the test method with the specified test result.
|
||||
/// </summary>
|
||||
public void UpdateTestResult(TestResult testResult) |
||||
{ |
||||
TestMethod method = null; |
||||
string methodName = TestMethod.GetMethodName(testResult.Name); |
||||
if (methodName != null) { |
||||
method = GetTestMethod(methodName); |
||||
if (method == null) { |
||||
method = GetPrefixedTestMethod(testResult.Name); |
||||
} |
||||
} |
||||
if (method != null) { |
||||
method.Result = testResult.ResultType; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Resets all the test results back to none.
|
||||
/// </summary>
|
||||
public void ResetTestResults() |
||||
{ |
||||
Result = TestResultType.None; |
||||
TestMethods.ResetTestResults(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Updates the methods and class based on the new class
|
||||
/// information that has been parsed.
|
||||
/// </summary>
|
||||
public void UpdateClass(IClass c) |
||||
{ |
||||
this.c = c.GetCompoundClass(); |
||||
|
||||
// Remove missing methods.
|
||||
TestMethodCollection newTestMethods = GetTestMethods(this.c); |
||||
TestMethodCollection existingTestMethods = TestMethods; |
||||
for (int i = existingTestMethods.Count - 1; i >= 0; --i) { |
||||
TestMethod method = existingTestMethods[i]; |
||||
if (!newTestMethods.Contains(method.Name)) { |
||||
existingTestMethods.RemoveAt(i); |
||||
} |
||||
} |
||||
|
||||
// Add new methods.
|
||||
foreach (TestMethod method in newTestMethods) { |
||||
if (existingTestMethods.Contains(method.Name)) { |
||||
} else { |
||||
existingTestMethods.Add(method); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the first dotted part of the namespace.
|
||||
/// </summary>
|
||||
static string GetRootNamespace(string ns) |
||||
{ |
||||
int index = ns.IndexOf('.'); |
||||
if (index > 0) { |
||||
return ns.Substring(0, index); |
||||
} |
||||
return ns; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the test methods for the class.
|
||||
/// </summary>
|
||||
void GetTestMethods() |
||||
{ |
||||
testMethods = GetTestMethods(c); |
||||
testMethods.ResultChanged += TestMethodsResultChanged; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the test methods for the specified class.
|
||||
/// </summary>
|
||||
static TestMethodCollection GetTestMethods(IClass c) |
||||
{ |
||||
TestMethodCollection testMethods = new TestMethodCollection(); |
||||
foreach (IMethod method in c.Methods) { |
||||
if (TestMethod.IsTestMethod(method)) { |
||||
if (!testMethods.Contains(method.Name)) { |
||||
testMethods.Add(new TestMethod(method)); |
||||
} |
||||
} |
||||
} |
||||
|
||||
// Add base class test methods.
|
||||
if (c.BaseClass != null) { |
||||
foreach (IMethod method in c.BaseClass.Methods) { |
||||
if (TestMethod.IsTestMethod(method)) { |
||||
TestMethod testMethod = new TestMethod(c.BaseClass.Name, method); |
||||
if (!testMethods.Contains(testMethod.Name)) { |
||||
testMethods.Add(testMethod); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
return testMethods; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Updates the test class's test result after the test method's
|
||||
/// test result has changed.
|
||||
/// </summary>
|
||||
void TestMethodsResultChanged(object source, EventArgs e) |
||||
{ |
||||
Result = testMethods.Result; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Raises the ResultChanged event.
|
||||
/// </summary>
|
||||
void OnResultChanged() |
||||
{ |
||||
if (ResultChanged != null) { |
||||
ResultChanged(this, new EventArgs()); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Updates the result of this class based on the results of
|
||||
/// its methods.
|
||||
/// </summary>
|
||||
void UpdateResult() |
||||
{ |
||||
bool failure = false; |
||||
bool ignored = false; |
||||
bool notRun = false; |
||||
foreach (TestMethod method in TestMethods) { |
||||
switch (method.Result) { |
||||
case TestResultType.None: |
||||
notRun = true; |
||||
break; |
||||
case TestResultType.Failure: |
||||
failure = true; |
||||
break; |
||||
case TestResultType.Ignored: |
||||
ignored = true; |
||||
break; |
||||
} |
||||
if (failure) { |
||||
break; |
||||
} |
||||
} |
||||
if (failure) { |
||||
Result = TestResultType.Failure; |
||||
} else if (ignored) { |
||||
Result = TestResultType.Ignored; |
||||
} else if (!notRun) { |
||||
Result = TestResultType.Success; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// First tries the last dotted part of the test result name as the
|
||||
/// method name. If there is no matching method the preceding dotted
|
||||
/// part is prefixed to the method name until a match is found.
|
||||
///
|
||||
/// Given a test result of:
|
||||
///
|
||||
/// RootNamespace.ClassName.BaseClass1.BaseClass2.TestMethod
|
||||
///
|
||||
/// The method names tried are:
|
||||
///
|
||||
/// TestMethod
|
||||
/// BaseClass2.TestMethod
|
||||
/// BaseClass2.BaseClass1.TestMethod
|
||||
/// etc.
|
||||
/// </summary>
|
||||
TestMethod GetPrefixedTestMethod(string testResultName) |
||||
{ |
||||
int index = 0; |
||||
string methodName = TestMethod.GetMethodName(testResultName); |
||||
string className = TestMethod.GetQualifiedClassName(testResultName); |
||||
do { |
||||
index = className.LastIndexOf('.'); |
||||
if (index > 0) { |
||||
methodName = String.Concat(className.Substring(index + 1), ".", methodName); |
||||
TestMethod method = GetTestMethod(methodName); |
||||
if (method != null) { |
||||
return method; |
||||
} |
||||
className = className.Substring(0, index); |
||||
} |
||||
} while (index > 0); |
||||
return null; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,218 @@
@@ -0,0 +1,218 @@
|
||||
// <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.Collections.ObjectModel; |
||||
using ICSharpCode.Core; |
||||
|
||||
namespace ICSharpCode.UnitTesting |
||||
{ |
||||
public class TestClassCollection : KeyedCollection<string, TestClass> |
||||
{ |
||||
TestResultType testResult = TestResultType.None; |
||||
|
||||
Dictionary<string, TestClass> passedTestClasses = new Dictionary<string, TestClass>(); |
||||
Dictionary<string, TestClass> failedTestClasses = new Dictionary<string, TestClass>(); |
||||
Dictionary<string, TestClass> ignoredTestClasses = new Dictionary<string, TestClass>(); |
||||
|
||||
/// <summary>
|
||||
/// Raised when the test result for this collection of
|
||||
/// classes has changed.
|
||||
/// </summary>
|
||||
public event EventHandler ResultChanged; |
||||
|
||||
/// <summary>
|
||||
/// Raised when a class is added to this collection.
|
||||
/// </summary>
|
||||
public event TestClassEventHandler TestClassAdded; |
||||
|
||||
/// <summary>
|
||||
/// Raised when a class is removed from this collection.
|
||||
/// </summary>
|
||||
public event TestClassEventHandler TestClassRemoved; |
||||
|
||||
/// <summary>
|
||||
/// Gets the overall test results for the collection of
|
||||
/// test classes.
|
||||
/// </summary>
|
||||
public TestResultType Result { |
||||
get { |
||||
return testResult; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Sets all the test class test results back to none.
|
||||
/// </summary>
|
||||
public void ResetTestResults() |
||||
{ |
||||
passedTestClasses.Clear(); |
||||
failedTestClasses.Clear(); |
||||
ignoredTestClasses.Clear(); |
||||
|
||||
foreach (TestClass c in this) { |
||||
c.ResetTestResults(); |
||||
} |
||||
|
||||
SetTestResult(TestResultType.None); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Updates the test method with the specified test result.
|
||||
/// </summary>
|
||||
public void UpdateTestResult(TestResult testResult) |
||||
{ |
||||
TestClass testClass = GetTestClassFromTestMethodName(testResult.Name); |
||||
if (testClass != null) { |
||||
testClass.UpdateTestResult(testResult); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the matching test method from this set of classes.
|
||||
/// </summary>
|
||||
/// <param name="fullyQualifiedName">The fully qualified
|
||||
/// method name (e.g. Namespace.ClassName.MethodName).</param>
|
||||
/// <returns>Null if the method cannot be found.</returns>
|
||||
public TestMethod GetTestMethod(string fullyQualifiedName) |
||||
{ |
||||
string className = TestMethod.GetQualifiedClassName(fullyQualifiedName); |
||||
if (className != null) { |
||||
if (Contains(className)) { |
||||
TestClass testClass = this[className]; |
||||
string methodName = TestMethod.GetMethodName(fullyQualifiedName); |
||||
if (methodName != null) { |
||||
return testClass.GetTestMethod(methodName); |
||||
} |
||||
} else { |
||||
LoggingService.Debug("TestClass not found: " + className); |
||||
} |
||||
} else { |
||||
LoggingService.Debug("Invalid test method name: " + fullyQualifiedName); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
protected override string GetKeyForItem(TestClass item) |
||||
{ |
||||
return item.Class.FullyQualifiedName; |
||||
} |
||||
|
||||
protected override void InsertItem(int index, TestClass item) |
||||
{ |
||||
item.ResultChanged += TestClassResultChanged; |
||||
base.InsertItem(index, item); |
||||
TestClassResultChanged(item, new EventArgs()); |
||||
OnTestClassAdded(item); |
||||
} |
||||
|
||||
protected override void RemoveItem(int index) |
||||
{ |
||||
TestClass c = this[index]; |
||||
c.ResultChanged -= TestClassResultChanged; |
||||
base.RemoveItem(index); |
||||
OnTestResultNone(c.Name); |
||||
OnTestClassRemoved(c); |
||||
} |
||||
|
||||
protected void OnTestClassAdded(TestClass testClass) |
||||
{ |
||||
if (TestClassAdded != null) { |
||||
TestClassAdded(this, new TestClassEventArgs(testClass)); |
||||
} |
||||
} |
||||
|
||||
protected void OnTestClassRemoved(TestClass testClass) |
||||
{ |
||||
if (TestClassRemoved != null) { |
||||
TestClassRemoved(this, new TestClassEventArgs(testClass)); |
||||
} |
||||
} |
||||
|
||||
void TestClassResultChanged(object source, EventArgs e) |
||||
{ |
||||
TestClass c = (TestClass)source; |
||||
switch (c.Result) { |
||||
case TestResultType.None: |
||||
OnTestResultNone(c.QualifiedName); |
||||
break; |
||||
case TestResultType.Failure: |
||||
SetTestResult(TestResultType.Failure); |
||||
failedTestClasses.Add(c.QualifiedName, c); |
||||
break; |
||||
case TestResultType.Success: |
||||
passedTestClasses.Add(c.QualifiedName, c); |
||||
if (passedTestClasses.Count == Count) { |
||||
SetTestResult(TestResultType.Success); |
||||
} else if (passedTestClasses.Count + ignoredTestClasses.Count == Count) { |
||||
SetTestResult(TestResultType.Ignored); |
||||
} |
||||
break; |
||||
case TestResultType.Ignored: |
||||
ignoredTestClasses.Add(c.QualifiedName, c); |
||||
if (ignoredTestClasses.Count == Count || |
||||
ignoredTestClasses.Count + passedTestClasses.Count == Count) { |
||||
SetTestResult(TestResultType.Ignored); |
||||
} |
||||
break; |
||||
} |
||||
} |
||||
|
||||
void SetTestResult(TestResultType value) |
||||
{ |
||||
TestResultType previousTestResult = testResult; |
||||
testResult = value; |
||||
if (testResult != previousTestResult) { |
||||
OnResultChanged(); |
||||
} |
||||
} |
||||
|
||||
void OnResultChanged() |
||||
{ |
||||
if (ResultChanged != null) { |
||||
ResultChanged(this, new EventArgs()); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Removes the specified test class from the list of
|
||||
/// failed, passed and ignored tests and updates the
|
||||
/// test result state of the test class collection.
|
||||
/// </summary>
|
||||
void OnTestResultNone(string qualifiedName) |
||||
{ |
||||
passedTestClasses.Remove(qualifiedName); |
||||
failedTestClasses.Remove(qualifiedName); |
||||
ignoredTestClasses.Remove(qualifiedName); |
||||
if (ignoredTestClasses.Count + failedTestClasses.Count == 0) { |
||||
SetTestResult(TestResultType.None); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the test class from the specified test result.
|
||||
/// </summary>
|
||||
TestClass GetTestClassFromTestMethodName(string methodName) |
||||
{ |
||||
if (methodName != null) { |
||||
string className = TestMethod.GetQualifiedClassName(methodName); |
||||
if (className != null) { |
||||
if (Contains(className)) { |
||||
return this[className]; |
||||
} else { |
||||
LoggingService.Debug("TestClass not found: " + className); |
||||
return GetTestClassFromTestMethodName(className); |
||||
} |
||||
} else { |
||||
LoggingService.Debug("Invalid TestMethod.Name: " + methodName); |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
// <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 |
||||
{ |
||||
/// <summary>
|
||||
/// Represents the method that will handle the TestCollection's
|
||||
/// TestClassAdded or TestClassRemoved events.
|
||||
/// </summary>
|
||||
public delegate void TestClassEventHandler(object source, TestClassEventArgs e); |
||||
|
||||
/// <summary>
|
||||
/// Provides data for the TestCollection's TestClassAdded and TestClassRemoved events.
|
||||
/// </summary>
|
||||
public class TestClassEventArgs |
||||
{ |
||||
TestClass testClass; |
||||
|
||||
public TestClassEventArgs(TestClass testClass) |
||||
{ |
||||
this.testClass = testClass; |
||||
} |
||||
|
||||
public TestClass TestClass { |
||||
get { |
||||
return testClass; |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,103 @@
@@ -0,0 +1,103 @@
|
||||
// <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.Gui; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
|
||||
namespace ICSharpCode.UnitTesting |
||||
{ |
||||
/// <summary>
|
||||
/// Represents a class that has the [TestFixture] attribute
|
||||
/// associated with it.
|
||||
/// </summary>
|
||||
public class TestClassTreeNode : TestTreeNode |
||||
{ |
||||
TestClass testClass; |
||||
|
||||
public TestClassTreeNode(TestProject project, TestClass testClass) |
||||
: base(project, testClass.Name) |
||||
{ |
||||
this.testClass = testClass; |
||||
testClass.ResultChanged += TestClassResultChanged; |
||||
Nodes.Add(new ExtTreeNode()); |
||||
UpdateImageListIndex(testClass.Result); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the underlying IClass for this test class.
|
||||
/// </summary>
|
||||
public IClass Class { |
||||
get { |
||||
return testClass.Class; |
||||
} |
||||
} |
||||
|
||||
public override void Dispose() |
||||
{ |
||||
if (!IsDisposed) { |
||||
testClass.ResultChanged -= TestClassResultChanged; |
||||
testClass.TestMethods.TestMethodAdded -= TestMethodAdded; |
||||
testClass.TestMethods.TestMethodRemoved -= TestMethodRemoved; |
||||
} |
||||
base.Dispose(); |
||||
} |
||||
|
||||
protected override void Initialize() |
||||
{ |
||||
Nodes.Clear(); |
||||
|
||||
foreach (TestMethod method in testClass.TestMethods) { |
||||
AddTestMethodTreeNode(method); |
||||
} |
||||
testClass.TestMethods.TestMethodAdded += TestMethodAdded; |
||||
testClass.TestMethods.TestMethodRemoved += TestMethodRemoved; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Adds a new TestMethodTreeNode to this node.
|
||||
/// </summary>
|
||||
void AddTestMethodTreeNode(TestMethod method) |
||||
{ |
||||
TestMethodTreeNode node = new TestMethodTreeNode(TestProject, method); |
||||
node.AddTo(this); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Updates the node's icon based on the test class test result.
|
||||
/// </summary>
|
||||
void TestClassResultChanged(object source, EventArgs e) |
||||
{ |
||||
UpdateImageListIndex(testClass.Result); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Adds a new test method tree node to this class node after a new
|
||||
/// TestMethod has been added to the TestClass.
|
||||
/// </summary>
|
||||
void TestMethodAdded(object source, TestMethodEventArgs e) |
||||
{ |
||||
AddTestMethodTreeNode(e.TestMethod); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Removes the corresponding test method node after it has been
|
||||
/// removed from the TestClass.
|
||||
/// </summary>
|
||||
void TestMethodRemoved(object source, TestMethodEventArgs e) |
||||
{ |
||||
foreach (TestMethodTreeNode methodNode in Nodes) { |
||||
if (methodNode.Text == e.TestMethod.Name) { |
||||
Nodes.Remove(methodNode); |
||||
methodNode.Dispose(); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -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 class TestFinishedEventArgs : EventArgs |
||||
{ |
||||
TestResult result; |
||||
|
||||
public TestFinishedEventArgs(TestResult result) |
||||
{ |
||||
this.result = result; |
||||
} |
||||
|
||||
public TestResult Result { |
||||
get { |
||||
return result; |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,163 @@
@@ -0,0 +1,163 @@
|
||||
// <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; |
||||
|
||||
namespace ICSharpCode.UnitTesting |
||||
{ |
||||
/// <summary>
|
||||
/// Represents a method that has the [Test] attribute and
|
||||
/// can be tested.
|
||||
/// </summary>
|
||||
public class TestMethod |
||||
{ |
||||
string prefix = String.Empty; |
||||
IMethod method; |
||||
TestResultType testResultType = TestResultType.None; |
||||
|
||||
/// <summary>
|
||||
/// Raised when the test result has changed.
|
||||
/// </summary>
|
||||
public event EventHandler ResultChanged; |
||||
|
||||
public TestMethod(IMethod method) |
||||
{ |
||||
this.method = method; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Creates a new TestMethod instance.
|
||||
/// </summary>
|
||||
/// <param name="prefix">The prefix to be added to the
|
||||
/// method name with a dot character. This is specified
|
||||
/// when the test method refers to a base class method. NUnit
|
||||
/// refers to base class test methods by prefixing the
|
||||
/// class name to it:
|
||||
///
|
||||
/// [TestFixture]
|
||||
/// public class DerivedClass : BaseClass
|
||||
///
|
||||
/// Test method name:
|
||||
///
|
||||
/// RootNamespace.DerivedClass.BaseClass.BaseClassMethod
|
||||
/// </param>
|
||||
public TestMethod(string prefix, IMethod method) |
||||
{ |
||||
this.method = method; |
||||
this.prefix = prefix; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the underlying IMethod for this TestMethod.
|
||||
/// </summary>
|
||||
public IMethod Method { |
||||
get { |
||||
return method; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the test result for this method.
|
||||
/// </summary>
|
||||
public TestResultType Result { |
||||
get { |
||||
return testResultType; |
||||
} |
||||
set { |
||||
TestResultType previousTestResultType = testResultType; |
||||
testResultType = value; |
||||
if (previousTestResultType != testResultType) { |
||||
OnResultChanged(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the method's name.
|
||||
/// </summary>
|
||||
public string Name { |
||||
get { |
||||
if (prefix.Length > 0) { |
||||
return String.Concat(prefix, ".", method.Name); |
||||
} |
||||
return method.Name; |
||||
} |
||||
} |
||||
|
||||
/// <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.Name)) { |
||||
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:
|
||||
///
|
||||
/// Namespace.Class.Method
|
||||
/// </summary>
|
||||
public static string GetMethodName(string qualifiedName) |
||||
{ |
||||
if (qualifiedName != null) { |
||||
int index = qualifiedName.LastIndexOf('.'); |
||||
if (index >= 0) { |
||||
return qualifiedName.Substring(index + 1); |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns the namespace and class name from a fully qualified
|
||||
/// name of the form:
|
||||
///
|
||||
/// Namespace.Class.Method
|
||||
/// </summary>
|
||||
public static string GetQualifiedClassName(string qualifiedName) |
||||
{ |
||||
if (qualifiedName != null) { |
||||
int methodIndex = qualifiedName.LastIndexOf('.'); |
||||
if (methodIndex >= 0) { |
||||
return qualifiedName.Substring(0, methodIndex); |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Raises the ResultChanged event.
|
||||
/// </summary>
|
||||
void OnResultChanged() |
||||
{ |
||||
if (ResultChanged != null) { |
||||
ResultChanged(this, new EventArgs()); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,159 @@
@@ -0,0 +1,159 @@
|
||||
// <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.Collections.ObjectModel; |
||||
|
||||
namespace ICSharpCode.UnitTesting |
||||
{ |
||||
public class TestMethodCollection : KeyedCollection<string, TestMethod> |
||||
{ |
||||
TestResultType testResult = TestResultType.None; |
||||
Dictionary<string, TestMethod> passedTestMethods = new Dictionary<string, TestMethod>(); |
||||
Dictionary<string, TestMethod> failedTestMethods = new Dictionary<string, TestMethod>(); |
||||
Dictionary<string, TestMethod> ignoredTestMethods = new Dictionary<string, TestMethod>(); |
||||
|
||||
/// <summary>
|
||||
/// Raised when the test result for this collection of
|
||||
/// methods has changed.
|
||||
/// </summary>
|
||||
public event EventHandler ResultChanged; |
||||
|
||||
/// <summary>
|
||||
/// Raised when a method is added to this collection.
|
||||
/// </summary>
|
||||
public event TestMethodEventHandler TestMethodAdded; |
||||
|
||||
/// <summary>
|
||||
/// Raised when a method is removed from this collection.
|
||||
/// </summary>
|
||||
public event TestMethodEventHandler TestMethodRemoved; |
||||
|
||||
/// <summary>
|
||||
/// Gets the overall test results for the collection of
|
||||
/// test methods.
|
||||
/// </summary>
|
||||
public TestResultType Result { |
||||
get { |
||||
return testResult; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Sets all the test method test results back to none.
|
||||
/// </summary>
|
||||
public void ResetTestResults() |
||||
{ |
||||
passedTestMethods.Clear(); |
||||
failedTestMethods.Clear(); |
||||
ignoredTestMethods.Clear(); |
||||
|
||||
foreach (TestMethod method in this) { |
||||
method.Result = TestResultType.None; |
||||
} |
||||
|
||||
SetTestResult(TestResultType.None); |
||||
} |
||||
|
||||
protected override void InsertItem(int index, TestMethod item) |
||||
{ |
||||
item.ResultChanged += TestMethodResultChanged; |
||||
base.InsertItem(index, item); |
||||
TestMethodResultChanged(item, new EventArgs()); |
||||
OnTestMethodAdded(item); |
||||
} |
||||
|
||||
protected override string GetKeyForItem(TestMethod item) |
||||
{ |
||||
return item.Name; |
||||
} |
||||
|
||||
protected override void RemoveItem(int index) |
||||
{ |
||||
TestMethod method = this[index]; |
||||
method.ResultChanged -= TestMethodResultChanged; |
||||
base.RemoveItem(index); |
||||
OnTestResultNone(method.Name); |
||||
OnTestMethodRemoved(method); |
||||
} |
||||
|
||||
protected void OnTestMethodAdded(TestMethod testMethod) |
||||
{ |
||||
if (TestMethodAdded != null) { |
||||
TestMethodAdded(this, new TestMethodEventArgs(testMethod)); |
||||
} |
||||
} |
||||
|
||||
protected void OnTestMethodRemoved(TestMethod testMethod) |
||||
{ |
||||
if (TestMethodRemoved != null) { |
||||
TestMethodRemoved(this, new TestMethodEventArgs(testMethod)); |
||||
} |
||||
} |
||||
|
||||
void TestMethodResultChanged(object source, EventArgs e) |
||||
{ |
||||
TestMethod method = (TestMethod)source; |
||||
switch (method.Result) { |
||||
case TestResultType.None: |
||||
OnTestResultNone(method.Name); |
||||
break; |
||||
case TestResultType.Failure: |
||||
SetTestResult(TestResultType.Failure); |
||||
failedTestMethods.Add(method.Name, method); |
||||
break; |
||||
case TestResultType.Success: |
||||
passedTestMethods.Add(method.Name, method); |
||||
if (passedTestMethods.Count == Count) { |
||||
SetTestResult(TestResultType.Success); |
||||
} else if (passedTestMethods.Count + ignoredTestMethods.Count == Count) { |
||||
SetTestResult(TestResultType.Ignored); |
||||
} |
||||
break; |
||||
case TestResultType.Ignored: |
||||
ignoredTestMethods.Add(method.Name, method); |
||||
if (ignoredTestMethods.Count == Count || |
||||
ignoredTestMethods.Count + passedTestMethods.Count == Count) { |
||||
SetTestResult(TestResultType.Ignored); |
||||
} |
||||
break; |
||||
} |
||||
} |
||||
|
||||
void SetTestResult(TestResultType value) |
||||
{ |
||||
TestResultType previousTestResult = testResult; |
||||
testResult = value; |
||||
if (testResult != previousTestResult) { |
||||
OnResultChanged(); |
||||
} |
||||
} |
||||
|
||||
void OnResultChanged() |
||||
{ |
||||
if (ResultChanged != null) { |
||||
ResultChanged(this, new EventArgs()); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Removes the specified test method from the list of
|
||||
/// failed, passed and ignored tests and updates the
|
||||
/// test result state of the test methods collection.
|
||||
/// </summary>
|
||||
void OnTestResultNone(string name) |
||||
{ |
||||
passedTestMethods.Remove(name); |
||||
failedTestMethods.Remove(name); |
||||
ignoredTestMethods.Remove(name); |
||||
if (ignoredTestMethods.Count + failedTestMethods.Count == 0) { |
||||
SetTestResult(TestResultType.None); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
// <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 |
||||
{ |
||||
/// <summary>
|
||||
/// Represents the method that will handle the TestCollection's
|
||||
/// TestMethodAdded or TestMethodRemoved events.
|
||||
/// </summary>
|
||||
public delegate void TestMethodEventHandler(object source, TestMethodEventArgs e); |
||||
|
||||
/// <summary>
|
||||
/// Provides data for the TestCollection's TestMethodAdded and TestMethodRemoved events.
|
||||
/// </summary>
|
||||
public class TestMethodEventArgs |
||||
{ |
||||
TestMethod testMethod; |
||||
|
||||
public TestMethodEventArgs(TestMethod testMethod) |
||||
{ |
||||
this.testMethod = testMethod; |
||||
} |
||||
|
||||
public TestMethod TestMethod { |
||||
get { |
||||
return testMethod; |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,59 @@
@@ -0,0 +1,59 @@
|
||||
// <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.Gui; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
|
||||
namespace ICSharpCode.UnitTesting |
||||
{ |
||||
/// <summary>
|
||||
/// Represents a method that has the [Test] attribute associated with it.
|
||||
/// </summary>
|
||||
public class TestMethodTreeNode : TestTreeNode |
||||
{ |
||||
TestMethod testMethod; |
||||
|
||||
public TestMethodTreeNode(TestProject project, TestMethod testMethod) |
||||
: base(project, testMethod.Name) |
||||
{ |
||||
this.testMethod = testMethod; |
||||
testMethod.ResultChanged += TestMethodResultChanged; |
||||
UpdateImageListIndex(testMethod.Result); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the underlying IMethod for this test method.
|
||||
/// </summary>
|
||||
public IMethod Method { |
||||
get { |
||||
return testMethod.Method; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Removes the TestMethod.ResultChanged event handler.
|
||||
/// </summary>
|
||||
public override void Dispose() |
||||
{ |
||||
if (!IsDisposed) { |
||||
testMethod.ResultChanged -= TestMethodResultChanged; |
||||
} |
||||
base.Dispose(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Updates the node's icon after the test method result
|
||||
/// has changed.
|
||||
/// </summary>
|
||||
void TestMethodResultChanged(object source, EventArgs e) |
||||
{ |
||||
UpdateImageListIndex(testMethod.Result); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,302 @@
@@ -0,0 +1,302 @@
|
||||
// <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.Windows.Forms; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
|
||||
namespace ICSharpCode.UnitTesting |
||||
{ |
||||
/// <summary>
|
||||
/// Represents a namespace in the TestTreeView.
|
||||
/// </summary>
|
||||
public class TestNamespaceTreeNode : TestTreeNode |
||||
{ |
||||
string ns = String.Empty; |
||||
string namespacePrefix = String.Empty; |
||||
string fullNamespace; |
||||
TestClassCollection testClasses; |
||||
List<TestNamespaceTreeNode> namespaceChildNodes = new List<TestNamespaceTreeNode>(); |
||||
ExtTreeNode dummyNode; |
||||
|
||||
/// <summary>
|
||||
/// Creates a new TestNamespaceTreeNode
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Note that the Namespace child nodes are added in
|
||||
/// the constructor not whilst the node is expanding
|
||||
/// via the Initialize method. This is so the icon for the
|
||||
/// node can be updated even if the parent node is not
|
||||
/// expanded. The alternative is to have each namespace node,
|
||||
/// even if it does not have any class child nodes, to
|
||||
/// store all the classes that are below it in the tree and
|
||||
/// update the icon based on their results. The assumption
|
||||
/// is that there are fewer namespace nodes than classes so
|
||||
/// adding the namespace nodes here does not matter.
|
||||
/// </remarks>
|
||||
/// <param name="namespacePrefix">The first part of the
|
||||
/// namespace (including any dot characters) before this
|
||||
/// particular namespace.</param>
|
||||
/// <param name="name">The name of the namespace without any
|
||||
/// dot characters (e.g. the name at this particular
|
||||
/// location in the tree).</param>
|
||||
public TestNamespaceTreeNode(TestProject testProject, string namespacePrefix, string name) |
||||
: base(testProject, name) |
||||
{ |
||||
ns = name; |
||||
this.namespacePrefix = namespacePrefix; |
||||
fullNamespace = GetFullNamespace(namespacePrefix, ns); |
||||
GetTestClasses(); |
||||
testProject.TestClasses.TestClassAdded += TestClassAdded; |
||||
testProject.TestClasses.TestClassRemoved += TestClassRemoved; |
||||
|
||||
// Add namespace nodes - do not add them on node expansion.
|
||||
foreach (string namespaceName in TestProject.GetChildNamespaces(fullNamespace)) { |
||||
TestNamespaceTreeNode node = new TestNamespaceTreeNode(TestProject, fullNamespace, namespaceName); |
||||
node.AddTo(this); |
||||
namespaceChildNodes.Add(node); |
||||
node.ImageIndexChanged += TestNamespaceNodeImageIndexChanged; |
||||
} |
||||
|
||||
// Add a dummy node if there are no namespaces since
|
||||
// there might be class nodes which will be added
|
||||
// lazily when the node is expanded.
|
||||
if (namespaceChildNodes.Count == 0) { |
||||
dummyNode = new ExtTreeNode(); |
||||
Nodes.Add(dummyNode); |
||||
} |
||||
|
||||
UpdateImageListIndex(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Creates a new TestNamespaceTreeNode with the specified
|
||||
/// namespace name. This node will have no namespace prefix.
|
||||
/// </summary>
|
||||
public TestNamespaceTreeNode(TestProject testProject, string name) |
||||
: this(testProject, String.Empty, name) |
||||
{ |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Frees any resources held by this class.
|
||||
/// </summary>
|
||||
public override void Dispose() |
||||
{ |
||||
if (!IsDisposed) { |
||||
TestProject.TestClasses.TestClassAdded -= TestClassAdded; |
||||
TestProject.TestClasses.TestClassRemoved -= TestClassRemoved; |
||||
testClasses.ResultChanged -= TestClassesResultChanged; |
||||
} |
||||
base.Dispose(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Adds the test class nodes for this namespace when the
|
||||
/// node is expanded.
|
||||
/// </summary>
|
||||
protected override void Initialize() |
||||
{ |
||||
if (dummyNode != null) { |
||||
Nodes.Clear(); |
||||
} |
||||
|
||||
// Add class nodes for this namespace.
|
||||
foreach (TestClass c in testClasses) { |
||||
TestClassTreeNode classNode = new TestClassTreeNode(TestProject, c); |
||||
classNode.AddTo(this); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Adds the child namespace to the namespace prefix.
|
||||
/// </summary>
|
||||
static string GetFullNamespace(string prefix, string name) |
||||
{ |
||||
if (prefix.Length > 0) { |
||||
return String.Concat(prefix, ".", name); |
||||
} |
||||
return name; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Updates this node's icon because one of its child namespace nodes
|
||||
/// has changed.
|
||||
/// </summary>
|
||||
void TestNamespaceNodeImageIndexChanged(object source, EventArgs e) |
||||
{ |
||||
UpdateImageListIndex(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the test classes for this namespace.
|
||||
/// </summary>
|
||||
void GetTestClasses() |
||||
{ |
||||
testClasses = new TestClassCollection(); |
||||
foreach (TestClass c in TestProject.GetTestClasses(fullNamespace)) { |
||||
testClasses.Add(c); |
||||
} |
||||
testClasses.ResultChanged += TestClassesResultChanged; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// The overall test result for the classes in this namespace
|
||||
/// have changed so the node's icon is updated.
|
||||
/// </summary>
|
||||
void TestClassesResultChanged(object source, EventArgs e) |
||||
{ |
||||
UpdateImageListIndex(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Determines the image list index for this node based
|
||||
/// on the current state of all the child nodes.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Since the test classes overall test result is
|
||||
/// available via the TestClassCollection we do not
|
||||
/// need to sum all the individual test classes.
|
||||
/// </remarks>
|
||||
void UpdateImageListIndex() |
||||
{ |
||||
int ignoredCount = 0; |
||||
int passedCount = 0; |
||||
int failedCount = 0; |
||||
|
||||
// Count the passes, failures and ignores for the
|
||||
// namespace child nodes.
|
||||
foreach (ExtTreeNode node in namespaceChildNodes) { |
||||
switch (node.ImageIndex) { |
||||
case (int)TestTreeViewImageListIndex.TestFailed: |
||||
failedCount++; |
||||
break; |
||||
case (int)TestTreeViewImageListIndex.TestIgnored: |
||||
ignoredCount++; |
||||
break; |
||||
case (int)TestTreeViewImageListIndex.TestPassed: |
||||
passedCount++; |
||||
break; |
||||
} |
||||
} |
||||
|
||||
// Check the passes, failures and ignores for the
|
||||
// test classes that belong to this namespace.
|
||||
switch (testClasses.Result) { |
||||
case TestResultType.Failure: |
||||
failedCount++; |
||||
break; |
||||
case TestResultType.Success: |
||||
passedCount++; |
||||
break; |
||||
case TestResultType.Ignored: |
||||
ignoredCount++; |
||||
break; |
||||
} |
||||
|
||||
// Work out the total number of passes we are expecting
|
||||
int total = namespaceChildNodes.Count; |
||||
if (testClasses.Count > 0) { |
||||
// Only add one for the testClasses since the
|
||||
// overall pass or failure is indicated via
|
||||
// the TestClassCollection so we do not need
|
||||
// to add all the test classes.
|
||||
total++; |
||||
} |
||||
|
||||
// Determine the correct image list index for this node.
|
||||
if (failedCount > 0) { |
||||
UpdateImageListIndex(TestResultType.Failure); |
||||
} else if (ignoredCount > 0) { |
||||
UpdateImageListIndex(TestResultType.Ignored); |
||||
} else if (passedCount == total) { |
||||
UpdateImageListIndex(TestResultType.Success); |
||||
} else { |
||||
UpdateImageListIndex(TestResultType.None); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// A new test class has been added to the project so a new
|
||||
/// tree node is added if the class belongs to this namespace.
|
||||
/// </summary>
|
||||
void TestClassAdded(object source, TestClassEventArgs e) |
||||
{ |
||||
if (e.TestClass.Namespace == fullNamespace) { |
||||
// Add test class to our monitored test classes.
|
||||
testClasses.Add(e.TestClass); |
||||
|
||||
// Add a new tree node.
|
||||
TestClassTreeNode classNode = new TestClassTreeNode(TestProject, e.TestClass); |
||||
classNode.AddTo(this); |
||||
} else if (isInitialized && NamespaceStartsWith(e.TestClass.Namespace)) { |
||||
// Check if there is a child namespace node for the class.
|
||||
string childNamespace = TestClass.GetChildNamespace(e.TestClass.Namespace, fullNamespace); |
||||
if (!NamespaceNodeExists(childNamespace)) { |
||||
// Add a new namespace node.
|
||||
TestNamespaceTreeNode node = new TestNamespaceTreeNode(TestProject, fullNamespace, childNamespace); |
||||
node.AddTo(this); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Determines whether the namespace for this node starts
|
||||
/// with the namespace specified.
|
||||
/// </summary>
|
||||
bool NamespaceStartsWith(string ns) |
||||
{ |
||||
return ns.StartsWith(String.Concat(fullNamespace, ".")); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// A test class has been removed from the project so the
|
||||
/// corresponding tree node is removed if it belongs to this
|
||||
/// namespace.
|
||||
/// </summary>
|
||||
void TestClassRemoved(object source, TestClassEventArgs e) |
||||
{ |
||||
if (e.TestClass.Namespace == fullNamespace) { |
||||
// Remove test class from our monitored test classes.
|
||||
testClasses.Remove(e.TestClass); |
||||
|
||||
// Remove the corresponding tree node.
|
||||
foreach (ExtTreeNode node in Nodes) { |
||||
TestClassTreeNode classNode = node as TestClassTreeNode; |
||||
if (classNode != null && classNode.Text == e.TestClass.Name) { |
||||
classNode.Remove(); |
||||
classNode.Dispose(); |
||||
break; |
||||
} |
||||
} |
||||
|
||||
// Remove this namespace node if there are no more child nodes.
|
||||
RemoveIfEmpty(); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Removes this node if it has no child nodes. This
|
||||
/// method also calls the same method on the parent
|
||||
/// namespace node so it can check whether it should
|
||||
/// remove itself.
|
||||
/// </summary>
|
||||
void RemoveIfEmpty() |
||||
{ |
||||
if (Nodes.Count == 0) { |
||||
Remove(); |
||||
Dispose(); |
||||
TestNamespaceTreeNode parentNode = Parent as TestNamespaceTreeNode; |
||||
if (parentNode != null) { |
||||
parentNode.RemoveIfEmpty(); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,268 @@
@@ -0,0 +1,268 @@
|
||||
// <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.Project; |
||||
|
||||
namespace ICSharpCode.UnitTesting |
||||
{ |
||||
/// <summary>
|
||||
/// Represents a project that has a reference to a unit testing
|
||||
/// framework assembly. Currently only NUnit is supported.
|
||||
/// </summary>
|
||||
public class TestProject |
||||
{ |
||||
IProject project; |
||||
IProjectContent projectContent; |
||||
TestClassCollection testClasses; |
||||
List<string> rootNamespaces; |
||||
|
||||
public TestProject(IProject project, IProjectContent projectContent) |
||||
{ |
||||
this.project = project; |
||||
this.projectContent = projectContent; |
||||
} |
||||
|
||||
/// <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.Name)) { |
||||
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(string referenceName) |
||||
{ |
||||
if (referenceName != null) { |
||||
return referenceName.Equals("NUnit.Framework", StringComparison.InvariantCultureIgnoreCase); |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the test classes in this project.
|
||||
/// </summary>
|
||||
public TestClassCollection TestClasses { |
||||
get { |
||||
if (testClasses == null) { |
||||
GetTestClasses(); |
||||
} |
||||
return testClasses; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the test classes that exist in the specified namespace.
|
||||
/// </summary>
|
||||
public TestClass[] GetTestClasses(string ns) |
||||
{ |
||||
return TestClass.GetTestClasses(TestClasses, ns); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the test classes whose namespaces start with the specified string.
|
||||
/// </summary>
|
||||
public TestClass[] GetAllTestClasses(string namespaceStartsWith) |
||||
{ |
||||
return TestClass.GetAllTestClasses(TestClasses, namespaceStartsWith); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets all the child namespaces with the specified parent
|
||||
/// namespace. The parent namespace can be one or more
|
||||
/// namespaces separated with a period.
|
||||
/// </summary>
|
||||
public string[] GetChildNamespaces(string parentNamespace) |
||||
{ |
||||
return TestClass.GetChildNamespaces(TestClasses, parentNamespace); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the project's name.
|
||||
/// </summary>
|
||||
public string Name { |
||||
get { |
||||
return project.Name; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the distinct root namespaces for all this project.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If one of the namespaces is 'ICSharpCode.XmlEditor' then this
|
||||
/// method will return 'ICSharpCode' as one of the root namespaces.
|
||||
/// </remarks>
|
||||
public IList<string> RootNamespaces { |
||||
get { |
||||
if (rootNamespaces == null) { |
||||
GetRootNamespaces(); |
||||
} |
||||
return rootNamespaces; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Updates the test method based on the test result.
|
||||
/// </summary>
|
||||
public void UpdateTestResult(TestResult testResult) |
||||
{ |
||||
TestClasses.UpdateTestResult(testResult); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Sets all the test results back to none.
|
||||
/// </summary>
|
||||
public void ResetTestResults() |
||||
{ |
||||
TestClasses.ResetTestResults(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Updates the classes and methods based on the new parse
|
||||
/// information.
|
||||
/// </summary>
|
||||
/// <param name="oldUnit">The old compiliation unit
|
||||
/// (ParseInformationEventArgs.ParseInformation.BestCompilationUnit as ICompilationUnit)</param>
|
||||
/// <param name="newUnit">The new compilation unit
|
||||
/// (ParseInformationEventArgs.CompilationUnit).</param>
|
||||
public void UpdateParseInfo(ICompilationUnit oldUnit, ICompilationUnit newUnit) |
||||
{ |
||||
if (!IsParseInfoForThisProject(oldUnit, newUnit)) { |
||||
return; |
||||
} |
||||
|
||||
Dictionary<string, IClass> classDictionary = new Dictionary<string, IClass>(); |
||||
Dictionary<string, bool> wasUpdatedDictionary = new Dictionary<string, bool>(); |
||||
|
||||
if (oldUnit != null) { |
||||
foreach (IClass c in oldUnit.Classes) { |
||||
classDictionary[c.FullyQualifiedName] = c; |
||||
wasUpdatedDictionary[c.FullyQualifiedName] = false; |
||||
} |
||||
} |
||||
if (newUnit != null) { |
||||
foreach (IClass c in newUnit.Classes) { |
||||
UpdateTestClass(c); |
||||
wasUpdatedDictionary[c.FullyQualifiedName] = true; |
||||
} |
||||
} |
||||
|
||||
// Remove missing classes.
|
||||
foreach (KeyValuePair<string, bool> entry in wasUpdatedDictionary) { |
||||
if (!entry.Value) { |
||||
IClass c = classDictionary[entry.Key]; |
||||
TestClasses.Remove(c.FullyQualifiedName); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Determines whether the new parse information is for this test
|
||||
/// project.
|
||||
/// </summary>
|
||||
public bool IsParseInfoForThisProject(ICompilationUnit oldUnit, ICompilationUnit newUnit) |
||||
{ |
||||
ICompilationUnit unit = oldUnit; |
||||
if (unit == null) { |
||||
unit = newUnit; |
||||
} |
||||
if (unit != null) { |
||||
return Object.ReferenceEquals(unit.ProjectContent, this.projectContent); |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Adds a new class to the test project's classes only if
|
||||
/// the class is a test class.
|
||||
/// </summary>
|
||||
void AddNewTestClass(IClass c) |
||||
{ |
||||
if (TestClass.IsTestClass(c)) { |
||||
TestClass testClass = new TestClass(c); |
||||
TestClasses.Add(testClass); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Updates the test class methods based on the newly parsed class
|
||||
/// information.
|
||||
/// </summary>
|
||||
void UpdateTestClass(IClass c) |
||||
{ |
||||
if (TestClasses.Contains(c.FullyQualifiedName)) { |
||||
if (TestClass.IsTestClass(c)) { |
||||
TestClass testClass = TestClasses[c.FullyQualifiedName]; |
||||
testClass.UpdateClass(c); |
||||
} else { |
||||
// TestFixture attribute has been removed so
|
||||
// remove the class from the set of TestClasses.
|
||||
TestClasses.Remove(c.FullyQualifiedName); |
||||
} |
||||
} else { |
||||
// TestFixture attribute may have been recently added to
|
||||
// this class so call AddNewTestClass. No need to
|
||||
// check if the class is actually a test class since
|
||||
// AddNewTestClass does this anyway.
|
||||
AddNewTestClass(c); |
||||
} |
||||
} |
||||
|
||||
void GetTestClasses() |
||||
{ |
||||
testClasses = new TestClassCollection(); |
||||
foreach (IClass c in projectContent.Classes) { |
||||
if (TestClass.IsTestClass(c)) { |
||||
if (!testClasses.Contains(c.FullyQualifiedName)) { |
||||
testClasses.Add(new TestClass(c)); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
void GetRootNamespaces() |
||||
{ |
||||
rootNamespaces = new List<string>(); |
||||
foreach (TestClass c in TestClasses) { |
||||
string rootNamespace = c.RootNamespace; |
||||
if (rootNamespace.Length > 0 && !rootNamespaces.Contains(rootNamespace)) { |
||||
rootNamespaces.Add(rootNamespace); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -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 ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
|
||||
namespace ICSharpCode.UnitTesting |
||||
{ |
||||
/// <summary>
|
||||
/// The root tree node for a project that has tests.
|
||||
/// </summary>
|
||||
public class TestProjectTreeNode : TestTreeNode |
||||
{ |
||||
public TestProjectTreeNode(TestProject project) |
||||
: base(project, project.Name) |
||||
{ |
||||
Nodes.Add(new ExtTreeNode()); |
||||
TestProject.TestClasses.ResultChanged += TestClassesResultChanged; |
||||
TestProject.TestClasses.TestClassAdded += TestClassAdded; |
||||
TestProject.TestClasses.TestClassRemoved += TestClassRemoved; |
||||
} |
||||
|
||||
public override void Dispose() |
||||
{ |
||||
if (!IsDisposed) { |
||||
TestProject.TestClasses.ResultChanged -= TestClassesResultChanged; |
||||
TestProject.TestClasses.TestClassAdded -= TestClassAdded; |
||||
TestProject.TestClasses.TestClassRemoved -= TestClassRemoved; |
||||
} |
||||
base.Dispose(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Adds the child nodes after this node has been expanded.
|
||||
/// </summary>
|
||||
protected override void Initialize() |
||||
{ |
||||
Nodes.Clear(); |
||||
|
||||
// Add namespace nodes.
|
||||
foreach (string rootNamespace in TestProject.RootNamespaces) { |
||||
TestNamespaceTreeNode node = new TestNamespaceTreeNode(TestProject, rootNamespace); |
||||
node.AddTo(this); |
||||
} |
||||
|
||||
// Add class nodes.
|
||||
foreach (TestClass c in TestProject.GetTestClasses(String.Empty)) { |
||||
AddClassNode(c); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Updates this node's icon based on the overall result of the
|
||||
/// test classes.
|
||||
/// </summary>
|
||||
void TestClassesResultChanged(object source, EventArgs e) |
||||
{ |
||||
UpdateImageListIndex(TestProject.TestClasses.Result); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Adds a new class node to this project node if the
|
||||
/// class added has no root namespace.
|
||||
/// </summary>
|
||||
void TestClassAdded(object source, TestClassEventArgs e) |
||||
{ |
||||
if (e.TestClass.Namespace == String.Empty) { |
||||
AddClassNode(e.TestClass); |
||||
} else if (isInitialized) { |
||||
// Check that we have a namespace node for this class.
|
||||
if (!NamespaceNodeExists(e.TestClass.RootNamespace)) { |
||||
// Add a new namespace node.
|
||||
TestNamespaceTreeNode node = new TestNamespaceTreeNode(TestProject, e.TestClass.RootNamespace); |
||||
node.AddTo(this); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Removes the corresponding tree node that is a child of
|
||||
/// this project tree node if the class has no root namespace.
|
||||
/// </summary>
|
||||
void TestClassRemoved(object source, TestClassEventArgs e) |
||||
{ |
||||
if (e.TestClass.Namespace == String.Empty) { |
||||
foreach (ExtTreeNode node in Nodes) { |
||||
TestClassTreeNode classNode = node as TestClassTreeNode; |
||||
if (classNode != null && classNode.Text == e.TestClass.Name) { |
||||
classNode.Remove(); |
||||
classNode.Dispose(); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Adds a new TestClassTreeNode to this node.
|
||||
/// </summary>
|
||||
void AddClassNode(TestClass c) |
||||
{ |
||||
TestClassTreeNode node = new TestClassTreeNode(TestProject, c); |
||||
node.AddTo(this); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,106 @@
@@ -0,0 +1,106 @@
|
||||
// <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 enum TestResultType { |
||||
/// <summary>
|
||||
/// The test has not been run.
|
||||
/// </summary>
|
||||
None = 0, |
||||
|
||||
/// <summary>
|
||||
/// The test passed.
|
||||
/// </summary>
|
||||
Success = 1, |
||||
|
||||
/// <summary>
|
||||
/// The test failed.
|
||||
/// </summary>
|
||||
Failure = 2, |
||||
|
||||
/// <summary>
|
||||
/// The test was ignored.
|
||||
/// </summary>
|
||||
Ignored = 3 |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Holds the information about a single test result.
|
||||
/// </summary>
|
||||
public class TestResult |
||||
{ |
||||
string name = String.Empty; |
||||
string message = String.Empty; |
||||
string stackTrace = String.Empty; |
||||
TestResultType resultType = TestResultType.None; |
||||
|
||||
public TestResult(string name) |
||||
{ |
||||
this.name = name; |
||||
} |
||||
|
||||
public string Name { |
||||
get { |
||||
return name; |
||||
} |
||||
} |
||||
|
||||
public bool IsSuccess { |
||||
get { |
||||
return resultType == TestResultType.Success; |
||||
} |
||||
set { |
||||
resultType = TestResultType.Success; |
||||
} |
||||
} |
||||
|
||||
public bool IsFailure { |
||||
get { |
||||
return resultType == TestResultType.Failure; |
||||
} |
||||
set { |
||||
resultType = TestResultType.Failure; |
||||
} |
||||
} |
||||
|
||||
public bool IsIgnored { |
||||
get { |
||||
return resultType == TestResultType.Ignored; |
||||
} |
||||
set { |
||||
resultType = TestResultType.Ignored; |
||||
} |
||||
} |
||||
|
||||
public TestResultType ResultType { |
||||
get { |
||||
return resultType; |
||||
} |
||||
} |
||||
|
||||
public string Message { |
||||
get { |
||||
return message; |
||||
} |
||||
set { |
||||
message = value; |
||||
} |
||||
} |
||||
|
||||
public string StackTrace { |
||||
get { |
||||
return stackTrace; |
||||
} |
||||
set { |
||||
stackTrace = value; |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,172 @@
@@ -0,0 +1,172 @@
|
||||
// <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 System.Text; |
||||
|
||||
namespace ICSharpCode.UnitTesting |
||||
{ |
||||
/// <summary>
|
||||
/// 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 |
||||
{ |
||||
FileInfo fileInfo; |
||||
TestResultsReader testResultsReader; |
||||
FileSystemWatcher fileSystemWatcher; |
||||
|
||||
long filePosition; |
||||
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>
|
||||
public event TestFinishedEventHandler TestFinished; |
||||
|
||||
public TestResultsMonitor(string fileName) |
||||
{ |
||||
fileInfo = new FileInfo(fileName); |
||||
ResetFilePosition(); |
||||
} |
||||
|
||||
public TestResultsMonitor() |
||||
{ |
||||
ResetFilePosition(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the test results filename.
|
||||
/// </summary>
|
||||
public string FileName { |
||||
get { |
||||
return fileInfo.FullName; |
||||
} |
||||
set { |
||||
fileInfo = new FileInfo(value); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Starts monitoring for test results.
|
||||
/// </summary>
|
||||
public void Start() |
||||
{ |
||||
testResultsReader = new TestResultsReader(); |
||||
ResetFilePosition(); |
||||
|
||||
string filter = fileInfo.Name; |
||||
fileSystemWatcher = new FileSystemWatcher(fileInfo.DirectoryName, filter); |
||||
|
||||
if (File.Exists(fileInfo.FullName)) { |
||||
fileSystemWatcher.NotifyFilter = NotifyFilters.LastWrite; |
||||
fileSystemWatcher.Changed += FileChanged; |
||||
} else { |
||||
fileSystemWatcher.Created += FileCreated; |
||||
} |
||||
fileSystemWatcher.Error += FileSystemWatcherError; |
||||
fileSystemWatcher.EnableRaisingEvents = true; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Stops monitoring.
|
||||
/// </summary>
|
||||
public void Stop() |
||||
{ |
||||
if (fileSystemWatcher != null) { |
||||
fileSystemWatcher.Dispose(); |
||||
fileSystemWatcher = null; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Reads the rest of the file from the current position.
|
||||
/// Raises the TestFinished event for each test result
|
||||
/// still in the file.
|
||||
/// </summary>
|
||||
public void Read() |
||||
{ |
||||
string text = ReadTextAdded(); |
||||
if (text != null) { |
||||
Console.WriteLine(text); |
||||
TestResult[] results = testResultsReader.Read(text); |
||||
OnTestResultsReceived(results); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Stops monitoring and releases any resources used
|
||||
/// by the TestResultsMonitor.
|
||||
/// </summary>
|
||||
public void Dispose() |
||||
{ |
||||
Stop(); |
||||
} |
||||
|
||||
void FileCreated(object source, FileSystemEventArgs e) |
||||
{ |
||||
fileSystemWatcher.Created -= FileCreated; |
||||
fileSystemWatcher.NotifyFilter = NotifyFilters.LastWrite; |
||||
fileSystemWatcher.Changed += FileChanged; |
||||
} |
||||
|
||||
void FileChanged(object source, FileSystemEventArgs e) |
||||
{ |
||||
Read(); |
||||
} |
||||
|
||||
void OnTestResultsReceived(TestResult[] results) |
||||
{ |
||||
if (results.Length > 0 && TestFinished != null) { |
||||
foreach (TestResult result in results) { |
||||
TestFinished(this, new TestFinishedEventArgs(result)); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Reads the text added to the end of the file from the last
|
||||
/// position we read from.
|
||||
/// </summary>
|
||||
string ReadTextAdded() |
||||
{ |
||||
StringBuilder text = null; |
||||
using (FileStream fs = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { |
||||
if (fs.Length > 0) { |
||||
text = new StringBuilder(); |
||||
int bytesRead = 0; |
||||
fs.Seek(filePosition, SeekOrigin.Begin); |
||||
do { |
||||
bytesRead = fs.Read(bytes, 0, BytesBufferLength); |
||||
if (bytesRead > 0) { |
||||
filePosition += bytesRead; |
||||
text.Append(UTF8Encoding.UTF8.GetString(bytes, 0, bytesRead)); |
||||
} |
||||
} while (bytesRead > 0 && filePosition < fs.Length); |
||||
} |
||||
} |
||||
if (text != null) { |
||||
return text.ToString(); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
void FileSystemWatcherError(object source, ErrorEventArgs e) |
||||
{ |
||||
Console.WriteLine(e.GetException().ToString()); |
||||
} |
||||
|
||||
void ResetFilePosition() |
||||
{ |
||||
filePosition = 3; // Use 3 to ignores UTF-8 preamble.
|
||||
} |
||||
} |
||||
} |
@ -0,0 +1,159 @@
@@ -0,0 +1,159 @@
|
||||
// <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.Text; |
||||
|
||||
namespace ICSharpCode.UnitTesting |
||||
{ |
||||
/// <summary>
|
||||
/// Reads the test results file produced by the custom
|
||||
/// nunit-console application.
|
||||
/// </summary>
|
||||
public class TestResultsReader |
||||
{ |
||||
StringBuilder nameBuilder = new StringBuilder(); |
||||
StringBuilder valueBuilder = new StringBuilder(); |
||||
bool firstNameChar = true; |
||||
TestResult result; |
||||
|
||||
enum State { |
||||
WaitingForEndOfName = 0, |
||||
WaitingForStartOfValue = 1, |
||||
WaitingForEndOfValue = 2 |
||||
} |
||||
|
||||
State state = State.WaitingForEndOfName; |
||||
|
||||
public TestResultsReader() |
||||
{ |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns any TestResults that are in the text.
|
||||
/// </summary>
|
||||
/// <param name="text">The text read in from the
|
||||
/// TestResults file.</param>
|
||||
public TestResult[] Read(string text) |
||||
{ |
||||
List<TestResult> results = new List<TestResult>(); |
||||
foreach (char ch in text) { |
||||
if (ReadNameValuePair(ch)) { |
||||
if (ReadTestResult()) { |
||||
results.Add(result); |
||||
} |
||||
} |
||||
} |
||||
return results.ToArray(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Reads a name-value pair of the form:
|
||||
///
|
||||
/// Name: Value
|
||||
///
|
||||
/// A value can span multiple lines:
|
||||
///
|
||||
/// Name1: ValueLine1
|
||||
/// {SP}ValueLine2
|
||||
/// {SP}ValueLine3
|
||||
/// Name1: Value2
|
||||
///
|
||||
/// Each continued line of the value must start with
|
||||
/// a single space character to distinguish it from
|
||||
/// the start of a new name-value pair.
|
||||
/// </summary>
|
||||
/// <returns>True if a name-value pair has been
|
||||
/// successfully read in</returns>
|
||||
bool ReadNameValuePair(char ch) |
||||
{ |
||||
if (state == State.WaitingForEndOfName) { |
||||
ReadNameChar(ch); |
||||
} else if (state == State.WaitingForStartOfValue) { |
||||
// Makes sure first space is ignored.
|
||||
state = State.WaitingForEndOfValue; |
||||
} else { |
||||
return ReadValueChar(ch); |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
void ReadNameChar(char ch) |
||||
{ |
||||
if (ch == ':') { |
||||
state = State.WaitingForStartOfValue; |
||||
} else if (ch == '\r' || ch == '\n') { |
||||
nameBuilder = new StringBuilder(); |
||||
} else if (ch == ' ' && firstNameChar) { |
||||
state = State.WaitingForEndOfValue; |
||||
valueBuilder.Append("\r\n"); |
||||
} else if (firstNameChar) { |
||||
firstNameChar = false; |
||||
nameBuilder = new StringBuilder(); |
||||
valueBuilder = new StringBuilder(); |
||||
nameBuilder.Append(ch); |
||||
} else { |
||||
nameBuilder.Append(ch); |
||||
} |
||||
} |
||||
|
||||
bool ReadValueChar(char ch) |
||||
{ |
||||
if (ch == '\r') { |
||||
// Ignore.
|
||||
} else if (ch == '\n') { |
||||
state = State.WaitingForEndOfName; |
||||
firstNameChar = true; |
||||
return true; |
||||
} else { |
||||
valueBuilder.Append(ch); |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Creates and updates a TestResult based on the
|
||||
/// name-value pair read in,
|
||||
/// </summary>
|
||||
/// <returns>True if a TestResult is ready to be returned
|
||||
/// to the caller.</returns>
|
||||
/// <remarks>
|
||||
/// The first name-value pair for a test result is the
|
||||
/// test name. The last name-value pair is the result of
|
||||
/// the test (Success, Failure or Ignored).</remarks>
|
||||
bool ReadTestResult() |
||||
{ |
||||
string name = nameBuilder.ToString(); |
||||
if (name == "Name") { |
||||
result = new TestResult(valueBuilder.ToString()); |
||||
} else if (result != null) { |
||||
if (name == "Message") { |
||||
result.Message = valueBuilder.ToString(); |
||||
} else if (name == "StackTrace") { |
||||
result.StackTrace = valueBuilder.ToString(); |
||||
} else if (name == "Result") { |
||||
UpdateTestSuccess(); |
||||
return true; |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
void UpdateTestSuccess() |
||||
{ |
||||
string value = valueBuilder.ToString(); |
||||
if (value =="Success") { |
||||
result.IsSuccess = true; |
||||
} else if (value == "Failure") { |
||||
result.IsFailure = true; |
||||
} else { |
||||
result.IsIgnored = true; |
||||
} |
||||
} |
||||
} |
||||
} |
@ -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.Gui; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
|
||||
namespace ICSharpCode.UnitTesting |
||||
{ |
||||
/// <summary>
|
||||
/// Base class for all test tree nodes.
|
||||
/// </summary>
|
||||
public abstract class TestTreeNode : ExtTreeNode |
||||
{ |
||||
TestProject testProject; |
||||
|
||||
public event EventHandler ImageIndexChanged; |
||||
|
||||
public TestTreeNode(TestProject testProject, string text) |
||||
{ |
||||
this.testProject = testProject; |
||||
this.Text = text; |
||||
ImageIndex = (int)TestTreeViewImageListIndex.TestNotRun; |
||||
} |
||||
|
||||
public IProject Project { |
||||
get { |
||||
return testProject.Project; |
||||
} |
||||
} |
||||
|
||||
public TestProject TestProject { |
||||
get { |
||||
return testProject; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Changes the node's icon based on the specified test result.
|
||||
/// </summary>
|
||||
protected void UpdateImageListIndex(TestResultType result) |
||||
{ |
||||
int previousImageIndex = ImageIndex; |
||||
switch (result) { |
||||
case TestResultType.Failure: |
||||
ImageIndex = (int)TestTreeViewImageListIndex.TestFailed; |
||||
break; |
||||
case TestResultType.Success: |
||||
ImageIndex = (int)TestTreeViewImageListIndex.TestPassed; |
||||
break; |
||||
case TestResultType.Ignored: |
||||
ImageIndex = (int)TestTreeViewImageListIndex.TestIgnored; |
||||
break; |
||||
case TestResultType.None: |
||||
ImageIndex = (int)TestTreeViewImageListIndex.TestNotRun; |
||||
break; |
||||
} |
||||
SelectedImageIndex = ImageIndex; |
||||
if (previousImageIndex != ImageIndex) { |
||||
OnImageIndexChanged(); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Raises the ImageIndexChanged event.
|
||||
/// </summary>
|
||||
protected void OnImageIndexChanged() |
||||
{ |
||||
if (ImageIndexChanged != null) { |
||||
ImageIndexChanged(this, new EventArgs()); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Checks all the child nodes of this node to see
|
||||
/// if the root namespace (i.e. the first part of the
|
||||
/// namespace) exists in the tree.
|
||||
/// </summary>
|
||||
/// <param name="rootNamespace">The first dotted part
|
||||
/// of the namespace.</param>
|
||||
protected bool NamespaceNodeExists(string rootNamespace) |
||||
{ |
||||
foreach (ExtTreeNode node in Nodes) { |
||||
TestNamespaceTreeNode namespaceNode = node as TestNamespaceTreeNode; |
||||
if (namespaceNode != null && namespaceNode.Text == rootNamespace) { |
||||
return true; |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
} |
||||
} |
@ -1,452 +1,259 @@
@@ -1,452 +1,259 @@
|
||||
// <file>
|
||||
// <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.IO; |
||||
using System.Windows.Forms; |
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using NUnit.Core; |
||||
using NUnit.UiKit; |
||||
using NUnit.Util; |
||||
|
||||
namespace ICSharpCode.UnitTesting |
||||
{ |
||||
public class TestTreeView : TestSuiteTreeView, IOwnerState |
||||
/// <summary>
|
||||
/// Tree view that shows all the unit tests in a project.
|
||||
/// </summary>
|
||||
public class TestTreeView : ExtTreeView, ITestTreeView, IOwnerState |
||||
{ |
||||
TestLoader loader = new TestLoader(); |
||||
static MessageViewCategory testRunnerCategory; |
||||
bool runningTests; |
||||
|
||||
/// <summary>
|
||||
/// The current state of the tree view.
|
||||
/// </summary>
|
||||
[Flags] |
||||
public enum TestTreeViewState { |
||||
Nothing = 0, |
||||
SourceCodeItemSelected = 1, |
||||
TestItemSelected = 2 |
||||
} |
||||
|
||||
System.Enum IOwnerState.InternalState { |
||||
get { |
||||
TestTreeViewState state = TestTreeViewState.Nothing; |
||||
UITestNode test = SelectedTest; |
||||
if (test != null) { |
||||
state |= TestTreeViewState.TestItemSelected; |
||||
if (test.IsTestCase || test.IsFixture) { |
||||
state |= TestTreeViewState.SourceCodeItemSelected; |
||||
} |
||||
} |
||||
return state; |
||||
} |
||||
} |
||||
|
||||
public static MessageViewCategory TestRunnerCategory { |
||||
get { |
||||
if (testRunnerCategory == null) { |
||||
testRunnerCategory = new MessageViewCategory("${res:ICSharpCode.NUnitPad.NUnitPadContent.PadName}"); |
||||
CompilerMessageView.Instance.AddCategory(testRunnerCategory); |
||||
} |
||||
return testRunnerCategory; |
||||
} |
||||
} |
||||
|
||||
void OnRunStarting() |
||||
{ |
||||
TaskService.ClearExceptCommentTasks(); |
||||
TestRunnerCategory.ClearText(); |
||||
PadDescriptor outputPad = WorkbenchSingleton.Workbench.GetPad(typeof(CompilerMessageView)); |
||||
outputPad.BringPadToFront(); |
||||
None = 0, |
||||
SourceCodeItemSelected = 1 |
||||
} |
||||
|
||||
public TestTreeView() |
||||
{ |
||||
loader.ReloadOnChange = false; |
||||
loader.ReloadOnRun = false; |
||||
loader.Events.TestLoadFailed += delegate(object sender, TestEventArgs e) { |
||||
TestRunnerCategory.AppendText("Loading " + e.Name + " failed: " + e.Exception.ToString()); |
||||
if (e.Exception is InvalidCastException && e.Exception.Message.Contains(typeof(AssemblyResolver).FullName)) { |
||||
MessageService.ShowMessage("Loading tests failed, make sure NUnit.Core is in the Global Assembly Cache."); |
||||
} else { |
||||
MessageService.ShowMessage("Loading " + e.Name + " failed: " + e.Exception.ToString()); |
||||
} |
||||
}; |
||||
loader.Events.TestLoaded += delegate(object sender, TestEventArgs e) { |
||||
WorkbenchSingleton.SafeThreadAsyncCall(UpdateProjectTitles); |
||||
}; |
||||
loader.Events.RunStarting += delegate(object sender, TestEventArgs e) { |
||||
WorkbenchSingleton.SafeThreadAsyncCall(OnRunStarting); |
||||
}; |
||||
loader.Events.TestOutput += delegate(object sender, TestEventArgs e) { |
||||
// This method interceps StdOut/StdErr from the tests
|
||||
TestRunnerCategory.AppendText(e.TestOutput.Text); |
||||
}; |
||||
loader.Events.RunFinished += delegate(object sender, TestEventArgs e) { |
||||
runningTests = false; |
||||
}; |
||||
loader.Events.TestFinished += delegate(object sender, TestEventArgs e) { |
||||
TestResult result = e.Result; |
||||
if (!result.IsSuccess) { |
||||
string outputMessage = StringParser.Parse("${res:NUnitPad.NUnitPadContent.TestTreeView.TestFailedMessage}", new string[,] { |
||||
{"TestCase", result.Test.FullName}, |
||||
{"Message", result.Message.Replace("\t", " ").Trim()} |
||||
}); |
||||
|
||||
TestRunnerCategory.AppendText(Environment.NewLine + outputMessage + Environment.NewLine); |
||||
if (!string.IsNullOrEmpty(result.Description)) { |
||||
TestRunnerCategory.AppendText(result.Description + Environment.NewLine); |
||||
} |
||||
TestRunnerCategory.AppendText(result.StackTrace + Environment.NewLine); |
||||
|
||||
AddTask(TaskType.Error, outputMessage, result.Test.FullName, result.StackTrace); |
||||
} else if (!result.Executed) { |
||||
string outputMessage = StringParser.Parse("${res:NUnitPad.NUnitPadContent.TestTreeView.TestNotExecutedMessage}", new string[,] { |
||||
{"TestCase", result.Test.FullName} |
||||
}); |
||||
|
||||
testRunnerCategory.AppendText(Environment.NewLine + outputMessage + Environment.NewLine); |
||||
testRunnerCategory.AppendText(result.Message + Environment.NewLine); |
||||
if (!string.IsNullOrEmpty(result.Description)) { |
||||
TestRunnerCategory.AppendText(result.Description + Environment.NewLine); |
||||
} |
||||
testRunnerCategory.AppendText(result.StackTrace + Environment.NewLine); |
||||
|
||||
AddTask(TaskType.Warning, outputMessage, result.Test.FullName, result.StackTrace); |
||||
} |
||||
}; |
||||
Initialize(loader, loader.Events); |
||||
this.ContextMenu = null; |
||||
this.ContextMenuStrip = MenuService.CreateContextMenu(this, "/SharpDevelop/Pads/UnitTestingPad/ContextMenu"); |
||||
ImageList = TestTreeViewImageList.ImageList; |
||||
} |
||||
|
||||
void UpdateProjectTitles() |
||||
{ |
||||
if (Nodes.Count == 0) |
||||
return; |
||||
TreeNode root = Nodes[0]; |
||||
root.Text = ProjectService.OpenSolution.Name; |
||||
foreach (TreeNode project in root.Nodes) { |
||||
if (Path.IsPathRooted(project.Text)) { |
||||
project.Text = Path.GetFileNameWithoutExtension(project.Text); |
||||
/// <summary>
|
||||
/// Gets the current state of the test tree view.
|
||||
/// </summary>
|
||||
public Enum InternalState { |
||||
get { |
||||
TestTreeNode selectedNode = SelectedNode as TestTreeNode; |
||||
if (selectedNode is TestClassTreeNode || selectedNode is TestMethodTreeNode) { |
||||
return TestTreeViewState.SourceCodeItemSelected; |
||||
} |
||||
return TestTreeViewState.None; |
||||
} |
||||
} |
||||
|
||||
static void AddTask(TaskType type, string message, string fullTestName, string stackTrace) |
||||
/// <summary>
|
||||
/// Adds the solution's projects to the test tree view.
|
||||
/// Only test projects are displayed.
|
||||
/// </summary>
|
||||
public void AddSolution(Solution solution) |
||||
{ |
||||
Task task = CreateTask(type, message, fullTestName, stackTrace); |
||||
if (task != null) { |
||||
WorkbenchSingleton.SafeThreadAsyncCall(TaskService.Add, task); |
||||
} |
||||
Clear(); |
||||
AddProjects(solution.Projects); |
||||
} |
||||
|
||||
internal static Task CreateTask(TaskType type, string message, string fullTestName, string stackTrace) |
||||
/// <summary>
|
||||
/// Adds the projects to the test tree view. Only those projects
|
||||
/// which are determined to have a reference to a supported
|
||||
/// test framework will be added to the tree.
|
||||
/// </summary>
|
||||
public void AddProjects(IEnumerable<IProject> projects) |
||||
{ |
||||
FileLineReference lineRef = OutputTextLineParser.GetNUnitOutputFileLineReference(stackTrace, true); |
||||
if (lineRef == null) { |
||||
lineRef = FindTest(fullTestName); |
||||
} |
||||
if (lineRef != null) { |
||||
return new Task(Path.GetFullPath(lineRef.FileName), |
||||
message, lineRef.Column, lineRef.Line, type); |
||||
} else { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
public void StopTests() |
||||
{ |
||||
loader.CancelTestRun(); |
||||
} |
||||
|
||||
public event TestEventHandler RunStarted { |
||||
add { loader.Events.RunStarting += value; } |
||||
remove { loader.Events.RunStarting -= value; } |
||||
} |
||||
|
||||
public event TestEventHandler RunFinished { |
||||
add { loader.Events.RunFinished += value; } |
||||
remove { loader.Events.RunFinished -= value; } |
||||
} |
||||
|
||||
public bool IsTestRunning { |
||||
get { |
||||
return runningTests; |
||||
foreach (IProject project in projects) { |
||||
AddProject(project); |
||||
} |
||||
} |
||||
|
||||
NUnitProject project; |
||||
|
||||
public void StartAddingAssemblies() |
||||
{ |
||||
project = NUnitProject.NewProject(); |
||||
project.ProjectPath = ProjectService.OpenSolution.Directory; |
||||
// assemblies outside the BasePath cannot be loaded by .NET, so use the root of the drive
|
||||
project.BasePath = Path.GetPathRoot(ProjectService.OpenSolution.Directory); |
||||
} |
||||
|
||||
public void FinishAddingAssemblies() |
||||
{ |
||||
loader.TestProject = project; |
||||
loader.LoadTest(); |
||||
project = null; |
||||
} |
||||
|
||||
public void AddAssembly(IProject sdProject, string assemblyFile) |
||||
/// <summary>
|
||||
/// Adds the project to the test tree view if the project
|
||||
/// has a reference to a supported test framework.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If the project is already in the tree then it will
|
||||
/// not be added again.
|
||||
/// </remarks>
|
||||
public void AddProject(IProject project) |
||||
{ |
||||
if (!File.Exists(assemblyFile)) { |
||||
TestRunnerCategory.AppendText(assemblyFile + " does not exist."); |
||||
return; |
||||
} |
||||
|
||||
#if DEBUG
|
||||
// NUnit uses cross thread calls.......
|
||||
System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false; |
||||
#endif
|
||||
|
||||
if (project != null) { |
||||
project.ActiveConfig.Assemblies.Add(assemblyFile); |
||||
} else { |
||||
if (!loader.IsProjectLoaded) { |
||||
StartAddingAssemblies(); |
||||
loader.TestProject = project; |
||||
project = null; |
||||
if (TestProject.IsTestProject(project)) { |
||||
if (GetProjectTreeNode(project) == null) { |
||||
// Add a new tree node.
|
||||
TestProject testProject = new TestProject(project, GetProjectContent(project)); |
||||
TestProjectTreeNode node = new TestProjectTreeNode(testProject); |
||||
node.AddTo(this); |
||||
|
||||
// Sort the nodes.
|
||||
SortNodes(Nodes, true); |
||||
} |
||||
|
||||
loader.TestProject.ActiveConfig.Assemblies.Add(assemblyFile); |
||||
} |
||||
} |
||||
|
||||
public void UnloadTestAssemblies() |
||||
{ |
||||
if (loader.IsProjectLoaded) { |
||||
loader.UnloadProject(); |
||||
} |
||||
} |
||||
|
||||
protected override void OnMouseDown(MouseEventArgs e) |
||||
/// <summary>
|
||||
/// Removes the specified project from the test tree view.
|
||||
/// </summary>
|
||||
public void RemoveProject(IProject project) |
||||
{ |
||||
if (e.Button == MouseButtons.Right) { |
||||
// required to run context menu commands on the correct item:
|
||||
this.SelectedNode = GetNodeAt(e.Location); |
||||
} |
||||
base.OnMouseDown(e); |
||||
} |
||||
|
||||
protected override void OnKeyPress(KeyPressEventArgs e) |
||||
{ |
||||
if (e.KeyChar == '\r') { |
||||
e.Handled = true; |
||||
GotoDefinition(); |
||||
} else if (e.KeyChar == ' ') { |
||||
e.Handled = true; |
||||
RunTests(); |
||||
} else { |
||||
base.OnKeyPress(e); |
||||
} |
||||
RemoveProjectNode(GetProjectTreeNode(project)); |
||||
} |
||||
|
||||
public void SelectTest(IProject project, IClass fixture, IMember test) |
||||
/// <summary>
|
||||
/// Gets the projects displayed in the tree.
|
||||
/// </summary>
|
||||
public IProject[] GetProjects() |
||||
{ |
||||
if (Nodes.Count == 0) { |
||||
return; |
||||
} |
||||
TreeNode root = Nodes[0]; |
||||
TreeNode nodeToSelect = null; |
||||
foreach (TreeNode projectNode in root.Nodes) { |
||||
if (projectNode.Text == project.Name) { |
||||
nodeToSelect = projectNode; |
||||
break; |
||||
} |
||||
List<IProject> projects = new List<IProject>(); |
||||
foreach (TestProjectTreeNode projectNode in Nodes) { |
||||
projects.Add(projectNode.Project); |
||||
} |
||||
if (nodeToSelect != null && fixture != null) { |
||||
// find fixture node
|
||||
TestSuiteTreeNode node = FindTest(nodeToSelect, fixture); |
||||
if (node != null) { |
||||
nodeToSelect = node; |
||||
if (test != null) { |
||||
node = FindTest(node, test); |
||||
if (node != null) { |
||||
nodeToSelect = node; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
this.SelectedNode = nodeToSelect; |
||||
return projects.ToArray(); |
||||
} |
||||
|
||||
TestSuiteTreeNode FindTest(TestSuiteTreeNode fixtureNode, IMember test) |
||||
/// <summary>
|
||||
/// Returns the TestProject associated with the specified project.
|
||||
/// </summary>
|
||||
public TestProject GetTestProject(IProject project) |
||||
{ |
||||
foreach (TestSuiteTreeNode node in fixtureNode.Nodes) { |
||||
if (node.Text == test.Name) |
||||
return node; |
||||
TestProjectTreeNode node = GetProjectTreeNode(project); |
||||
if (node != null) { |
||||
return node.TestProject; |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
TestSuiteTreeNode FindTest(TreeNode projectNode, IClass fixture) |
||||
{ |
||||
foreach (TreeNode node in projectNode.Nodes) { |
||||
TestSuiteTreeNode testNode = node as TestSuiteTreeNode; |
||||
if (testNode != null) { |
||||
if (testNode.Test.IsFixture) { |
||||
if (testNode.Test.FullName == fixture.FullyQualifiedName) |
||||
return testNode; |
||||
} else { |
||||
testNode = FindTest(testNode, fixture); |
||||
if (testNode != null) |
||||
return testNode; |
||||
} |
||||
/// <summary>
|
||||
/// Gets the method of the currently selected tree node.
|
||||
/// </summary>
|
||||
public IMember SelectedMethod { |
||||
get { |
||||
TestMethodTreeNode methodNode = SelectedNode as TestMethodTreeNode; |
||||
if (methodNode != null) { |
||||
return methodNode.Method; |
||||
} |
||||
return null; |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public new void RunTests() |
||||
{ |
||||
if (Nodes.Count > 0) { |
||||
runningTests = true; |
||||
base.RunTests(); |
||||
} |
||||
} |
||||
|
||||
protected override void OnDoubleClick(EventArgs e) |
||||
{ |
||||
GotoDefinition(); |
||||
} |
||||
|
||||
public void GotoDefinition() |
||||
{ |
||||
UITestNode node = SelectedTest; |
||||
if (node != null) { |
||||
FileLineReference lr = null; |
||||
if (node.IsFixture) { |
||||
lr = FindTest(node.FullName, null); |
||||
} else if (node.IsTestCase) { |
||||
lr = FindTest(node.FullName); |
||||
/// <summary>
|
||||
/// Gets the class of the currently selected tree node.
|
||||
/// </summary>
|
||||
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; |
||||
} |
||||
} |
||||
if (lr != null) { |
||||
FileService.JumpToFilePosition(lr.FileName, lr.Line, lr.Column); |
||||
|
||||
if (classNode != null) { |
||||
return classNode.Class; |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the project associated with the currently selected
|
||||
/// tree node.
|
||||
/// </summary>
|
||||
public IProject SelectedProject { |
||||
get { |
||||
IClass fixture = SelectedFixtureClass; |
||||
if (fixture != null) |
||||
return (IProject)fixture.ProjectContent.Project; |
||||
TreeNode node = SelectedNode; |
||||
if (node == null) |
||||
return null; |
||||
if (node.Level == 0 && node.Nodes.Count == 1) { |
||||
// solution node clicked, but has only 1 project
|
||||
node = node.Nodes[0]; |
||||
} |
||||
while (node.Level >= 2 && node.Parent.Nodes.Count == 1) { |
||||
// namespace node clicked, but project has only 1 namespace
|
||||
node = node.Parent; |
||||
} |
||||
if (node.Level == 1) { |
||||
foreach (IProject p in ProjectService.OpenSolution.Projects) { |
||||
if (Path.GetFileNameWithoutExtension(p.OutputAssemblyFullPath) == node.Text) { |
||||
return p; |
||||
} |
||||
} |
||||
TestProject testProject = SelectedTestProject; |
||||
if (testProject != null) { |
||||
return testProject.Project; |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
public IClass SelectedFixtureClass { |
||||
public TestProject SelectedTestProject { |
||||
get { |
||||
IMember member = SelectedTestMethod; |
||||
if (member != null) |
||||
return member.DeclaringType; |
||||
UITestNode node = SelectedTest; |
||||
if (node != null && node.IsFixture) { |
||||
foreach (IClass fixture in FindTestFixtures(node.FullName)) { |
||||
return fixture; |
||||
} |
||||
TestTreeNode selectedNode = SelectedNode as TestTreeNode; |
||||
if (selectedNode != null) { |
||||
return selectedNode.TestProject; |
||||
} |
||||
return null; |
||||
|
||||
} |
||||
} |
||||
|
||||
public IMember SelectedTestMethod { |
||||
get { |
||||
UITestNode node = SelectedTest; |
||||
if (node != null && node.IsTestCase) { |
||||
string fullMethodName = node.FullName; |
||||
int pos = fullMethodName.LastIndexOf('.'); |
||||
string shortName = fullMethodName.Substring(pos + 1); |
||||
foreach (IClass fixture in FindTestFixtures(fullMethodName.Substring(0, pos))) { |
||||
IMember m = FindTestMethod(fixture, shortName); |
||||
if (m != null) |
||||
return m; |
||||
} |
||||
} |
||||
return null; |
||||
/// <summary>
|
||||
/// Updates the classes and methods in the test tree view based on the
|
||||
/// parse information.
|
||||
/// </summary>
|
||||
public void UpdateParseInfo(ICompilationUnit oldUnit, ICompilationUnit newUnit) |
||||
{ |
||||
foreach (TestProjectTreeNode projectNode in Nodes) { |
||||
TestProject testProject = projectNode.TestProject; |
||||
testProject.UpdateParseInfo(oldUnit, newUnit); |
||||
} |
||||
} |
||||
|
||||
static FileLineReference FindTest(string fullMethodName) |
||||
/// <summary>
|
||||
/// Resets the test results for all the projects in the
|
||||
/// test tree view.
|
||||
/// </summary>
|
||||
public void ResetTestResults() |
||||
{ |
||||
int pos = fullMethodName.LastIndexOf('.'); |
||||
return FindTest(fullMethodName.Substring(0, pos), fullMethodName.Substring(pos + 1)); |
||||
foreach (TestProjectTreeNode projectNode in Nodes) { |
||||
TestProject testProject = projectNode.TestProject; |
||||
testProject.ResetTestResults(); |
||||
} |
||||
} |
||||
|
||||
static FileLineReference FindTest(string fixtureName, string methodName) |
||||
/// <summary>
|
||||
/// Returns the project content for the specified project.
|
||||
/// </summary>
|
||||
public virtual IProjectContent GetProjectContent(IProject project) |
||||
{ |
||||
if (fixtureName != null) { |
||||
List<IClass> fixtures = FindTestFixtures(fixtureName); |
||||
if (fixtures.Count > 0) { |
||||
if (methodName == null) { |
||||
// Go to fixture definition.
|
||||
IClass c = fixtures[0]; |
||||
if (c.CompilationUnit != null) { |
||||
return new FileLineReference(c.CompilationUnit.FileName, c.Region.BeginLine - 1, c.Region.BeginColumn - 1); |
||||
} |
||||
} else { |
||||
foreach (IClass c in fixtures) { |
||||
IMethod method = FindTestMethod(c, methodName); |
||||
if (method != null) { |
||||
return new FileLineReference(c.CompilationUnit.FileName, method.Region.BeginLine - 1, method.Region.BeginColumn - 1); |
||||
} |
||||
} |
||||
} |
||||
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); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
static List<IClass> FindTestFixtures(string fullName) |
||||
/// <summary>
|
||||
/// Returns the project tree node that is associated with the
|
||||
/// specified project.
|
||||
/// </summary>
|
||||
TestProjectTreeNode GetProjectTreeNode(IProject project) |
||||
{ |
||||
List<IClass> fixtures = new List<IClass>(); |
||||
if (ProjectService.OpenSolution != null) { |
||||
foreach (IProject project in ProjectService.OpenSolution.Projects) { |
||||
IProjectContent projectContent = ParserService.GetProjectContent(project); |
||||
if (projectContent != null) { |
||||
IClass c = projectContent.GetClass(fullName, 0, projectContent.Language, false); |
||||
if (c != null) { |
||||
fixtures.Add(c); |
||||
} |
||||
} |
||||
foreach (TestProjectTreeNode projectNode in Nodes) { |
||||
if (Object.ReferenceEquals(projectNode.Project, project)) { |
||||
return projectNode; |
||||
} |
||||
} |
||||
return fixtures; |
||||
return null; |
||||
} |
||||
|
||||
static IMethod FindTestMethod(IClass c, string name) |
||||
void RemoveProjectNode(TestProjectTreeNode projectNode) |
||||
{ |
||||
return c.Methods.Find(delegate(IMethod m) { return m.Name == name; }); |
||||
if (projectNode != null) { |
||||
projectNode.Remove(); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,60 @@
@@ -0,0 +1,60 @@
|
||||
// <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.Drawing; |
||||
using System.Reflection; |
||||
using System.Windows.Forms; |
||||
using ICSharpCode.Core; |
||||
|
||||
namespace ICSharpCode.UnitTesting |
||||
{ |
||||
public enum TestTreeViewImageListIndex |
||||
{ |
||||
TestNotRun = 0, |
||||
TestPassed = 1, |
||||
TestFailed = 2, |
||||
TestIgnored = 3 |
||||
} |
||||
|
||||
public class TestTreeViewImageList |
||||
{ |
||||
static ImageList imageList; |
||||
|
||||
TestTreeViewImageList() |
||||
{ |
||||
} |
||||
|
||||
public static ImageList ImageList { |
||||
get { |
||||
if (imageList == null) { |
||||
GetImageList(); |
||||
} |
||||
return imageList; |
||||
} |
||||
} |
||||
|
||||
static void GetImageList() |
||||
{ |
||||
imageList = new ImageList(); |
||||
imageList.ColorDepth = ColorDepth.Depth32Bit; |
||||
|
||||
AddBitmap("Grey.png"); |
||||
AddBitmap("Green.png"); |
||||
AddBitmap("Red.png"); |
||||
AddBitmap("Yellow.png"); |
||||
} |
||||
|
||||
static void AddBitmap(string name) |
||||
{ |
||||
string resourceName = String.Concat("ICSharpCode.UnitTesting.Resources.", name); |
||||
Assembly assembly = typeof(TestTreeViewImageList).Assembly; |
||||
imageList.Images.Add(new Bitmap(assembly.GetManifestResourceStream(resourceName))); |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,279 @@
@@ -0,0 +1,279 @@
|
||||
// <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.Windows.Forms; |
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
|
||||
namespace ICSharpCode.UnitTesting |
||||
{ |
||||
public class UnitTestsPad : AbstractPadContent |
||||
{ |
||||
TestTreeView treeView; |
||||
bool disposed; |
||||
Panel panel; |
||||
ToolStrip toolStrip; |
||||
List<ICompilationUnit[]> pending = new List<ICompilationUnit[]>(); |
||||
static UnitTestsPad instance; |
||||
|
||||
public UnitTestsPad() |
||||
{ |
||||
instance = this; |
||||
|
||||
panel = new Panel(); |
||||
treeView = CreateTestTreeView(); |
||||
treeView.Dock = DockStyle.Fill; |
||||
treeView.DoubleClick += TestTreeViewDoubleClick; |
||||
treeView.KeyPress += TestTreeViewKeyPress; |
||||
panel.Controls.Add(treeView); |
||||
|
||||
toolStrip = CreateToolStrip("/SharpDevelop/Pads/UnitTestsPad/Toolbar"); |
||||
toolStrip.GripStyle = ToolStripGripStyle.Hidden; |
||||
panel.Controls.Add(toolStrip); |
||||
|
||||
// Display currently open solution.
|
||||
Solution openSolution = ProjectService.OpenSolution; |
||||
if (openSolution != null) { |
||||
SolutionLoaded(openSolution); |
||||
} |
||||
|
||||
ParserService.LoadSolutionProjectsThreadEnded += LoadSolutionProjectsThreadEnded; |
||||
ParserService.ParseInformationUpdated += ParseInformationUpdated; |
||||
ProjectService.SolutionClosed += SolutionClosed; |
||||
ProjectService.SolutionFolderRemoved += SolutionFolderRemoved; |
||||
ProjectService.ProjectAdded += ProjectAdded; |
||||
ProjectService.ProjectItemAdded += ProjectItemAdded; |
||||
ProjectService.ProjectItemRemoved += ProjectItemRemoved; |
||||
|
||||
treeView.ContextMenuStrip = CreateContextMenu("/SharpDevelop/Pads/UnitTestsPad/ContextMenu"); |
||||
} |
||||
|
||||
public static UnitTestsPad Instance { |
||||
get { |
||||
return instance; |
||||
} |
||||
} |
||||
|
||||
public override Control Control { |
||||
get { |
||||
return panel; |
||||
} |
||||
} |
||||
|
||||
public override void Dispose() |
||||
{ |
||||
if (!disposed) { |
||||
disposed = true; |
||||
treeView.Dispose(); |
||||
treeView = null; |
||||
|
||||
ProjectService.ProjectItemRemoved -= ProjectItemRemoved; |
||||
ProjectService.ProjectItemAdded -= ProjectItemAdded; |
||||
ProjectService.ProjectAdded -= ProjectAdded; |
||||
ProjectService.SolutionFolderRemoved -= SolutionFolderRemoved; |
||||
ProjectService.SolutionClosed -= SolutionClosed; |
||||
ParserService.ParseInformationUpdated -= ParseInformationUpdated; |
||||
ParserService.LoadSolutionProjectsThreadEnded -= LoadSolutionProjectsThreadEnded; |
||||
} |
||||
} |
||||
|
||||
public TestTreeView TestTreeView { |
||||
get { |
||||
return treeView; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Updates the state of the buttons on the Unit Tests pad's
|
||||
/// toolbar.
|
||||
/// </summary>
|
||||
public void UpdateToolbar() |
||||
{ |
||||
ToolbarService.UpdateToolbar(toolStrip); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Called when a solution has been loaded.
|
||||
/// </summary>
|
||||
protected void SolutionLoaded(Solution solution) |
||||
{ |
||||
treeView.AddSolution(solution); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Called when a solution has been closed.
|
||||
/// </summary>
|
||||
protected void SolutionClosed() |
||||
{ |
||||
treeView.Clear(); |
||||
} |
||||
|
||||
protected void SolutionFolderRemoved(ISolutionFolder solutionFolder) |
||||
{ |
||||
IProject project = solutionFolder as IProject; |
||||
if (project != null) { |
||||
treeView.RemoveProject(project); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// The project is added to the tree view only if it has a
|
||||
/// reference to a unit testing framework.
|
||||
/// </summary>
|
||||
protected void ProjectAdded(IProject project) |
||||
{ |
||||
treeView.AddProject(project); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// If the project item removed is a reference to a unit
|
||||
/// test framework then the project will be removed from the
|
||||
/// test tree.
|
||||
/// </summary>
|
||||
protected void ProjectItemRemoved(ProjectItem projectItem) |
||||
{ |
||||
if (IsTestFrameworkReferenceProjectItem(projectItem)) { |
||||
if (!TestProject.IsTestProject(projectItem.Project)) { |
||||
treeView.RemoveProject(projectItem.Project); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <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); |
||||
} |
||||
} |
||||
|
||||
protected void UpdateParseInfo(ICompilationUnit oldUnit, ICompilationUnit newUnit) |
||||
{ |
||||
treeView.UpdateParseInfo(oldUnit, newUnit); |
||||
} |
||||
|
||||
protected virtual ToolStrip CreateToolStrip(string name) |
||||
{ |
||||
return ToolbarService.CreateToolStrip(treeView, "/SharpDevelop/Pads/UnitTestsPad/Toolbar"); |
||||
} |
||||
|
||||
protected virtual ContextMenuStrip CreateContextMenu(string name) |
||||
{ |
||||
return MenuService.CreateContextMenu(treeView, "/SharpDevelop/Pads/UnitTestsPad/ContextMenu"); |
||||
} |
||||
|
||||
protected virtual TestTreeView CreateTestTreeView() |
||||
{ |
||||
return new TestTreeView(); |
||||
} |
||||
|
||||
void SolutionClosed(object source, EventArgs e) |
||||
{ |
||||
SolutionClosed(); |
||||
UpdateToolbar(); |
||||
} |
||||
|
||||
void SolutionFolderRemoved(object source, SolutionFolderEventArgs e) |
||||
{ |
||||
SolutionFolderRemoved(e.SolutionFolder); |
||||
UpdateToolbar(); |
||||
} |
||||
|
||||
void ProjectAdded(object source, ProjectEventArgs e) |
||||
{ |
||||
ProjectAdded(e.Project); |
||||
UpdateToolbar(); |
||||
} |
||||
|
||||
void LoadSolutionProjectsThreadEnded(object source, EventArgs e) |
||||
{ |
||||
WorkbenchSingleton.SafeThreadAsyncCall(UpdateToolbar); |
||||
Solution solution = ProjectService.OpenSolution; |
||||
WorkbenchSingleton.SafeThreadAsyncCall(SolutionLoaded, solution); |
||||
} |
||||
|
||||
void ParseInformationUpdated(object source, ParseInformationEventArgs e) |
||||
{ |
||||
lock (pending) { |
||||
ICompilationUnit[] units = new ICompilationUnit[] {e.ParseInformation.BestCompilationUnit as ICompilationUnit, e.CompilationUnit}; |
||||
pending.Add(units); |
||||
} |
||||
WorkbenchSingleton.SafeThreadAsyncCall(UpdateParseInfo); |
||||
} |
||||
|
||||
void UpdateParseInfo() |
||||
{ |
||||
lock (pending) { |
||||
foreach (ICompilationUnit[] units in pending) { |
||||
UpdateParseInfo(units[0], units[1]); |
||||
} |
||||
pending.Clear(); |
||||
} |
||||
} |
||||
|
||||
void TestTreeViewDoubleClick(object source, EventArgs e) |
||||
{ |
||||
GotoDefinition(); |
||||
} |
||||
|
||||
void TestTreeViewKeyPress(object source, KeyPressEventArgs e) |
||||
{ |
||||
if (e.KeyChar == '\r') { |
||||
e.Handled = true; |
||||
GotoDefinition(); |
||||
} else if (e.KeyChar == ' ') { |
||||
e.Handled = true; |
||||
RunTests(); |
||||
} |
||||
} |
||||
|
||||
void GotoDefinition() |
||||
{ |
||||
RunCommand(new GotoDefinitionCommand()); |
||||
} |
||||
|
||||
void RunTests() |
||||
{ |
||||
RunCommand(new RunTestInPadCommand()); |
||||
} |
||||
|
||||
void RunCommand(ICommand command) |
||||
{ |
||||
command.Owner = treeView; |
||||
command.Run(); |
||||
} |
||||
|
||||
bool IsTestFrameworkReferenceProjectItem(ProjectItem projectItem) |
||||
{ |
||||
ReferenceProjectItem referenceProjectItem = projectItem as ReferenceProjectItem; |
||||
if (referenceProjectItem != null) { |
||||
return TestProject.IsTestFrameworkReference(referenceProjectItem.Include); |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
void ProjectItemAdded(object source, ProjectItemEventArgs e) |
||||
{ |
||||
ProjectItemAdded(e.ProjectItem); |
||||
} |
||||
|
||||
void ProjectItemRemoved(object source, ProjectItemEventArgs e) |
||||
{ |
||||
ProjectItemRemoved(e.ProjectItem); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,31 @@
@@ -0,0 +1,31 @@
|
||||
using System.Reflection; |
||||
using System.Runtime.CompilerServices; |
||||
using System.Runtime.InteropServices; |
||||
|
||||
// Information about this assembly is defined by the following
|
||||
// attributes.
|
||||
//
|
||||
// change them to the information which is associated with the assembly
|
||||
// you compile.
|
||||
|
||||
[assembly: AssemblyTitle("UnitTesting.Tests")] |
||||
[assembly: AssemblyDescription("")] |
||||
[assembly: AssemblyConfiguration("")] |
||||
[assembly: AssemblyCompany("")] |
||||
[assembly: AssemblyProduct("UnitTesting.Tests")] |
||||
[assembly: AssemblyCopyright("")] |
||||
[assembly: AssemblyTrademark("")] |
||||
[assembly: AssemblyCulture("")] |
||||
|
||||
// This sets the default COM visibility of types in the assembly to invisible.
|
||||
// If you need to expose a type to COM, use [ComVisible(true)] on that type.
|
||||
[assembly: ComVisible(false)] |
||||
|
||||
// The assembly version has following format :
|
||||
//
|
||||
// Major.Minor.Build.Revision
|
||||
//
|
||||
// You can specify all values by your own or you can build default build and revision
|
||||
// numbers with the '*' character (the default):
|
||||
|
||||
[assembly: AssemblyVersion("2.0.0.1")] |
@ -0,0 +1,48 @@
@@ -0,0 +1,48 @@
|
||||
// <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.UnitTesting; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using UnitTesting.Tests.Utils; |
||||
|
||||
namespace UnitTesting.Tests.Project |
||||
{ |
||||
/// <summary>
|
||||
/// Tests the TestClass.RootNamespace property.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class ClassRootNamespaceTests |
||||
{ |
||||
[Test] |
||||
public void OneParentNamespace() |
||||
{ |
||||
MockClass mockClass = new MockClass("TestRootNamespace.MyFixture"); |
||||
mockClass.Namespace = "TestRootNamespace"; |
||||
TestClass testClass = new TestClass(mockClass); |
||||
Assert.AreEqual("TestRootNamespace", testClass.RootNamespace); |
||||
} |
||||
|
||||
[Test] |
||||
public void TwoParentNamespaces() |
||||
{ |
||||
MockClass mockClass = new MockClass("TestRootNamespace.Tests.MyFixture"); |
||||
mockClass.Namespace = "TestRootNamespace.Tests"; |
||||
TestClass testClass = new TestClass(mockClass); |
||||
Assert.AreEqual("TestRootNamespace", testClass.RootNamespace); |
||||
} |
||||
|
||||
[Test] |
||||
public void NoNamespace() |
||||
{ |
||||
MockClass mockClass = new MockClass("MyFixture"); |
||||
mockClass.Namespace = String.Empty; |
||||
TestClass testClass = new TestClass(mockClass); |
||||
Assert.AreEqual(String.Empty, testClass.RootNamespace); |
||||
} |
||||
} |
||||
} |
@ -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.UnitTesting; |
||||
using NUnit.Framework; |
||||
using UnitTesting.Tests.Utils; |
||||
|
||||
namespace UnitTesting.Tests.Project |
||||
{ |
||||
[TestFixture] |
||||
public class ClassWithTwoChildNamespacesTestsFixture |
||||
{ |
||||
TestClass c; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
MockClass mockClass = new MockClass("UnitTesting.Tests.MyTestFixture"); |
||||
c = new TestClass(mockClass); |
||||
} |
||||
|
||||
[Test] |
||||
public void FullNamespace() |
||||
{ |
||||
Assert.AreEqual("UnitTesting.Tests", c.GetChildNamespace(String.Empty)); |
||||
} |
||||
|
||||
[Test] |
||||
public void FirstChildNamespace() |
||||
{ |
||||
Assert.AreEqual("Tests", c.GetChildNamespace("UnitTesting")); |
||||
} |
||||
|
||||
[Test] |
||||
public void EmptyChildNamespace() |
||||
{ |
||||
Assert.AreEqual(String.Empty, c.GetChildNamespace("UnitTesting.Tests")); |
||||
} |
||||
|
||||
[Test] |
||||
public void UnknownChildNamespace() |
||||
{ |
||||
Assert.AreEqual(String.Empty, c.GetChildNamespace("NotKnown")); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,76 @@
@@ -0,0 +1,76 @@
|
||||
// <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; |
||||
using ICSharpCode.UnitTesting; |
||||
using NUnit.Framework; |
||||
using UnitTesting.Tests.Utils; |
||||
|
||||
namespace UnitTesting.Tests.Project |
||||
{ |
||||
/// <summary>
|
||||
/// Tests that the TestProject can handle the user
|
||||
/// opening a project with two test classes with the same
|
||||
/// fully qualified name.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class DuplicateClassNameTestFixture |
||||
{ |
||||
TestProject testProject; |
||||
MSBuildProject project; |
||||
MockProjectContent projectContent; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
// Create a project to display.
|
||||
project = new MSBuildProject(); |
||||
project.Name = "TestProject"; |
||||
ReferenceProjectItem nunitFrameworkReferenceItem = new ReferenceProjectItem(project); |
||||
nunitFrameworkReferenceItem.Include = "NUnit.Framework"; |
||||
project.Items.Add(nunitFrameworkReferenceItem); |
||||
|
||||
// Add a test class.
|
||||
projectContent = new MockProjectContent(); |
||||
projectContent.Language = LanguageProperties.None; |
||||
MockClass c = new MockClass("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; |
||||
secondTestClass.Attributes.Add(new MockAttribute("TestFixture")); |
||||
projectContent.Classes.Add(secondTestClass); |
||||
|
||||
testProject = new TestProject(project, projectContent); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// If one or more classes exist with the same fully qualified
|
||||
/// name only one should be added to the test project. The
|
||||
/// project will not compile anyway due to the duplicate class
|
||||
/// name so only having one test class is probably an OK
|
||||
/// workaround.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void OneTestClass() |
||||
{ |
||||
Assert.AreEqual(1, testProject.TestClasses.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestClassName() |
||||
{ |
||||
Assert.AreEqual("RootNamespace.MyTestFixture", testProject.TestClasses[0].QualifiedName); |
||||
} |
||||
} |
||||
} |
@ -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 ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using ICSharpCode.UnitTesting; |
||||
using NUnit.Framework; |
||||
using UnitTesting.Tests.Utils; |
||||
|
||||
namespace UnitTesting.Tests.Project |
||||
{ |
||||
/// <summary>
|
||||
/// Tests that the TestProject can handle a test class that
|
||||
/// has two test methods with the same name.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class DuplicateMethodNameTestFixture |
||||
{ |
||||
TestClass testClass; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
// Add a test class.
|
||||
MockProjectContent projectContent = new MockProjectContent(); |
||||
projectContent.Language = LanguageProperties.None; |
||||
MockClass c = new MockClass("RootNamespace.MyTestFixture"); |
||||
c.Attributes.Add(new MockAttribute("TestFixture")); |
||||
c.ProjectContent = projectContent; |
||||
projectContent.Classes.Add(c); |
||||
|
||||
// Add first method.
|
||||
MockMethod method = new MockMethod("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"); |
||||
baseClass.Attributes.Add(new MockAttribute("TestFixture")); |
||||
baseClass.ProjectContent = projectContent; |
||||
projectContent.Classes.Add(baseClass); |
||||
c.BaseClass = baseClass; |
||||
baseClass.Methods.Add(method); |
||||
baseClass.Methods.Add(method); |
||||
|
||||
// Create test class.
|
||||
testClass = new TestClass(c); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Two test methods.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void TwoTestMethods() |
||||
{ |
||||
Assert.AreEqual(2, testClass.TestMethods.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestMethodName() |
||||
{ |
||||
Assert.AreEqual("MyTest", testClass.TestMethods[0].Name); |
||||
} |
||||
|
||||
[Test] |
||||
public void BaseClassTestMethodName() |
||||
{ |
||||
Assert.AreEqual("MyTestFixtureBase.MyTest", testClass.TestMethods[1].Name); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,75 @@
@@ -0,0 +1,75 @@
|
||||
// <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 UnitTesting.Tests.Utils; |
||||
|
||||
namespace UnitTesting.Tests.Project |
||||
{ |
||||
/// <summary>
|
||||
/// Tests that only one root namespace is returned when two
|
||||
/// classes contain the same root namespace.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class DuplicateProjectRootNamespaceTestFixture |
||||
{ |
||||
TestProject testProject; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
// Create a project.
|
||||
MSBuildProject project = new MSBuildProject(); |
||||
project.Name = "TestProject"; |
||||
ReferenceProjectItem nunitFrameworkReferenceItem = new ReferenceProjectItem(project); |
||||
nunitFrameworkReferenceItem.Include = "NUnit.Framework"; |
||||
project.Items.Add(nunitFrameworkReferenceItem); |
||||
|
||||
// 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"; |
||||
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.Attributes.Add(new MockAttribute("TestFixture")); |
||||
c.ProjectContent = projectContent; |
||||
projectContent.Classes.Add(c); |
||||
|
||||
testProject = new TestProject(project, projectContent); |
||||
} |
||||
|
||||
[Test] |
||||
public void OneRootNamespace() |
||||
{ |
||||
Assert.AreEqual(1, testProject.RootNamespaces.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void RootNamespace() |
||||
{ |
||||
Assert.AreEqual("RootNamespace", testProject.RootNamespaces[0]); |
||||
} |
||||
|
||||
[Test] |
||||
public void OneChildNamespacesForEmptyNamespace() |
||||
{ |
||||
string[] namespaces = testProject.GetChildNamespaces(String.Empty); |
||||
Assert.AreEqual(1, namespaces.Length); |
||||
Assert.AreEqual("RootNamespace", namespaces[0]); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,130 @@
@@ -0,0 +1,130 @@
|
||||
// <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 UnitTesting.Tests.Utils; |
||||
|
||||
namespace UnitTesting.Tests.Project |
||||
{ |
||||
/// <summary>
|
||||
/// Creates a TestProject object with no test classes.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class EmptyProjectTestFixture |
||||
{ |
||||
TestProject testProject; |
||||
MockProjectContent projectContent; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
// Create a project to display.
|
||||
MSBuildProject project = new MSBuildProject(); |
||||
project.Name = "TestProject"; |
||||
ReferenceProjectItem nunitFrameworkReferenceItem = new ReferenceProjectItem(project); |
||||
nunitFrameworkReferenceItem.Include = "NUnit.Framework"; |
||||
project.Items.Add(nunitFrameworkReferenceItem); |
||||
|
||||
projectContent = new MockProjectContent(); |
||||
projectContent.Language = LanguageProperties.None; |
||||
|
||||
testProject = new TestProject(project, projectContent); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Tests that a new class is added to the TestProject
|
||||
/// from the parse info when the old compilation unit is null.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void NewClassInParserInfo() |
||||
{ |
||||
// Create new compilation unit with extra class.
|
||||
DefaultCompilationUnit newUnit = new DefaultCompilationUnit(projectContent); |
||||
MockClass newClass = new MockClass("RootNamespace.MyNewTestFixture"); |
||||
newClass.Attributes.Add(new MockAttribute("TestFixture")); |
||||
newClass.ProjectContent = projectContent; |
||||
newClass.SetCompoundClass(newClass); |
||||
newUnit.Classes.Add(newClass); |
||||
|
||||
// Update TestProject's parse info.
|
||||
testProject.UpdateParseInfo(null, newUnit); |
||||
|
||||
Assert.IsTrue(testProject.TestClasses.Contains("RootNamespace.MyNewTestFixture")); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// The class exists in both the old compilation unit and the
|
||||
/// new compilation unit, but in the new compilation unit
|
||||
/// it has an added [TestFixture] attribute.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void TestFixtureAttributeAdded() |
||||
{ |
||||
// 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); |
||||
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.Attributes.Add(new MockAttribute("TestFixture")); |
||||
newClass.ProjectContent = projectContent; |
||||
newClass.SetCompoundClass(newClass); |
||||
newUnit.Classes.Add(newClass); |
||||
|
||||
// Update TestProject's parse info.
|
||||
testProject.UpdateParseInfo(oldUnit, newUnit); |
||||
|
||||
Assert.IsTrue(testProject.TestClasses.Contains("RootNamespace.MyNewTestFixture"), |
||||
"New class should have been added to the set of TestClasses."); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// The class exists in both the old compilation unit and the
|
||||
/// new compilation unit, but in the new compilation unit
|
||||
/// the [TestFixture] attribute has been removed.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void TestFixtureAttributeRemoved() |
||||
{ |
||||
// Add the test class first.
|
||||
TestFixtureAttributeAdded(); |
||||
|
||||
// Create an old compilation unit with the test class
|
||||
// having a [TestFixture] attribute.
|
||||
DefaultCompilationUnit oldUnit = new DefaultCompilationUnit(projectContent); |
||||
MockClass newClass = new MockClass("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); |
||||
newUnit.Classes.Add(newClass); |
||||
|
||||
// Update TestProject's parse info.
|
||||
testProject.UpdateParseInfo(oldUnit, newUnit); |
||||
|
||||
Assert.IsFalse(testProject.TestClasses.Contains("RootNamespace.MyNewTestFixture"), |
||||
"Class should have been removed."); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,75 @@
@@ -0,0 +1,75 @@
|
||||
// <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 UnitTesting.Tests.Utils; |
||||
|
||||
namespace UnitTesting.Tests.Project |
||||
{ |
||||
/// <summary>
|
||||
/// Tests that only one root namespace is returned when one class
|
||||
/// does not have a root namespace.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class EmptyRootNamespaceTestFixture |
||||
{ |
||||
TestProject testProject; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
// Create a project to display in the test tree view.
|
||||
MSBuildProject project = new MSBuildProject(); |
||||
project.Name = "TestProject"; |
||||
ReferenceProjectItem nunitFrameworkReferenceItem = new ReferenceProjectItem(project); |
||||
nunitFrameworkReferenceItem.Include = "NUnit.Framework"; |
||||
project.Items.Add(nunitFrameworkReferenceItem); |
||||
|
||||
// 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"; |
||||
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.Attributes.Add(new MockAttribute("TestFixture")); |
||||
c.ProjectContent = projectContent; |
||||
projectContent.Classes.Add(c); |
||||
|
||||
testProject = new TestProject(project, projectContent); |
||||
} |
||||
|
||||
[Test] |
||||
public void OneRootNamespace() |
||||
{ |
||||
Assert.AreEqual(1, testProject.RootNamespaces.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void RootNamespace() |
||||
{ |
||||
Assert.AreEqual("RootNamespace", testProject.RootNamespaces[0]); |
||||
} |
||||
|
||||
[Test] |
||||
public void EmptyNamespaceClass() |
||||
{ |
||||
TestClass[] classes = testProject.GetTestClasses(String.Empty); |
||||
Assert.AreEqual(1, classes.Length); |
||||
Assert.AreEqual("MyTestFixture2", classes[0].Name); |
||||
} |
||||
} |
||||
} |
@ -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.UnitTesting; |
||||
using NUnit.Framework; |
||||
|
||||
namespace UnitTesting.Tests.Project |
||||
{ |
||||
/// <summary>
|
||||
/// Tests TestMethod.GetMethodName.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class MethodNameTests |
||||
{ |
||||
[Test] |
||||
public void RootNamespaceClass() |
||||
{ |
||||
string qualifiedName = "RootNamespace.TestFixture.Method"; |
||||
Assert.AreEqual("Method", TestMethod.GetMethodName(qualifiedName)); |
||||
} |
||||
|
||||
[Test] |
||||
public void NullName() |
||||
{ |
||||
Assert.IsNull(TestMethod.GetMethodName(null)); |
||||
} |
||||
|
||||
[Test] |
||||
public void NoClassOrNamespace() |
||||
{ |
||||
Assert.IsNull(TestMethod.GetMethodName("Method")); |
||||
} |
||||
} |
||||
} |
@ -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 ICSharpCode.UnitTesting; |
||||
using NUnit.Framework; |
||||
|
||||
namespace UnitTesting.Tests.Project |
||||
{ |
||||
/// <summary>
|
||||
/// Tests TestMethod.GetQualifiedClassName.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class GetQualifiedClassNameTests |
||||
{ |
||||
[Test] |
||||
public void GetClassName() |
||||
{ |
||||
string name = "RootNamespace.ClassName.Method"; |
||||
Assert.AreEqual("RootNamespace.ClassName", TestMethod.GetQualifiedClassName(name)); |
||||
} |
||||
|
||||
[Test] |
||||
public void NoRootNamespace() |
||||
{ |
||||
string name = "ClassName.Method"; |
||||
Assert.AreEqual("ClassName", TestMethod.GetQualifiedClassName(name)); |
||||
} |
||||
|
||||
[Test] |
||||
public void OnlyMethod() |
||||
{ |
||||
string name = "Method"; |
||||
Assert.IsNull(TestMethod.GetQualifiedClassName(name)); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,116 @@
@@ -0,0 +1,116 @@
|
||||
// <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.Project |
||||
{ |
||||
/// <summary>
|
||||
/// Tests the TestClass.IsTestClass method.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class IsTestClassTests |
||||
{ |
||||
[Test] |
||||
public void HasNoAttributes() |
||||
{ |
||||
MockClass mockClass = CreateMockClass(); |
||||
Assert.IsFalse(TestClass.IsTestClass(mockClass)); |
||||
} |
||||
|
||||
[Test] |
||||
public void HasTestFixtureAttribute() |
||||
{ |
||||
List<MockAttribute> attributes = new List<MockAttribute>(); |
||||
attributes.Add(new MockAttribute("TestFixture")); |
||||
MockClass mockClass = CreateMockClass(attributes); |
||||
Assert.IsTrue(TestClass.IsTestClass(mockClass)); |
||||
} |
||||
|
||||
[Test] |
||||
public void HasTestFixtureAttributeAttribute() |
||||
{ |
||||
List<MockAttribute> attributes = new List<MockAttribute>(); |
||||
attributes.Add(new MockAttribute("TestFixtureAttribute")); |
||||
MockClass mockClass = CreateMockClass(attributes); |
||||
Assert.IsTrue(TestClass.IsTestClass(mockClass)); |
||||
} |
||||
|
||||
[Test] |
||||
public void HasNUnitTestFixtureAttribute() |
||||
{ |
||||
List<MockAttribute> attributes = new List<MockAttribute>(); |
||||
attributes.Add(new MockAttribute("NUnit.Framework.TestFixtureAttribute")); |
||||
MockClass mockClass = CreateMockClass(attributes); |
||||
Assert.IsTrue(TestClass.IsTestClass(mockClass)); |
||||
} |
||||
|
||||
[Test] |
||||
public void NullClass() |
||||
{ |
||||
Assert.IsFalse(TestClass.IsTestClass(null)); |
||||
} |
||||
|
||||
[Test] |
||||
public void NullLanguage() |
||||
{ |
||||
MSBuildProject project = new MSBuildProject(); |
||||
MockClass mockClass = new MockClass(); |
||||
MockProjectContent mockProjectContent = new MockProjectContent(); |
||||
mockProjectContent.Project = project; |
||||
mockClass.ProjectContent = mockProjectContent; |
||||
|
||||
Assert.IsFalse(TestClass.IsTestClass(mockClass)); |
||||
} |
||||
|
||||
[Test] |
||||
public void NullNameComparer() |
||||
{ |
||||
MSBuildProject project = new MSBuildProject(); |
||||
MockClass mockClass = new MockClass(); |
||||
MockProjectContent mockProjectContent = new MockProjectContent(); |
||||
mockProjectContent.Project = project; |
||||
mockProjectContent.Language = new LanguageProperties(null); |
||||
mockClass.ProjectContent = mockProjectContent; |
||||
mockClass.Attributes.Add(new MockAttribute("Test")); |
||||
|
||||
Assert.IsFalse(TestClass.IsTestClass(mockClass)); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetNameComparerWithNullClass() |
||||
{ |
||||
Assert.IsNull(TestClass.GetNameComparer(null)); |
||||
} |
||||
|
||||
static MockClass CreateMockClass() |
||||
{ |
||||
return CreateMockClass(new MockAttribute[0]); |
||||
} |
||||
|
||||
static MockClass CreateMockClass(IList<MockAttribute> attributes) |
||||
{ |
||||
MockClass mockClass = new MockClass(); |
||||
MockProjectContent mockProjectContent = new MockProjectContent(); |
||||
mockProjectContent.Language = LanguageProperties.None; |
||||
mockProjectContent.Project = new MSBuildProject(); |
||||
mockClass.ProjectContent = mockProjectContent; |
||||
|
||||
foreach (MockAttribute attribute in attributes) { |
||||
mockClass.Attributes.Add(attribute); |
||||
} |
||||
|
||||
return mockClass; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,162 @@
@@ -0,0 +1,162 @@
|
||||
// <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.Project |
||||
{ |
||||
/// <summary>
|
||||
/// Tests the TestMethod.IsTestMethod method.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class IsTestMethodTests |
||||
{ |
||||
[Test] |
||||
public void HasNoAttributes() |
||||
{ |
||||
MockMethod mockMethod = CreateMockMethod(); |
||||
Assert.IsFalse(TestMethod.IsTestMethod(mockMethod)); |
||||
} |
||||
|
||||
[Test] |
||||
public void HasTestAttribute() |
||||
{ |
||||
List<MockAttribute> attributes = new List<MockAttribute>(); |
||||
attributes.Add(new MockAttribute("Test")); |
||||
MockMethod mockMethod = CreateMockMethod(attributes); |
||||
Assert.IsTrue(TestMethod.IsTestMethod(mockMethod)); |
||||
} |
||||
|
||||
[Test] |
||||
public void HasTestAttributeAttribute() |
||||
{ |
||||
List<MockAttribute> attributes = new List<MockAttribute>(); |
||||
attributes.Add(new MockAttribute("TestAttribute")); |
||||
MockMethod mockMethod = CreateMockMethod(attributes); |
||||
Assert.IsTrue(TestMethod.IsTestMethod(mockMethod)); |
||||
} |
||||
|
||||
[Test] |
||||
public void HasNUnitTestAttribute() |
||||
{ |
||||
List<MockAttribute> attributes = new List<MockAttribute>(); |
||||
attributes.Add(new MockAttribute("NUnit.Framework.TestAttribute")); |
||||
MockMethod mockMethod = CreateMockMethod(attributes); |
||||
Assert.IsTrue(TestMethod.IsTestMethod(mockMethod)); |
||||
} |
||||
|
||||
[Test] |
||||
public void NullAttributeName() |
||||
{ |
||||
List<MockAttribute> attributes = new List<MockAttribute>(); |
||||
attributes.Add(new MockAttribute(null)); |
||||
MockMethod mockMethod = CreateMockMethod(attributes); |
||||
Assert.IsFalse(TestMethod.IsTestMethod(mockMethod)); |
||||
} |
||||
|
||||
[Test] |
||||
public void NullMethod() |
||||
{ |
||||
Assert.IsFalse(TestMethod.IsTestMethod(null)); |
||||
} |
||||
|
||||
[Test] |
||||
public void NullNameComparer() |
||||
{ |
||||
MSBuildProject project = new MSBuildProject(); |
||||
MockClass mockClass = new MockClass(); |
||||
MockProjectContent mockProjectContent = new MockProjectContent(); |
||||
mockProjectContent.Project = project; |
||||
mockProjectContent.Language = new LanguageProperties(null); |
||||
mockClass.ProjectContent = mockProjectContent; |
||||
MockMethod mockMethod = new MockMethod(); |
||||
mockMethod.DeclaringType = mockClass; |
||||
mockMethod.Attributes.Add(new MockAttribute("Test")); |
||||
|
||||
Assert.IsFalse(TestMethod.IsTestMethod(mockMethod)); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Even if the project is null the method should be
|
||||
/// flagged as a TestMethod.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void NullProject() |
||||
{ |
||||
List<MockAttribute> attributes = new List<MockAttribute>(); |
||||
attributes.Add(new MockAttribute("Test")); |
||||
MockMethod mockMethod = CreateMockMethod(attributes); |
||||
MockProjectContent mockProjectContent = (MockProjectContent)mockMethod.DeclaringType.ProjectContent; |
||||
mockProjectContent.Project = null; |
||||
|
||||
Assert.IsTrue(TestMethod.IsTestMethod(mockMethod)); |
||||
} |
||||
|
||||
[Test] |
||||
public void NullDeclaringType() |
||||
{ |
||||
MockMethod mockMethod = new MockMethod(); |
||||
|
||||
Assert.IsFalse(TestMethod.IsTestMethod(mockMethod)); |
||||
} |
||||
|
||||
[Test] |
||||
public void NullLanguage() |
||||
{ |
||||
MSBuildProject project = new MSBuildProject(); |
||||
MockClass mockClass = new MockClass(); |
||||
MockProjectContent mockProjectContent = new MockProjectContent(); |
||||
mockProjectContent.Project = project; |
||||
mockClass.ProjectContent = mockProjectContent; |
||||
MockMethod mockMethod = new MockMethod(); |
||||
mockMethod.DeclaringType = mockClass; |
||||
|
||||
Assert.IsFalse(TestMethod.IsTestMethod(mockMethod)); |
||||
} |
||||
|
||||
[Test] |
||||
public void MethodHasParameters() |
||||
{ |
||||
List<MockAttribute> attributes = new List<MockAttribute>(); |
||||
attributes.Add(new MockAttribute("Test")); |
||||
MockMethod mockMethod = CreateMockMethod(attributes); |
||||
MockParameter mockParameter = new MockParameter(); |
||||
mockMethod.Parameters.Add(mockParameter); |
||||
|
||||
Assert.IsFalse(TestMethod.IsTestMethod(mockMethod)); |
||||
} |
||||
|
||||
static MockMethod CreateMockMethod() |
||||
{ |
||||
return CreateMockMethod(new MockAttribute[0]); |
||||
} |
||||
|
||||
static MockMethod CreateMockMethod(IList<MockAttribute> attributes) |
||||
{ |
||||
MockMethod mockMethod = new MockMethod(); |
||||
MockClass mockClass = new MockClass(); |
||||
MockProjectContent mockProjectContent = new MockProjectContent(); |
||||
mockProjectContent.Language = LanguageProperties.None; |
||||
MSBuildProject project = new MSBuildProject(); |
||||
mockProjectContent.Project = project; |
||||
mockClass.ProjectContent = mockProjectContent; |
||||
mockMethod.DeclaringType = mockClass; |
||||
|
||||
foreach (MockAttribute attribute in attributes) { |
||||
mockMethod.Attributes.Add(attribute); |
||||
} |
||||
|
||||
return mockMethod; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,79 @@
@@ -0,0 +1,79 @@
|
||||
// <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.Project; |
||||
using ICSharpCode.UnitTesting; |
||||
using NUnit.Framework; |
||||
using System; |
||||
|
||||
namespace UnitTesting.Tests.Project |
||||
{ |
||||
/// <summary>
|
||||
/// A project is considered to be a test project if it contains
|
||||
/// a reference to the NUnit.Framework assembly.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class IsTestProjectTests |
||||
{ |
||||
[Test] |
||||
public void ProjectWithNoReferences() |
||||
{ |
||||
MSBuildProject project = new MSBuildProject(); |
||||
Assert.IsFalse(TestProject.IsTestProject(project)); |
||||
} |
||||
|
||||
[Test] |
||||
public void ProjectWithNUnitFrameworkReference() |
||||
{ |
||||
MSBuildProject project = new MSBuildProject(); |
||||
ReferenceProjectItem referenceProjectItem = new ReferenceProjectItem(project); |
||||
referenceProjectItem.Include = "NUnit.Framework"; |
||||
project.Items.Add(referenceProjectItem); |
||||
|
||||
Assert.IsTrue(TestProject.IsTestProject(project)); |
||||
} |
||||
|
||||
[Test] |
||||
public void ProjectWithNUnitFrameworkReferenceCaseInsensitive() |
||||
{ |
||||
MSBuildProject project = new MSBuildProject(); |
||||
ReferenceProjectItem referenceProjectItem = new ReferenceProjectItem(project); |
||||
referenceProjectItem.Include = "nunit.framework"; |
||||
project.Items.Add(referenceProjectItem); |
||||
|
||||
Assert.IsTrue(TestProject.IsTestProject(project)); |
||||
} |
||||
|
||||
[Test] |
||||
public void ProjectWithNUnitFrameworkReferenceSpecificVersion() |
||||
{ |
||||
MSBuildProject project = new MSBuildProject(); |
||||
ReferenceProjectItem referenceProjectItem = new ReferenceProjectItem(project); |
||||
referenceProjectItem.Include = "NUnit.Framework, Version=2.2.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77"; |
||||
project.Items.Add(referenceProjectItem); |
||||
|
||||
Assert.IsTrue(TestProject.IsTestProject(project)); |
||||
} |
||||
|
||||
[Test] |
||||
public void NullReferenceName() |
||||
{ |
||||
MSBuildProject project = new MSBuildProject(); |
||||
ReferenceProjectItem referenceProjectItem = new ReferenceProjectItem(project); |
||||
referenceProjectItem.Include = null; |
||||
project.Items.Add(referenceProjectItem); |
||||
|
||||
Assert.IsFalse(TestProject.IsTestProject(project)); |
||||
} |
||||
|
||||
[Test] |
||||
public void NullProject() |
||||
{ |
||||
Assert.IsFalse(TestProject.IsTestProject(null)); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,219 @@
@@ -0,0 +1,219 @@
|
||||
// <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; |
||||
using ICSharpCode.UnitTesting; |
||||
using NUnit.Framework; |
||||
using UnitTesting.Tests.Utils; |
||||
|
||||
namespace UnitTesting.Tests.Project |
||||
{ |
||||
[TestFixture] |
||||
public class TestClassWithOneMethodTestFixture |
||||
{ |
||||
TestProject testProject; |
||||
TestClass testClass; |
||||
TestMethod testMethod; |
||||
bool resultChangedCalled; |
||||
MockProjectContent projectContent; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
resultChangedCalled = false; |
||||
MSBuildProject project = new MSBuildProject(); |
||||
project.Name = "TestProject"; |
||||
ReferenceProjectItem nunitFrameworkReferenceItem = new ReferenceProjectItem(project); |
||||
nunitFrameworkReferenceItem.Include = "NUnit.Framework"; |
||||
project.Items.Add(nunitFrameworkReferenceItem); |
||||
|
||||
projectContent = new MockProjectContent(); |
||||
projectContent.Language = LanguageProperties.None; |
||||
|
||||
MockClass mockClass = new MockClass("RootNamespace.Tests.MyTestFixture"); |
||||
mockClass.Namespace = "RootNamespace.Tests"; |
||||
mockClass.ProjectContent = projectContent; |
||||
mockClass.Attributes.Add(new MockAttribute("TestFixture")); |
||||
projectContent.Classes.Add(mockClass); |
||||
|
||||
// Add a method to the test class
|
||||
MockMethod mockMethod = new MockMethod("TestMethod"); |
||||
mockMethod.DeclaringType = mockClass; |
||||
mockMethod.Attributes.Add(new MockAttribute("Test")); |
||||
mockClass.Methods.Add(mockMethod); |
||||
|
||||
testProject = new TestProject(project, projectContent); |
||||
testClass = testProject.TestClasses[0]; |
||||
testMethod = testClass.TestMethods[0]; |
||||
} |
||||
|
||||
[Test] |
||||
public void OneMethod() |
||||
{ |
||||
Assert.AreEqual(1, testClass.TestMethods.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestMethodResult() |
||||
{ |
||||
Assert.AreEqual(TestResultType.None, testMethod.Result); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestFailed() |
||||
{ |
||||
TestResult result = new TestResult("RootNamespace.Tests.MyTestFixture.TestMethod"); |
||||
result.IsFailure = true; |
||||
|
||||
testProject.UpdateTestResult(result); |
||||
|
||||
Assert.AreEqual(TestResultType.Failure, testMethod.Result); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestClassFailed() |
||||
{ |
||||
TestFailed(); |
||||
Assert.AreEqual(TestResultType.Failure, testClass.Result); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestClassIgnored() |
||||
{ |
||||
TestResult result = new TestResult("RootNamespace.Tests.MyTestFixture.TestMethod"); |
||||
result.IsIgnored = true; |
||||
|
||||
testProject.UpdateTestResult(result); |
||||
|
||||
Assert.AreEqual(TestResultType.Ignored, testClass.Result); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestResultChanged() |
||||
{ |
||||
try { |
||||
testMethod.ResultChanged += ResultChanged; |
||||
TestResult result = new TestResult("RootNamespace.Tests.MyTestFixture.TestMethod"); |
||||
result.IsFailure = true; |
||||
testProject.UpdateTestResult(result); |
||||
} finally { |
||||
testMethod.ResultChanged -= ResultChanged; |
||||
} |
||||
|
||||
Assert.IsTrue(resultChangedCalled); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestResultChangedOnClass() |
||||
{ |
||||
try { |
||||
testClass.ResultChanged += ResultChanged; |
||||
TestResult result = new TestResult("RootNamespace.Tests.MyTestFixture.TestMethod"); |
||||
result.IsFailure = true; |
||||
testProject.UpdateTestResult(result); |
||||
} finally { |
||||
testClass.ResultChanged -= ResultChanged; |
||||
} |
||||
|
||||
Assert.IsTrue(resultChangedCalled); |
||||
} |
||||
|
||||
[Test] |
||||
public void UpdateProjectWithTestResultHavingClassNameOnly() |
||||
{ |
||||
TestResult result = new TestResult("ClassNameOnly"); |
||||
result.IsFailure = true; |
||||
|
||||
testProject.UpdateTestResult(result); |
||||
} |
||||
|
||||
[Test] |
||||
public void UpdateProjectWithTestResultWithUnknownClassName() |
||||
{ |
||||
TestResult result = new TestResult("RootNamespace.Tests.UnknownClassName.TestMethod"); |
||||
result.IsFailure = true; |
||||
|
||||
testProject.UpdateTestResult(result); |
||||
} |
||||
|
||||
[Test] |
||||
public void UpdateProjectWithTestResultWithUnknownMethodName() |
||||
{ |
||||
TestResult result = new TestResult("RootNamespace.Tests.MyTestFixture.UnknownMethodName"); |
||||
result.IsFailure = true; |
||||
|
||||
testProject.UpdateTestResult(result); |
||||
} |
||||
|
||||
[Test] |
||||
public void FindTestMethod() |
||||
{ |
||||
Assert.AreSame(testMethod, testClass.TestMethods["TestMethod"]); |
||||
} |
||||
|
||||
[Test] |
||||
public void AddNewClassNodeWhenTestClassPassed() |
||||
{ |
||||
testClass.Result = TestResultType.Success; |
||||
TestClassTreeNode node = new TestClassTreeNode(testProject, testClass); |
||||
Assert.AreEqual(TestTreeViewImageListIndex.TestPassed, (TestTreeViewImageListIndex)node.ImageIndex); |
||||
} |
||||
|
||||
[Test] |
||||
public void AddNewMethodNodeWhenTestPassed() |
||||
{ |
||||
testMethod.Result = TestResultType.Success; |
||||
TestMethodTreeNode node = new TestMethodTreeNode(testProject, testMethod); |
||||
Assert.AreEqual(TestTreeViewImageListIndex.TestPassed, (TestTreeViewImageListIndex)node.ImageIndex); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Tests that a method is removed from the TestClass
|
||||
/// based on the parse info. Also checks that the test methods are
|
||||
/// checked based on the CompoundClass via IClass.GetCompoundClass.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void MethodRemovedInParserInfo() |
||||
{ |
||||
// Create old compilation unit.
|
||||
DefaultCompilationUnit oldUnit = new DefaultCompilationUnit(projectContent); |
||||
oldUnit.Classes.Add(testClass.Class); |
||||
|
||||
// Create new compilation unit.
|
||||
DefaultCompilationUnit newUnit = new DefaultCompilationUnit(projectContent); |
||||
newUnit.Classes.Add(testClass.Class); |
||||
|
||||
// Add a new method to a new compound class.
|
||||
MockClass compoundClass = new MockClass("RootNamespace.MyTestFixture"); |
||||
compoundClass.ProjectContent = projectContent; |
||||
compoundClass.Attributes.Add(new MockAttribute("TestFixture")); |
||||
MockClass mockClass = (MockClass)testClass.Class; |
||||
mockClass.SetCompoundClass(compoundClass); |
||||
|
||||
// Monitor test methods removed.
|
||||
List<TestMethod> methodsRemoved = new List<TestMethod>(); |
||||
testClass.TestMethods.TestMethodRemoved += delegate(Object source, TestMethodEventArgs e) |
||||
{ methodsRemoved.Add(e.TestMethod); }; |
||||
|
||||
// Update TestProject's parse info.
|
||||
testProject.UpdateParseInfo(oldUnit, newUnit); |
||||
|
||||
Assert.IsFalse(testClass.TestMethods.Contains("TestMethod")); |
||||
Assert.AreEqual(1, methodsRemoved.Count); |
||||
Assert.AreSame(testMethod.Method, methodsRemoved[0].Method); |
||||
} |
||||
|
||||
void ResultChanged(object source, EventArgs e) |
||||
{ |
||||
resultChangedCalled = true; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,169 @@
@@ -0,0 +1,169 @@
|
||||
// <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; |
||||
using ICSharpCode.UnitTesting; |
||||
using NUnit.Framework; |
||||
using UnitTesting.Tests.Utils; |
||||
|
||||
namespace UnitTesting.Tests.Project |
||||
{ |
||||
[TestFixture] |
||||
public class TestClassWithTwoMethodsTestFixture |
||||
{ |
||||
TestProject testProject; |
||||
TestClass testClass; |
||||
TestMethod testMethod1; |
||||
TestMethod testMethod2; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
MSBuildProject project = new MSBuildProject(); |
||||
project.Name = "TestProject"; |
||||
ReferenceProjectItem nunitFrameworkReferenceItem = new ReferenceProjectItem(project); |
||||
nunitFrameworkReferenceItem.Include = "NUnit.Framework"; |
||||
project.Items.Add(nunitFrameworkReferenceItem); |
||||
|
||||
MockProjectContent projectContent = new MockProjectContent(); |
||||
projectContent.Language = LanguageProperties.None; |
||||
|
||||
MockClass mockClass = new MockClass("RootNamespace.Tests.MyTestFixture"); |
||||
mockClass.Namespace = "RootNamespace.Tests"; |
||||
mockClass.ProjectContent = projectContent; |
||||
mockClass.Attributes.Add(new MockAttribute("TestFixture")); |
||||
projectContent.Classes.Add(mockClass); |
||||
|
||||
// Add a method to the test class
|
||||
MockMethod mockMethod = new MockMethod("TestMethod1"); |
||||
mockMethod.DeclaringType = mockClass; |
||||
mockMethod.Attributes.Add(new MockAttribute("Test")); |
||||
mockClass.Methods.Add(mockMethod); |
||||
|
||||
mockMethod = new MockMethod("TestMethod2"); |
||||
mockMethod.DeclaringType = mockClass; |
||||
mockMethod.Attributes.Add(new MockAttribute("Test")); |
||||
mockClass.Methods.Add(mockMethod); |
||||
|
||||
testProject = new TestProject(project, projectContent); |
||||
testClass = testProject.TestClasses[0]; |
||||
testMethod1 = testClass.TestMethods[0]; |
||||
testMethod2 = testClass.TestMethods[1]; |
||||
} |
||||
|
||||
[Test] |
||||
public void TwoMethods() |
||||
{ |
||||
Assert.AreEqual(2, testClass.TestMethods.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestMethod1Failed() |
||||
{ |
||||
TestResult result = new TestResult("RootNamespace.Tests.MyTestFixture.TestMethod1"); |
||||
result.IsFailure = true; |
||||
|
||||
testProject.UpdateTestResult(result); |
||||
|
||||
Assert.AreEqual(TestResultType.Failure, testMethod1.Result); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestMethod1Ignored() |
||||
{ |
||||
TestResult result = new TestResult("RootNamespace.Tests.MyTestFixture.TestMethod1"); |
||||
result.IsIgnored = true; |
||||
|
||||
testProject.UpdateTestResult(result); |
||||
|
||||
Assert.AreEqual(TestResultType.Ignored, testMethod1.Result); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestClassResultAfterTestMethod1Failed() |
||||
{ |
||||
TestMethod1Failed(); |
||||
|
||||
Assert.AreEqual(TestResultType.Failure, testClass.Result); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestMethod1Passes() |
||||
{ |
||||
TestResult result = new TestResult("RootNamespace.Tests.MyTestFixture.TestMethod1"); |
||||
result.IsSuccess = true; |
||||
|
||||
testProject.UpdateTestResult(result); |
||||
|
||||
Assert.AreEqual(TestResultType.Success, testMethod1.Result); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestClassResultAfterTestMethod1Passes() |
||||
{ |
||||
TestMethod1Passes(); |
||||
|
||||
Assert.AreEqual(TestResultType.None, testClass.Result); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestMethod2Passes() |
||||
{ |
||||
TestResult result = new TestResult("RootNamespace.Tests.MyTestFixture.TestMethod2"); |
||||
result.IsSuccess = true; |
||||
|
||||
testProject.UpdateTestResult(result); |
||||
|
||||
Assert.AreEqual(TestResultType.Success, testMethod2.Result); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestClassResultAfterTestMethod2Passes() |
||||
{ |
||||
TestMethod2Passes(); |
||||
|
||||
Assert.AreEqual(TestResultType.None, testClass.Result); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestClassResultAfterBothMethodsPass() |
||||
{ |
||||
TestMethod1Passes(); |
||||
TestMethod2Passes(); |
||||
|
||||
Assert.AreEqual(TestResultType.Success, testClass.Result); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestClassResultAfterOneIgnoredAndOnePassed() |
||||
{ |
||||
TestMethod1Ignored(); |
||||
TestMethod2Passes(); |
||||
|
||||
Assert.AreEqual(TestResultType.Ignored, testClass.Result); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestClassResultAfterOneFailedAndOnePassed() |
||||
{ |
||||
TestMethod1Failed(); |
||||
TestMethod2Passes(); |
||||
|
||||
Assert.AreEqual(TestResultType.Failure, testClass.Result); |
||||
} |
||||
|
||||
[Test] |
||||
public void FindTestMethod() |
||||
{ |
||||
TestMethod method = testProject.TestClasses.GetTestMethod("RootNamespace.Tests.MyTestFixture.TestMethod1"); |
||||
Assert.AreSame(testMethod1, method); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,98 @@
@@ -0,0 +1,98 @@
|
||||
// <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 UnitTesting.Tests.Utils; |
||||
|
||||
namespace UnitTesting.Tests.Project |
||||
{ |
||||
/// <summary>
|
||||
/// If a test fixture's base class has test attributes then
|
||||
/// NUnit includes the base class test methods by prefixing
|
||||
/// the base class name to them.
|
||||
///
|
||||
/// [TestFixture]
|
||||
/// public DerivedClass : BaseClass
|
||||
///
|
||||
/// Fully qualified test method is named:
|
||||
///
|
||||
/// RootNamespace.DerivedClass.BaseClass.BaseClassMethod.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class TestMethodsInBaseClassTestFixture |
||||
{ |
||||
TestClass testClass; |
||||
|
||||
[SetUp] |
||||
public void SetUp() |
||||
{ |
||||
|
||||
MockProjectContent projectContent = new MockProjectContent(); |
||||
projectContent.Language = LanguageProperties.None; |
||||
|
||||
// Create the base test class.
|
||||
MockClass baseClass = new MockClass("RootNamespace.TestFixtureBase"); |
||||
baseClass.Attributes.Add(new MockAttribute("TestFixture")); |
||||
baseClass.ProjectContent = projectContent; |
||||
MockMethod baseMethod = new MockMethod("BaseMethod"); |
||||
baseMethod.Attributes.Add(new MockAttribute("Test")); |
||||
baseMethod.DeclaringType = baseClass; |
||||
baseClass.Methods.Add(baseMethod); |
||||
|
||||
// Create the derived test class.
|
||||
MockClass c = new MockClass("RootNamespace.MyTestFixture"); |
||||
c.Attributes.Add(new MockAttribute("TestFixture")); |
||||
c.ProjectContent = projectContent; |
||||
MockMethod method = new MockMethod("DerivedMethod"); |
||||
method.DeclaringType = c; |
||||
method.Attributes.Add(new MockAttribute("Test")); |
||||
c.Methods.Add(method); |
||||
projectContent.Classes.Add(c); |
||||
|
||||
// Set derived class's base class.
|
||||
c.BaseClass = baseClass; |
||||
|
||||
// Create TestClass.
|
||||
testClass = new TestClass(c); |
||||
} |
||||
|
||||
[Test] |
||||
public void TwoTestMethods() |
||||
{ |
||||
Assert.AreEqual(2, testClass.TestMethods.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void DerivedMethod() |
||||
{ |
||||
Assert.IsTrue(testClass.TestMethods.Contains("DerivedMethod")); |
||||
} |
||||
|
||||
[Test] |
||||
public void BaseMethod() |
||||
{ |
||||
Assert.IsTrue(testClass.TestMethods.Contains("TestFixtureBase.BaseMethod")); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetTestClass() |
||||
{ |
||||
TestClassCollection testClasses = new TestClassCollection(); |
||||
testClasses.Add(testClass); |
||||
|
||||
TestResult testResult = new TestResult("RootNamespace.MyTestFixture.TestFixtureBase.BaseMethod"); |
||||
testResult.IsFailure = true; |
||||
testClasses.UpdateTestResult(testResult); |
||||
|
||||
Assert.AreEqual(TestResultType.Failure, testClass.Result); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,354 @@
@@ -0,0 +1,354 @@
|
||||
// <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; |
||||
using ICSharpCode.UnitTesting; |
||||
using NUnit.Framework; |
||||
using UnitTesting.Tests.Utils; |
||||
|
||||
namespace UnitTesting.Tests.Project |
||||
{ |
||||
/// <summary>
|
||||
/// Creates a TestProject that has one test class.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class TestProjectWithOneClassTestFixture |
||||
{ |
||||
TestProject testProject; |
||||
TestClass testClass; |
||||
MSBuildProject project; |
||||
bool resultChangedCalled; |
||||
MockProjectContent projectContent; |
||||
List<TestClass> classesAdded; |
||||
List<TestClass> classesRemoved; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
resultChangedCalled = false; |
||||
classesAdded = new List<TestClass>(); |
||||
classesRemoved = new List<TestClass>(); |
||||
|
||||
// Create a project.
|
||||
project = new MSBuildProject(); |
||||
project.Name = "TestProject"; |
||||
ReferenceProjectItem nunitFrameworkReferenceItem = new ReferenceProjectItem(project); |
||||
nunitFrameworkReferenceItem.Include = "NUnit.Framework"; |
||||
project.Items.Add(nunitFrameworkReferenceItem); |
||||
|
||||
// Add a test class with a TestFixture attributes.
|
||||
projectContent = new MockProjectContent(); |
||||
projectContent.Language = LanguageProperties.None; |
||||
MockClass c = new MockClass("RootNamespace.MyTestFixture"); |
||||
c.SetCompoundClass(c); |
||||
c.Attributes.Add(new MockAttribute("TestFixture")); |
||||
c.ProjectContent = projectContent; |
||||
projectContent.Classes.Add(c); |
||||
|
||||
// Add a second class that has no test fixture attribute.
|
||||
MockClass nonTestClass = new MockClass(); |
||||
nonTestClass.ProjectContent = projectContent; |
||||
projectContent.Classes.Add(nonTestClass); |
||||
|
||||
testProject = new TestProject(project, projectContent); |
||||
testProject.TestClasses.TestClassAdded += TestClassAdded; |
||||
testProject.TestClasses.TestClassRemoved += TestClassRemoved; |
||||
|
||||
testClass = testProject.TestClasses[0]; |
||||
} |
||||
|
||||
[Test] |
||||
public void OneTestClass() |
||||
{ |
||||
Assert.AreEqual(1, testProject.TestClasses.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestProjectName() |
||||
{ |
||||
Assert.AreEqual("TestProject", testProject.Name); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestClassName() |
||||
{ |
||||
Assert.AreEqual("MyTestFixture", testClass.Name); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestClassQualifiedName() |
||||
{ |
||||
Assert.AreEqual("RootNamespace.MyTestFixture", testClass.QualifiedName); |
||||
} |
||||
|
||||
[Test] |
||||
public void OneRootNamespace() |
||||
{ |
||||
Assert.AreEqual(1, testProject.RootNamespaces.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void ProjectProperty() |
||||
{ |
||||
Assert.AreSame(project, testProject.Project); |
||||
} |
||||
|
||||
[Test] |
||||
public void FindTestClass() |
||||
{ |
||||
Assert.AreSame(testClass, testProject.TestClasses["RootNamespace.MyTestFixture"]); |
||||
} |
||||
|
||||
[Test] |
||||
public void NoMatchingTestClass() |
||||
{ |
||||
Assert.IsFalse(testProject.TestClasses.Contains("NoSuchClass.MyTestFixture")); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestClassResultChanged() |
||||
{ |
||||
try { |
||||
testClass.ResultChanged += ResultChanged; |
||||
testClass.Result = TestResultType.Success; |
||||
} finally { |
||||
testClass.ResultChanged -= ResultChanged; |
||||
} |
||||
|
||||
Assert.IsTrue(resultChangedCalled); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Tests that a new class is added to the TestProject
|
||||
/// from the parse info.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void NewClassInParserInfo() |
||||
{ |
||||
// Create old compilation unit.
|
||||
DefaultCompilationUnit oldUnit = new DefaultCompilationUnit(projectContent); |
||||
MockClass mockClass = (MockClass)testClass.Class; |
||||
mockClass.SetCompoundClass(mockClass); |
||||
oldUnit.Classes.Add(testClass.Class); |
||||
|
||||
// Create new compilation unit with extra class.
|
||||
DefaultCompilationUnit newUnit = new DefaultCompilationUnit(projectContent); |
||||
newUnit.Classes.Add(testClass.Class); |
||||
MockClass newClass = new MockClass("RootNamespace.MyNewTestFixture"); |
||||
newClass.Attributes.Add(new MockAttribute("TestFixture")); |
||||
newClass.ProjectContent = projectContent; |
||||
newClass.SetCompoundClass(newClass); |
||||
newUnit.Classes.Add(newClass); |
||||
|
||||
// Update TestProject's parse info.
|
||||
testProject.UpdateParseInfo(oldUnit, newUnit); |
||||
|
||||
Assert.IsTrue(testProject.TestClasses.Contains("RootNamespace.MyNewTestFixture")); |
||||
Assert.AreEqual(1, classesAdded.Count); |
||||
Assert.AreSame(newClass, classesAdded[0].Class); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Tests that the TestProject.UpdateParseInfo handles the
|
||||
/// case when the old compilation unit does not have a
|
||||
/// test class, the new compilation unit does have the
|
||||
/// test class, but the test class has already been
|
||||
/// added to our TestProject.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void TestClassInNewCompilationUnitOnly() |
||||
{ |
||||
// Create old compilation unit.
|
||||
DefaultCompilationUnit oldUnit = new DefaultCompilationUnit(projectContent); |
||||
|
||||
// Create new compilation unit with class that
|
||||
// already exists in the project.
|
||||
DefaultCompilationUnit newUnit = new DefaultCompilationUnit(projectContent); |
||||
newUnit.Classes.Add(testClass.Class); |
||||
MockClass c = new MockClass("RootNamespace.MyTestFixture"); |
||||
c.Attributes.Add(new MockAttribute("TestFixture")); |
||||
c.ProjectContent = projectContent; |
||||
c.SetCompoundClass(c); |
||||
newUnit.Classes.Add(c); |
||||
|
||||
// Update TestProject's parse info.
|
||||
testProject.UpdateParseInfo(oldUnit, newUnit); |
||||
|
||||
Assert.IsTrue(testProject.TestClasses.Contains("RootNamespace.MyTestFixture")); |
||||
Assert.AreEqual(0, classesAdded.Count); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// New class without a test fixture attribute should not
|
||||
/// be added to the list of test classes.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void NewClassInParserInfoWithoutTestFixtureAttribute() |
||||
{ |
||||
// Create old compilation unit.
|
||||
DefaultCompilationUnit oldUnit = new DefaultCompilationUnit(projectContent); |
||||
MockClass mockClass = (MockClass)testClass.Class; |
||||
mockClass.SetCompoundClass(mockClass); |
||||
oldUnit.Classes.Add(testClass.Class); |
||||
|
||||
// Create new compilation unit with extra class.
|
||||
DefaultCompilationUnit newUnit = new DefaultCompilationUnit(projectContent); |
||||
newUnit.Classes.Add(testClass.Class); |
||||
MockClass newClass = new MockClass("RootNamespace.MyNewTestFixture"); |
||||
newClass.ProjectContent = projectContent; |
||||
newClass.SetCompoundClass(newClass); |
||||
newUnit.Classes.Add(newClass); |
||||
|
||||
// Update TestProject's parse info.
|
||||
testProject.UpdateParseInfo(oldUnit, newUnit); |
||||
|
||||
Assert.IsFalse(testProject.TestClasses.Contains("RootNamespace.MyNewTestFixture")); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestClassRemovedInParserInfo() |
||||
{ |
||||
// Create old compilation unit.
|
||||
DefaultCompilationUnit oldUnit = new DefaultCompilationUnit(projectContent); |
||||
MockClass mockClass = (MockClass)testClass.Class; |
||||
mockClass.SetCompoundClass(mockClass); |
||||
oldUnit.Classes.Add(testClass.Class); |
||||
|
||||
// Create new compilation unit with the original test class
|
||||
// removed.
|
||||
DefaultCompilationUnit newUnit = new DefaultCompilationUnit(projectContent); |
||||
|
||||
// Update TestProject's parse info.
|
||||
testProject.UpdateParseInfo(oldUnit, newUnit); |
||||
|
||||
Assert.AreEqual(0, testProject.TestClasses.Count); |
||||
Assert.AreEqual(1, classesRemoved.Count); |
||||
Assert.AreSame(testClass, classesRemoved[0]); |
||||
} |
||||
|
||||
[Test] |
||||
public void NewCompilationUnitNull() |
||||
{ |
||||
// Create old compilation unit.
|
||||
DefaultCompilationUnit oldUnit = new DefaultCompilationUnit(projectContent); |
||||
MockClass mockClass = (MockClass)testClass.Class; |
||||
mockClass.SetCompoundClass(mockClass); |
||||
oldUnit.Classes.Add(testClass.Class); |
||||
|
||||
// Update TestProject's parse info.
|
||||
testProject.UpdateParseInfo(oldUnit, null); |
||||
|
||||
Assert.AreEqual(0, testProject.TestClasses.Count); |
||||
Assert.AreEqual(1, classesRemoved.Count); |
||||
Assert.AreSame(testClass, classesRemoved[0]); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Tests that a new method is added to the TestClass
|
||||
/// from the parse info. Also checks that the test method is
|
||||
/// taken from the CompoundClass via IClass.GetCompoundClass.
|
||||
/// A CompoundClass combines partial classes into one class so
|
||||
/// we do not get any duplicate classes with the same name.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void NewMethodInParserInfo() |
||||
{ |
||||
// Create old compilation unit.
|
||||
DefaultCompilationUnit oldUnit = new DefaultCompilationUnit(projectContent); |
||||
oldUnit.Classes.Add(testClass.Class); |
||||
|
||||
// Create new compilation unit.
|
||||
DefaultCompilationUnit newUnit = new DefaultCompilationUnit(projectContent); |
||||
newUnit.Classes.Add(testClass.Class); |
||||
|
||||
// Add a new method to a new compound class.
|
||||
MockClass compoundClass = new MockClass("RootNamespace.MyTestFixture"); |
||||
compoundClass.ProjectContent = projectContent; |
||||
compoundClass.Attributes.Add(new MockAttribute("TestFixture")); |
||||
MockMethod method = new MockMethod("NewMethod"); |
||||
method.DeclaringType = testClass.Class; |
||||
method.Attributes.Add(new MockAttribute("Test")); |
||||
compoundClass.Methods.Add(method); |
||||
MockClass mockClass = (MockClass)testClass.Class; |
||||
mockClass.SetCompoundClass(compoundClass); |
||||
|
||||
// Monitor test methods added.
|
||||
List<TestMethod> methodsAdded = new List<TestMethod>(); |
||||
testClass.TestMethods.TestMethodAdded += delegate(Object source, TestMethodEventArgs e) |
||||
{ methodsAdded.Add(e.TestMethod); }; |
||||
|
||||
// Update TestProject's parse info.
|
||||
testProject.UpdateParseInfo(oldUnit, newUnit); |
||||
|
||||
Assert.IsTrue(testClass.TestMethods.Contains("NewMethod")); |
||||
Assert.AreEqual(1, methodsAdded.Count); |
||||
Assert.AreSame(method, methodsAdded[0].Method); |
||||
} |
||||
|
||||
[Test] |
||||
public void ParserInfoForDifferentProject() |
||||
{ |
||||
// Create old compilation unit.
|
||||
MockProjectContent differentProjectContent = new MockProjectContent(); |
||||
DefaultCompilationUnit oldUnit = new DefaultCompilationUnit(differentProjectContent); |
||||
MockClass mockClass = (MockClass)testClass.Class; |
||||
mockClass.SetCompoundClass(mockClass); |
||||
oldUnit.Classes.Add(testClass.Class); |
||||
|
||||
// Create new compilation unit with the original test class
|
||||
// removed.
|
||||
DefaultCompilationUnit newUnit = new DefaultCompilationUnit(differentProjectContent); |
||||
|
||||
// Update TestProject's parse info.
|
||||
testProject.UpdateParseInfo(oldUnit, newUnit); |
||||
|
||||
Assert.AreEqual(1, testProject.TestClasses.Count); |
||||
Assert.AreEqual(0, classesRemoved.Count); |
||||
Assert.AreEqual(0, classesAdded.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void ParserInfoForThisProjectOldCompilationUnitNull() |
||||
{ |
||||
DefaultCompilationUnit newUnit = new DefaultCompilationUnit(projectContent); |
||||
Assert.IsTrue(testProject.IsParseInfoForThisProject(null, newUnit)); |
||||
} |
||||
|
||||
[Test] |
||||
public void ParserInfoForDifferentProjectOldCompilationUnitNull() |
||||
{ |
||||
MockProjectContent differentProjectContent = new MockProjectContent(); |
||||
DefaultCompilationUnit newUnit = new DefaultCompilationUnit(differentProjectContent); |
||||
|
||||
Assert.IsFalse(testProject.IsParseInfoForThisProject(null, newUnit)); |
||||
} |
||||
|
||||
[Test] |
||||
public void ParseInfoForThisProjectWhenBothCompilationUnitsNull() |
||||
{ |
||||
Assert.IsFalse(testProject.IsParseInfoForThisProject(null, null)); |
||||
} |
||||
|
||||
void ResultChanged(object source, EventArgs e) |
||||
{ |
||||
resultChangedCalled = true; |
||||
} |
||||
|
||||
void TestClassAdded(object source, TestClassEventArgs e) |
||||
{ |
||||
classesAdded.Add(e.TestClass); |
||||
} |
||||
|
||||
void TestClassRemoved(object source, TestClassEventArgs e) |
||||
{ |
||||
classesRemoved.Add(e.TestClass); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,173 @@
@@ -0,0 +1,173 @@
|
||||
// <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.UnitTesting; |
||||
using NUnit.Framework; |
||||
using UnitTesting.Tests.Utils; |
||||
|
||||
namespace UnitTesting.Tests.Project |
||||
{ |
||||
/// <summary>
|
||||
/// Creates a TestClassCollection with three test classes.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class ThreeTestClassesTestResultsTestFixture |
||||
{ |
||||
TestClass testClass1; |
||||
TestClass testClass2; |
||||
TestClass testClass3; |
||||
TestClassCollection testClasses; |
||||
bool testClassesResultChanged; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
testClassesResultChanged = false; |
||||
testClasses = new TestClassCollection(); |
||||
|
||||
// TestClass1.
|
||||
MockClass mockClass = new MockClass("TestClass1"); |
||||
testClass1 = new TestClass(mockClass); |
||||
testClasses.Add(testClass1); |
||||
|
||||
// TestClass2.
|
||||
mockClass = new MockClass("TestClass2"); |
||||
testClass2 = new TestClass(mockClass); |
||||
testClasses.Add(testClass2); |
||||
|
||||
// TestClass3.
|
||||
mockClass = new MockClass("TestClass3"); |
||||
testClass3 = new TestClass(mockClass); |
||||
testClasses.Add(testClass3); |
||||
|
||||
testClasses.ResultChanged += TestClassesResultChanged; |
||||
} |
||||
|
||||
[Test] |
||||
public void InitialTestResult() |
||||
{ |
||||
Assert.AreEqual(TestResultType.None, testClasses.Result); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestClass1Fails() |
||||
{ |
||||
testClass1.Result = TestResultType.Failure; |
||||
Assert.AreEqual(TestResultType.Failure, testClasses.Result); |
||||
Assert.IsTrue(testClassesResultChanged); |
||||
} |
||||
|
||||
[Test] |
||||
public void ResetAfterTestClass1Failed() |
||||
{ |
||||
TestClass1Fails(); |
||||
testClasses.ResetTestResults(); |
||||
InitialTestResult(); |
||||
|
||||
Assert.AreEqual(TestResultType.None, testClass1.Result); |
||||
} |
||||
|
||||
[Test] |
||||
public void AllTestClassesPass() |
||||
{ |
||||
testClass1.Result = TestResultType.Success; |
||||
testClass2.Result = TestResultType.Success; |
||||
testClass3.Result = TestResultType.Success; |
||||
Assert.AreEqual(TestResultType.Success, testClasses.Result); |
||||
Assert.IsTrue(testClassesResultChanged); |
||||
} |
||||
|
||||
[Test] |
||||
public void ResetAfterAllPassed() |
||||
{ |
||||
AllTestClassesPass(); |
||||
testClasses.ResetTestResults(); |
||||
InitialTestResult(); |
||||
|
||||
Assert.AreEqual(TestResultType.None, testClass1.Result); |
||||
Assert.IsTrue(testClassesResultChanged); |
||||
} |
||||
|
||||
[Test] |
||||
public void AllTestClassesIgnored() |
||||
{ |
||||
testClass1.Result = TestResultType.Ignored; |
||||
testClass2.Result = TestResultType.Ignored; |
||||
testClass3.Result = TestResultType.Ignored; |
||||
Assert.AreEqual(TestResultType.Ignored, testClasses.Result); |
||||
Assert.IsTrue(testClassesResultChanged); |
||||
} |
||||
|
||||
[Test] |
||||
public void ResetAfterAllTestClasssIgnored() |
||||
{ |
||||
AllTestClassesIgnored(); |
||||
|
||||
testClassesResultChanged = false; |
||||
testClasses.ResetTestResults(); |
||||
|
||||
InitialTestResult(); |
||||
|
||||
Assert.AreEqual(TestResultType.None, testClass1.Result); |
||||
Assert.IsTrue(testClassesResultChanged); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestClass1Removed() |
||||
{ |
||||
testClasses.Remove(testClass1); |
||||
testClass1.Result = TestResultType.Failure; |
||||
|
||||
InitialTestResult(); |
||||
|
||||
Assert.IsFalse(testClassesResultChanged); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestClassesResultSetToNoneAfterAllTestClassesIgnored() |
||||
{ |
||||
AllTestClassesIgnored(); |
||||
|
||||
testClassesResultChanged = false; |
||||
testClass1.Result = TestResultType.None; |
||||
testClass2.Result = TestResultType.None; |
||||
testClass3.Result = TestResultType.None; |
||||
|
||||
InitialTestResult(); |
||||
|
||||
Assert.IsTrue(testClassesResultChanged); |
||||
} |
||||
|
||||
[Test] |
||||
public void AddTestFailureClassAfterAllTestsPassed() |
||||
{ |
||||
AllTestClassesPass(); |
||||
|
||||
MockClass mockClass = new MockClass("TestClass4"); |
||||
TestClass testClass4 = new TestClass(mockClass); |
||||
testClass4.Result = TestResultType.Failure; |
||||
testClasses.Add(testClass4); |
||||
|
||||
Assert.AreEqual(TestResultType.Failure, testClasses.Result); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestClass1RemovedAfterSetToIgnored() |
||||
{ |
||||
testClass1.Result = TestResultType.Ignored; |
||||
|
||||
testClasses.Remove(testClass1); |
||||
InitialTestResult(); |
||||
} |
||||
|
||||
void TestClassesResultChanged(object source, EventArgs e) |
||||
{ |
||||
testClassesResultChanged = true; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,173 @@
@@ -0,0 +1,173 @@
|
||||
// <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.UnitTesting; |
||||
using NUnit.Framework; |
||||
using UnitTesting.Tests.Utils; |
||||
|
||||
namespace UnitTesting.Tests.Project |
||||
{ |
||||
/// <summary>
|
||||
/// Creates a TestMethodCollection with three TestMethods.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class ThreeTestMethodsTestResultsTestFixture |
||||
{ |
||||
TestMethod testMethod1; |
||||
TestMethod testMethod2; |
||||
TestMethod testMethod3; |
||||
TestMethodCollection testMethods; |
||||
bool testMethodsResultChanged; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
testMethodsResultChanged = false; |
||||
testMethods = new TestMethodCollection(); |
||||
|
||||
// TestMethod1.
|
||||
MockMethod mockMethod = new MockMethod("TestMethod1"); |
||||
testMethod1 = new TestMethod(mockMethod); |
||||
testMethods.Add(testMethod1); |
||||
|
||||
// TestMethod2.
|
||||
mockMethod = new MockMethod("TestMethod2"); |
||||
testMethod2 = new TestMethod(mockMethod); |
||||
testMethods.Add(testMethod2); |
||||
|
||||
// TestMethod3.
|
||||
mockMethod = new MockMethod("TestMethod3"); |
||||
testMethod3 = new TestMethod(mockMethod); |
||||
testMethods.Add(testMethod3); |
||||
|
||||
testMethods.ResultChanged += TestMethodsResultChanged; |
||||
} |
||||
|
||||
[Test] |
||||
public void InitialTestResult() |
||||
{ |
||||
Assert.AreEqual(TestResultType.None, testMethods.Result); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestMethod1Fails() |
||||
{ |
||||
testMethod1.Result = TestResultType.Failure; |
||||
Assert.AreEqual(TestResultType.Failure, testMethods.Result); |
||||
Assert.IsTrue(testMethodsResultChanged); |
||||
} |
||||
|
||||
[Test] |
||||
public void ResetAfterTestMethod1Failed() |
||||
{ |
||||
TestMethod1Fails(); |
||||
testMethods.ResetTestResults(); |
||||
InitialTestResult(); |
||||
|
||||
Assert.AreEqual(TestResultType.None, testMethod1.Result); |
||||
} |
||||
|
||||
[Test] |
||||
public void AllTestMethodsPass() |
||||
{ |
||||
testMethod1.Result = TestResultType.Success; |
||||
testMethod2.Result = TestResultType.Success; |
||||
testMethod3.Result = TestResultType.Success; |
||||
Assert.AreEqual(TestResultType.Success, testMethods.Result); |
||||
Assert.IsTrue(testMethodsResultChanged); |
||||
} |
||||
|
||||
[Test] |
||||
public void ResetAfterAllPassed() |
||||
{ |
||||
AllTestMethodsPass(); |
||||
testMethods.ResetTestResults(); |
||||
InitialTestResult(); |
||||
|
||||
Assert.AreEqual(TestResultType.None, testMethod1.Result); |
||||
Assert.IsTrue(testMethodsResultChanged); |
||||
} |
||||
|
||||
[Test] |
||||
public void AllTestMethodsIgnored() |
||||
{ |
||||
testMethod1.Result = TestResultType.Ignored; |
||||
testMethod2.Result = TestResultType.Ignored; |
||||
testMethod3.Result = TestResultType.Ignored; |
||||
Assert.AreEqual(TestResultType.Ignored, testMethods.Result); |
||||
Assert.IsTrue(testMethodsResultChanged); |
||||
} |
||||
|
||||
[Test] |
||||
public void ResetAfterAllTestMethodsIgnored() |
||||
{ |
||||
AllTestMethodsIgnored(); |
||||
|
||||
testMethodsResultChanged = false; |
||||
testMethods.ResetTestResults(); |
||||
|
||||
InitialTestResult(); |
||||
|
||||
Assert.AreEqual(TestResultType.None, testMethod1.Result); |
||||
Assert.IsTrue(testMethodsResultChanged); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestMethod1Removed() |
||||
{ |
||||
testMethods.Remove(testMethod1); |
||||
testMethod1.Result = TestResultType.Failure; |
||||
|
||||
InitialTestResult(); |
||||
|
||||
Assert.IsFalse(testMethodsResultChanged); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestMethodsResultSetToNoneAfterAllTestClasssIgnored() |
||||
{ |
||||
AllTestMethodsIgnored(); |
||||
|
||||
testMethodsResultChanged = false; |
||||
testMethod1.Result = TestResultType.None; |
||||
testMethod2.Result = TestResultType.None; |
||||
testMethod3.Result = TestResultType.None; |
||||
|
||||
InitialTestResult(); |
||||
|
||||
Assert.IsTrue(testMethodsResultChanged); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestMethod1RemovedAfterSetToIgnored() |
||||
{ |
||||
testMethod1.Result = TestResultType.Ignored; |
||||
|
||||
testMethods.Remove(testMethod1); |
||||
InitialTestResult(); |
||||
} |
||||
|
||||
[Test] |
||||
public void AddTestFailureAfterAllTestsPassed() |
||||
{ |
||||
AllTestMethodsPass(); |
||||
|
||||
MockMethod mockMethod = new MockMethod("TestMethod4"); |
||||
TestMethod testMethod4 = new TestMethod(mockMethod); |
||||
testMethod4.Result = TestResultType.Failure; |
||||
testMethods.Add(testMethod4); |
||||
|
||||
Assert.AreEqual(TestResultType.Failure, testMethods.Result); |
||||
} |
||||
|
||||
void TestMethodsResultChanged(object source, EventArgs e) |
||||
{ |
||||
testMethodsResultChanged = true; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,140 @@
@@ -0,0 +1,140 @@
|
||||
// <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 UnitTesting.Tests.Utils; |
||||
|
||||
namespace UnitTesting.Tests.Project |
||||
{ |
||||
[TestFixture] |
||||
public class TwoRootNamespacesTestFixture |
||||
{ |
||||
TestProject testProject; |
||||
MockProjectContent projectContent; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
// Create a project to display in the test tree view.
|
||||
MSBuildProject project = new MSBuildProject(); |
||||
project.Name = "TestProject"; |
||||
ReferenceProjectItem nunitFrameworkReferenceItem = new ReferenceProjectItem(project); |
||||
nunitFrameworkReferenceItem.Include = "NUnit.Framework"; |
||||
project.Items.Add(nunitFrameworkReferenceItem); |
||||
|
||||
// Add a test class with a TestFixture attributes.
|
||||
projectContent = new MockProjectContent(); |
||||
projectContent.Language = LanguageProperties.None; |
||||
MockClass c = new MockClass("RootNamespace1.MyTestFixture1"); |
||||
c.Attributes.Add(new MockAttribute("TestFixture")); |
||||
c.ProjectContent = projectContent; |
||||
projectContent.Classes.Add(c); |
||||
|
||||
// Add a second class with a different root namespace.
|
||||
c = new MockClass("RootNamespace2.MyTestFixture2"); |
||||
c.Attributes.Add(new MockAttribute("TestFixture")); |
||||
c.ProjectContent = projectContent; |
||||
projectContent.Classes.Add(c); |
||||
|
||||
testProject = new TestProject(project, projectContent); |
||||
} |
||||
|
||||
[Test] |
||||
public void TwoRootNamespaces() |
||||
{ |
||||
Assert.AreEqual(2, testProject.RootNamespaces.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void RootNamespace1() |
||||
{ |
||||
Assert.AreEqual("RootNamespace1", testProject.RootNamespaces[0]); |
||||
} |
||||
|
||||
[Test] |
||||
public void RootNamespace2() |
||||
{ |
||||
Assert.AreEqual("RootNamespace2", testProject.RootNamespaces[1]); |
||||
} |
||||
|
||||
[Test] |
||||
public void OneClassInNamespace1() |
||||
{ |
||||
Assert.AreEqual(1, testProject.GetTestClasses("RootNamespace1").Length); |
||||
} |
||||
|
||||
[Test] |
||||
public void ClassNameInNamespace1() |
||||
{ |
||||
TestClass[] classes = testProject.GetTestClasses("RootNamespace1"); |
||||
Assert.AreEqual("MyTestFixture1", classes[0].Name); |
||||
} |
||||
|
||||
[Test] |
||||
public void OneClassInNamespace2() |
||||
{ |
||||
Assert.AreEqual(1, testProject.GetTestClasses("RootNamespace2").Length); |
||||
} |
||||
|
||||
[Test] |
||||
public void ClassNameInNamespace2() |
||||
{ |
||||
TestClass[] classes = testProject.GetTestClasses("RootNamespace2"); |
||||
Assert.AreEqual("MyTestFixture2", classes[0].Name); |
||||
} |
||||
|
||||
[Test] |
||||
public void TwoClassesStartWithRootNamespace() |
||||
{ |
||||
TestClass[] classes = testProject.GetAllTestClasses("RootNamespace"); |
||||
Assert.AreEqual(2, classes.Length); |
||||
Assert.AreEqual("MyTestFixture1", classes[0].Name); |
||||
Assert.AreEqual("MyTestFixture2", classes[1].Name); |
||||
} |
||||
|
||||
[Test] |
||||
public void NoChildNamespaces() |
||||
{ |
||||
Assert.AreEqual(0, testProject.GetChildNamespaces("RootNamespace").Length); |
||||
} |
||||
|
||||
[Test] |
||||
public void TwoChildNamespacesForEmptyNamespace() |
||||
{ |
||||
string[] namespaces = testProject.GetChildNamespaces(String.Empty); |
||||
Assert.AreEqual(2, namespaces.Length); |
||||
Assert.AreEqual("RootNamespace1", namespaces[0]); |
||||
Assert.AreEqual("RootNamespace2", namespaces[1]); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Makes sure that the fully qualified class name is used
|
||||
/// when working out the overall test result in the
|
||||
/// TestClassCollection.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void DuplicateClassName() |
||||
{ |
||||
MockClass c = new MockClass("RootNamespace1.MyTestFixture2"); |
||||
c.Attributes.Add(new MockAttribute("TestFixture")); |
||||
c.ProjectContent = projectContent; |
||||
|
||||
TestClass testClass = new TestClass(c); |
||||
testProject.TestClasses.Add(testClass); |
||||
|
||||
testClass.Result = TestResultType.Failure; |
||||
TestClass testClass2 = testProject.TestClasses["RootNamespace2.MyTestFixture2"]; |
||||
testClass2.Result = TestResultType.Failure; |
||||
|
||||
Assert.AreEqual(TestResultType.Failure, testProject.TestClasses.Result); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,251 @@
@@ -0,0 +1,251 @@
|
||||
// <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.UnitTesting; |
||||
using NUnit.Framework; |
||||
|
||||
namespace UnitTesting.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class TestResultsReaderTests |
||||
{ |
||||
[Test] |
||||
public void OneTestPass() |
||||
{ |
||||
string resultsText = "Name: MyTest\r\n" + |
||||
"Result: Success\r\n"; |
||||
|
||||
TestResultsReader reader = new TestResultsReader(); |
||||
TestResult[] results = reader.Read(resultsText); |
||||
|
||||
Assert.AreEqual(1, results.Length); |
||||
|
||||
TestResult result = results[0]; |
||||
Assert.AreEqual("MyTest", result.Name); |
||||
Assert.IsTrue(result.IsSuccess); |
||||
Assert.AreEqual(TestResultType.Success, result.ResultType); |
||||
} |
||||
|
||||
[Test] |
||||
public void OneTestIgnored() |
||||
{ |
||||
string resultsText = "Name: MyTest\r\n" + |
||||
"Result: Ignored\r\n"; |
||||
|
||||
TestResultsReader reader = new TestResultsReader(); |
||||
TestResult[] results = reader.Read(resultsText); |
||||
|
||||
Assert.AreEqual(1, results.Length); |
||||
|
||||
TestResult result = results[0]; |
||||
Assert.AreEqual("MyTest", result.Name); |
||||
Assert.IsTrue(result.IsIgnored); |
||||
Assert.IsFalse(result.IsSuccess); |
||||
Assert.AreEqual(TestResultType.Ignored, result.ResultType); |
||||
} |
||||
|
||||
[Test] |
||||
public void OneTestPassInParts() |
||||
{ |
||||
string resultsText = "Name: MyTest\r\n" + |
||||
"Result: Success\r\n"; |
||||
|
||||
TestResultsReader reader = new TestResultsReader(); |
||||
|
||||
List<TestResult> results = new List<TestResult>(); |
||||
foreach (char ch in resultsText) { |
||||
TestResult[] readResults = reader.Read(ch.ToString()); |
||||
if (readResults.Length > 0) { |
||||
foreach (TestResult readResult in readResults) { |
||||
results.Add(readResult); |
||||
} |
||||
} |
||||
} |
||||
|
||||
Assert.AreEqual(1, results.Count); |
||||
|
||||
TestResult result = results[0]; |
||||
Assert.AreEqual("MyTest", result.Name); |
||||
Assert.IsTrue(result.IsSuccess); |
||||
} |
||||
|
||||
[Test] |
||||
public void OneTestFailure() |
||||
{ |
||||
string resultsText = "Name: MyTest\r\n" + |
||||
"Result: Failure\r\n"; |
||||
|
||||
TestResultsReader reader = new TestResultsReader(); |
||||
TestResult[] results = reader.Read(resultsText); |
||||
|
||||
Assert.AreEqual(1, results.Length); |
||||
|
||||
TestResult result = results[0]; |
||||
Assert.AreEqual("MyTest", result.Name); |
||||
Assert.IsTrue(result.IsFailure); |
||||
Assert.IsFalse(result.IsSuccess); |
||||
Assert.IsFalse(result.IsIgnored); |
||||
Assert.AreEqual(TestResultType.Failure, result.ResultType); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestMessage() |
||||
{ |
||||
string resultsText = "Name: Test\r\n" + |
||||
"Message: Should not be 0.\r\n" + |
||||
"Result: Failure\r\n"; |
||||
|
||||
TestResultsReader reader = new TestResultsReader(); |
||||
TestResult[] results = reader.Read(resultsText); |
||||
|
||||
Assert.AreEqual(1, results.Length); |
||||
|
||||
TestResult result = results[0]; |
||||
Assert.AreEqual("Test", result.Name); |
||||
Assert.AreEqual("Should not be 0.", result.Message); |
||||
Assert.IsTrue(result.IsFailure); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestStackTrace() |
||||
{ |
||||
string resultsText = "Name: Test\r\n" + |
||||
"StackTrace: stack trace\r\n" + |
||||
"Result: Failure\r\n"; |
||||
|
||||
TestResultsReader reader = new TestResultsReader(); |
||||
TestResult[] results = reader.Read(resultsText); |
||||
|
||||
Assert.AreEqual(1, results.Length); |
||||
|
||||
TestResult result = results[0]; |
||||
Assert.AreEqual("Test", result.Name); |
||||
Assert.AreEqual("stack trace", result.StackTrace); |
||||
Assert.IsTrue(result.IsFailure); |
||||
} |
||||
|
||||
[Test] |
||||
public void ResultWithNoTestName() |
||||
{ |
||||
string resultsText = "Result: Failure\r\n"; |
||||
|
||||
TestResultsReader reader = new TestResultsReader(); |
||||
TestResult[] results = reader.Read(resultsText); |
||||
|
||||
Assert.AreEqual(0, results.Length); |
||||
} |
||||
|
||||
[Test] |
||||
public void MissingNameValuePairOnFirstLine() |
||||
{ |
||||
string resultsText = "MissingNameValuePair\r\n" + |
||||
"Name: Test\r\n" + |
||||
"Result: Failure\r\n"; |
||||
|
||||
TestResultsReader reader = new TestResultsReader(); |
||||
TestResult[] results = reader.Read(resultsText); |
||||
|
||||
Assert.AreEqual(1, results.Length); |
||||
|
||||
TestResult result = results[0]; |
||||
Assert.AreEqual("Test", result.Name); |
||||
Assert.IsTrue(result.IsFailure); |
||||
} |
||||
|
||||
[Test] |
||||
public void TwoLineTestMessage() |
||||
{ |
||||
string resultsText = "Name: Test\r\n" + |
||||
"Message: Should not be 0.\r\n" + |
||||
" Should be 1.\r\n" + |
||||
"Result: Failure\r\n"; |
||||
|
||||
TestResultsReader reader = new TestResultsReader(); |
||||
TestResult[] results = reader.Read(resultsText); |
||||
|
||||
Assert.AreEqual(1, results.Length); |
||||
|
||||
TestResult result = results[0]; |
||||
Assert.AreEqual("Test", result.Name); |
||||
Assert.AreEqual("Should not be 0.\r\nShould be 1.", result.Message); |
||||
Assert.IsTrue(result.IsFailure); |
||||
} |
||||
|
||||
[Test] |
||||
public void ThreeLineTestMessage() |
||||
{ |
||||
string resultsText = "Name: Test\r\n" + |
||||
"Message: Should not be 0.\r\n" + |
||||
" Should be 1.\r\n" + |
||||
" End of message.\r\n" + |
||||
"Result: Failure\r\n"; |
||||
|
||||
TestResultsReader reader = new TestResultsReader(); |
||||
TestResult[] results = reader.Read(resultsText); |
||||
|
||||
Assert.AreEqual(1, results.Length); |
||||
|
||||
TestResult result = results[0]; |
||||
Assert.AreEqual("Test", result.Name); |
||||
Assert.AreEqual("Should not be 0.\r\nShould be 1.\r\nEnd of message.", result.Message); |
||||
Assert.IsTrue(result.IsFailure); |
||||
} |
||||
|
||||
[Test] |
||||
public void TwoTestFailures() |
||||
{ |
||||
string resultsText = "Name: MyTest1\r\n" + |
||||
"Result: Failure\r\n" + |
||||
"Name: MyTest2\r\n" + |
||||
"Result: Failure\r\n"; |
||||
|
||||
TestResultsReader reader = new TestResultsReader(); |
||||
TestResult[] results = reader.Read(resultsText); |
||||
|
||||
Assert.AreEqual(2, results.Length); |
||||
|
||||
TestResult result1 = results[0]; |
||||
Assert.AreEqual("MyTest1", result1.Name); |
||||
Assert.IsTrue(result1.IsFailure); |
||||
|
||||
TestResult result2 = results[1]; |
||||
Assert.AreEqual("MyTest2", result2.Name); |
||||
Assert.IsTrue(result2.IsFailure); |
||||
} |
||||
|
||||
[Test] |
||||
public void TwoTestFailuresWithMultilineMessages() |
||||
{ |
||||
string resultsText = "Name: MyTest1\r\n" + |
||||
"Message: FirstLine\r\n" + |
||||
" SecondLine\r\n" + |
||||
"Result: Failure\r\n" + |
||||
"Name: MyTest2\r\n" + |
||||
"Message: FirstLine\r\n" + |
||||
" SecondLine\r\n" + |
||||
" ThirdLine\r\n" + |
||||
"Result: Failure\r\n"; |
||||
|
||||
TestResultsReader reader = new TestResultsReader(); |
||||
TestResult[] results = reader.Read(resultsText); |
||||
|
||||
Assert.AreEqual(2, results.Length); |
||||
|
||||
TestResult result1 = results[0]; |
||||
Assert.AreEqual("MyTest1", result1.Name); |
||||
Assert.AreEqual("FirstLine\r\nSecondLine", result1.Message); |
||||
Assert.IsTrue(result1.IsFailure); |
||||
|
||||
TestResult result2 = results[1]; |
||||
Assert.AreEqual("MyTest2", result2.Name); |
||||
Assert.AreEqual("FirstLine\r\nSecondLine\r\nThirdLine", result2.Message); |
||||
Assert.IsTrue(result2.IsFailure); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,263 @@
@@ -0,0 +1,263 @@
|
||||
// <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.Bookmarks; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.SharpDevelop.Gui.ClassBrowser; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using ICSharpCode.UnitTesting; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using UnitTesting.Tests.Utils; |
||||
|
||||
namespace UnitTesting.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class TestableConditionTests |
||||
{ |
||||
[SetUp] |
||||
public void SetUpFixture() |
||||
{ |
||||
ResourceManager.Initialize(); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetMemberFromNullOwner() |
||||
{ |
||||
Assert.IsNull(TestableCondition.GetMember(null)); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetClassFromNullOwner() |
||||
{ |
||||
Assert.IsNull(TestableCondition.GetClass(null)); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetProjectFromNullOwner() |
||||
{ |
||||
Assert.IsNull(TestableCondition.GetProject(null)); |
||||
} |
||||
|
||||
[Test] |
||||
public void IsValidFromNullOwner() |
||||
{ |
||||
TestableCondition testableCondition = new TestableCondition(); |
||||
Assert.IsFalse(testableCondition.IsValid(null, null)); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetMemberFromTreeView() |
||||
{ |
||||
MockTestTreeView mockTreeView = new MockTestTreeView(); |
||||
MockMember mockMember = new MockMember(); |
||||
mockTreeView.SelectedMethod = mockMember; |
||||
|
||||
Assert.IsTrue(Object.ReferenceEquals(mockMember, TestableCondition.GetMember(mockTreeView))); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetClassFromTreeView() |
||||
{ |
||||
MockTestTreeView mockTreeView = new MockTestTreeView(); |
||||
MockClass mockClass = new MockClass(); |
||||
mockTreeView.SelectedClass = mockClass; |
||||
|
||||
Assert.IsTrue(Object.ReferenceEquals(mockClass, TestableCondition.GetClass(mockTreeView))); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetProjectFromTreeView() |
||||
{ |
||||
MockTestTreeView mockTreeView = new MockTestTreeView(); |
||||
MSBuildProject project = new MSBuildProject(); |
||||
mockTreeView.SelectedProject = project; |
||||
|
||||
Assert.IsTrue(Object.ReferenceEquals(project, TestableCondition.GetProject(mockTreeView))); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetMemberFromMemberNode() |
||||
{ |
||||
MockMethod mockMethod = new MockMethod(); |
||||
MockMemberNode memberNode = new MockMemberNode(mockMethod); |
||||
|
||||
Assert.IsTrue(Object.ReferenceEquals(mockMethod, TestableCondition.GetMember(memberNode))); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetProjectFromMemberNode() |
||||
{ |
||||
MockMethod mockMethod = new MockMethod(); |
||||
MSBuildProject project = new MSBuildProject(); |
||||
MockClass mockClass = new MockClass(); |
||||
MockProjectContent mockProjectContent = new MockProjectContent(); |
||||
mockProjectContent.Project = project; |
||||
mockClass.ProjectContent = mockProjectContent; |
||||
mockMethod.DeclaringType = mockClass; |
||||
MockMemberNode memberNode = new MockMemberNode(mockMethod); |
||||
|
||||
Assert.IsTrue(Object.ReferenceEquals(project, TestableCondition.GetProject(memberNode))); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetClassFromClassNode() |
||||
{ |
||||
MockClass mockClass = new MockClass(); |
||||
ClassNode classNode = new ClassNode(null, mockClass); |
||||
|
||||
Assert.IsTrue(Object.ReferenceEquals(mockClass, TestableCondition.GetClass(classNode))); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetProjectFromClassNode() |
||||
{ |
||||
MSBuildProject project = new MSBuildProject(); |
||||
MockClass mockClass = new MockClass(); |
||||
MockProjectContent mockProjectContent = new MockProjectContent(); |
||||
mockProjectContent.Project = project; |
||||
mockClass.ProjectContent = mockProjectContent; |
||||
ClassNode classNode = new ClassNode(project, mockClass); |
||||
|
||||
Assert.IsTrue(Object.ReferenceEquals(project, TestableCondition.GetProject(classNode))); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetMemberFromClassMemberBookmark() |
||||
{ |
||||
MockMethod mockMethod = new MockMethod(); |
||||
mockMethod.Region = new DomRegion(1,1); |
||||
MethodBookmark bookmark = new MethodBookmark(null, mockMethod); |
||||
|
||||
Assert.IsTrue(Object.ReferenceEquals(mockMethod, TestableCondition.GetMember(bookmark))); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetClassFromClassBookmark() |
||||
{ |
||||
MockClass mockClass = new MockClass(); |
||||
mockClass.Region = new DomRegion(1,1); |
||||
ClassBookmark bookmark = new ClassBookmark(null, mockClass); |
||||
|
||||
Assert.IsTrue(Object.ReferenceEquals(mockClass, TestableCondition.GetClass(bookmark))); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Tests references to class.ProjectContent when
|
||||
/// it is null.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void GetProjectWhenProjectContentIsNull() |
||||
{ |
||||
MockClass mockClass = new MockClass(); |
||||
ClassNode classNode = new ClassNode(null, mockClass); |
||||
|
||||
Assert.IsNull(TestableCondition.GetProject(classNode)); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Tests references to class.ProjectContent when
|
||||
/// it is null.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void IsValidWhenProjectContentIsNull() |
||||
{ |
||||
MockClass mockClass = new MockClass(); |
||||
ClassNode classNode = new ClassNode(null, mockClass); |
||||
|
||||
TestableCondition testableCondition = new TestableCondition(); |
||||
Assert.IsFalse(testableCondition.IsValid(classNode, null)); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// When class.ProjectContent.Project == null the
|
||||
/// TestableCondition.IsValid should return false.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void IsValidWhenProjectIsNull() |
||||
{ |
||||
MockClass mockClass = new MockClass(); |
||||
MockProjectContent mockProjectContent = new MockProjectContent(); |
||||
mockClass.ProjectContent = mockProjectContent; |
||||
ClassNode classNode = new ClassNode(null, mockClass); |
||||
|
||||
TestableCondition testableCondition = new TestableCondition(); |
||||
Assert.IsFalse(testableCondition.IsValid(classNode, null)); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Tests what happens when the class.ProjectContent.Language
|
||||
/// is null.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void IsValidWhenLanguageIsNull() |
||||
{ |
||||
MSBuildProject project = new MSBuildProject(); |
||||
MockClass mockClass = new MockClass(); |
||||
MockProjectContent mockProjectContent = new MockProjectContent(); |
||||
mockProjectContent.Project = project; |
||||
mockClass.ProjectContent = mockProjectContent; |
||||
ClassNode classNode = new ClassNode(project, mockClass); |
||||
|
||||
TestableCondition testableCondition = new TestableCondition(); |
||||
Assert.IsFalse(testableCondition.IsValid(classNode, null)); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Tests what happens when the
|
||||
/// class.ProjectContent.Language.NameComparer is null.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void IsValidWhenNameComparerIsNull() |
||||
{ |
||||
MSBuildProject project = new MSBuildProject(); |
||||
MockClass mockClass = new MockClass(); |
||||
MockProjectContent mockProjectContent = new MockProjectContent(); |
||||
mockProjectContent.Project = project; |
||||
mockProjectContent.Language = new LanguageProperties(null); |
||||
mockClass.ProjectContent = mockProjectContent; |
||||
ClassNode classNode = new ClassNode(project, mockClass); |
||||
|
||||
TestableCondition testableCondition = new TestableCondition(); |
||||
Assert.IsFalse(testableCondition.IsValid(classNode, null)); |
||||
} |
||||
|
||||
[Test] |
||||
public void IsValidWhenMethodHasTestAttribute() |
||||
{ |
||||
MockMethod mockMethod = new MockMethod(); |
||||
mockMethod.Attributes.Add(new MockAttribute("Test")); |
||||
MSBuildProject project = new MSBuildProject(); |
||||
MockClass mockClass = new MockClass(); |
||||
MockProjectContent mockProjectContent = new MockProjectContent(); |
||||
mockProjectContent.Project = project; |
||||
mockProjectContent.Language = LanguageProperties.None; |
||||
mockClass.ProjectContent = mockProjectContent; |
||||
mockMethod.DeclaringType = mockClass; |
||||
MockMemberNode memberNode = new MockMemberNode(mockMethod); |
||||
|
||||
TestableCondition testableCondition = new TestableCondition(); |
||||
Assert.IsTrue(testableCondition.IsValid(memberNode, null)); |
||||
} |
||||
|
||||
[Test] |
||||
public void IsValidWhenClassHasTestFixtureAttribute() |
||||
{ |
||||
MSBuildProject project = new MSBuildProject(); |
||||
MockClass mockClass = new MockClass(); |
||||
mockClass.Attributes.Add(new MockAttribute("TestFixture")); |
||||
MockProjectContent mockProjectContent = new MockProjectContent(); |
||||
mockProjectContent.Project = project; |
||||
mockProjectContent.Language = LanguageProperties.None; |
||||
mockClass.ProjectContent = mockProjectContent; |
||||
ClassNode classNode = new ClassNode(project, mockClass); |
||||
|
||||
TestableCondition testableCondition = new TestableCondition(); |
||||
Assert.IsTrue(testableCondition.IsValid(classNode, null)); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,304 @@
@@ -0,0 +1,304 @@
|
||||
// <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.Windows.Forms; |
||||
|
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using ICSharpCode.UnitTesting; |
||||
using NUnit.Framework; |
||||
using UnitTesting.Tests.Utils; |
||||
|
||||
namespace UnitTesting.Tests.Tree |
||||
{ |
||||
/// <summary>
|
||||
/// Adds a class with no root namespace to the test tree.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class ClassWithNoRootNamespaceTestFixture |
||||
{ |
||||
Solution solution; |
||||
ExtTreeNode rootNode; |
||||
TreeNodeCollection nodes; |
||||
DummyParserServiceTestTreeView dummyTreeView; |
||||
TestTreeView treeView; |
||||
MSBuildProject project; |
||||
MockClass testClass; |
||||
ExtTreeNode testFixtureNode; |
||||
TreeNodeCollection rootChildNodes; |
||||
MockProjectContent projectContent; |
||||
|
||||
[SetUp] |
||||
public void SetUp() |
||||
{ |
||||
// Create solution.
|
||||
solution = new Solution(); |
||||
|
||||
// Create a project to display in the test tree view.
|
||||
project = new MSBuildProject(); |
||||
project.Name = "TestProject"; |
||||
ReferenceProjectItem nunitFrameworkReferenceItem = new ReferenceProjectItem(project); |
||||
nunitFrameworkReferenceItem.Include = "NUnit.Framework"; |
||||
project.Items.Add(nunitFrameworkReferenceItem); |
||||
|
||||
// Add a test class with a TestFixture attributes.
|
||||
projectContent = new MockProjectContent(); |
||||
projectContent.Language = LanguageProperties.None; |
||||
testClass = new MockClass("MyTestFixture"); |
||||
testClass.Attributes.Add(new MockAttribute("TestFixture")); |
||||
testClass.ProjectContent = projectContent; |
||||
projectContent.Classes.Add(testClass); |
||||
|
||||
// Init mock project content to be returned.
|
||||
dummyTreeView = new DummyParserServiceTestTreeView(); |
||||
dummyTreeView.AddProjectContentForProject(projectContent); |
||||
|
||||
// Load the projects into the test tree view.
|
||||
treeView = dummyTreeView as TestTreeView; |
||||
solution.Folders.Add(project); |
||||
treeView.AddSolution(solution); |
||||
nodes = treeView.Nodes; |
||||
rootNode = (ExtTreeNode)treeView.Nodes[0]; |
||||
|
||||
// Expand the root node so any child nodes are
|
||||
// lazily created.
|
||||
rootNode.Expanding(); |
||||
rootChildNodes = rootNode.Nodes; |
||||
testFixtureNode = (ExtTreeNode)rootNode.Nodes[0]; |
||||
} |
||||
|
||||
[TearDown] |
||||
public void TearDown() |
||||
{ |
||||
if (treeView != null) { |
||||
treeView.Dispose(); |
||||
} |
||||
} |
||||
|
||||
[Test] |
||||
public void OneRootChildNode() |
||||
{ |
||||
Assert.AreEqual(1, rootChildNodes.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestFixtureNodeText() |
||||
{ |
||||
Assert.AreEqual("MyTestFixture", testFixtureNode.Text); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestFixtureNodeIsTestClassNode() |
||||
{ |
||||
Assert.IsInstanceOfType(typeof(TestClassTreeNode), testFixtureNode); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Make sure the test tree view clears the existing nodes
|
||||
/// when the solution is added to the tree. Only one
|
||||
/// solution can be displayed in the tree.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void AddSolution() |
||||
{ |
||||
treeView.AddSolution(solution); |
||||
|
||||
Assert.AreEqual(1, treeView.Nodes.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestClassFails() |
||||
{ |
||||
treeView.SelectedNode = testFixtureNode; |
||||
TestClass testClass = treeView.SelectedTestProject.TestClasses["MyTestFixture"]; |
||||
testClass.Result = TestResultType.Failure; |
||||
|
||||
Assert.AreEqual(TestTreeViewImageListIndex.TestFailed, (TestTreeViewImageListIndex)testFixtureNode.ImageIndex); |
||||
Assert.AreEqual(TestTreeViewImageListIndex.TestFailed, (TestTreeViewImageListIndex)rootNode.ImageIndex); |
||||
} |
||||
|
||||
[Test] |
||||
public void AddNewClass() |
||||
{ |
||||
TestProjectTreeNode projectNode = (TestProjectTreeNode)rootNode; |
||||
|
||||
MockClass mockClass = new MockClass("MyNewTestFixture"); |
||||
mockClass.Attributes.Add(new MockAttribute("TestFixture")); |
||||
mockClass.ProjectContent = projectContent; |
||||
TestClass newTestClass = new TestClass(mockClass); |
||||
projectNode.TestProject.TestClasses.Add(newTestClass); |
||||
|
||||
ExtTreeNode newTestClassNode = null; |
||||
foreach (ExtTreeNode node in rootNode.Nodes) { |
||||
if (node.Text == "MyNewTestFixture") { |
||||
newTestClassNode = node; |
||||
break; |
||||
} |
||||
} |
||||
newTestClass.Result = TestResultType.Failure; |
||||
|
||||
// New test class node should be added to the root node.
|
||||
Assert.IsNotNull(newTestClassNode); |
||||
Assert.AreEqual(2, rootNode.Nodes.Count); |
||||
|
||||
// Make sure the project node image index is affected by the
|
||||
// new test class added.
|
||||
Assert.AreEqual(TestTreeViewImageListIndex.TestFailed, (TestTreeViewImageListIndex)rootNode.SelectedImageIndex); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Tests that the test class with no root namespace
|
||||
/// is removed from the project tree node.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void RemoveClass() |
||||
{ |
||||
// Locate the class we are going to remove.
|
||||
TestProjectTreeNode projectNode = (TestProjectTreeNode)rootNode; |
||||
TestClassTreeNode testClassNode = (TestClassTreeNode)projectNode.Nodes[0]; |
||||
testClassNode.Expanding(); |
||||
TestClass testClass = projectNode.TestProject.TestClasses["MyTestFixture"]; |
||||
projectNode.TestProject.TestClasses.Remove(testClass); |
||||
|
||||
ExtTreeNode testClassNodeAfterRemove = null; |
||||
foreach (ExtTreeNode node in rootNode.Nodes) { |
||||
if (node.Text == "MyTestFixture") { |
||||
testClassNodeAfterRemove = node; |
||||
break; |
||||
} |
||||
} |
||||
|
||||
Assert.IsNull(testClassNodeAfterRemove); |
||||
Assert.AreEqual(0, projectNode.Nodes.Count); |
||||
Assert.IsTrue(testClassNode.IsDisposed); |
||||
|
||||
// Make sure the TestClassTreeNode.Dispose removes all event
|
||||
// handlers.
|
||||
// It uses the events:
|
||||
// TestClass.ResultChanged
|
||||
// TestClassCollection.TestMethodAdded
|
||||
// TestClassCollection.TestMethodRemoved
|
||||
|
||||
// Make sure the test class result is not a failure already.
|
||||
testClass.Result = TestResultType.None; |
||||
testClass.Result = TestResultType.Failure; |
||||
Assert.AreEqual(TestTreeViewImageListIndex.TestNotRun, |
||||
(TestTreeViewImageListIndex)testClassNode.ImageIndex, |
||||
"Disposed TestClassTreeNode affected by test class result change."); |
||||
|
||||
// Add a new test method to the test class
|
||||
// and make sure the disposed class node does
|
||||
// not add a new child node.
|
||||
Assert.AreEqual(0, testClassNode.Nodes.Count); |
||||
MockMethod mockMethod = new MockMethod("Method"); |
||||
TestMethod testMethod = new TestMethod(mockMethod); |
||||
testClass.TestMethods.Add(testMethod); |
||||
|
||||
Assert.AreEqual(0, testClassNode.Nodes.Count); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Tests that the TestProjectTreeNode handles the case where
|
||||
/// some of its children are not class nodes when removing a class.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void RemoveClassWithProjectNodeHavingNonClassNodeChildren() |
||||
{ |
||||
// Locate the class we are going to remove.
|
||||
TestProjectTreeNode projectNode = (TestProjectTreeNode)rootNode; |
||||
projectNode.Nodes.Insert(0, new ExtTreeNode()); |
||||
TestClass testClass = projectNode.TestProject.TestClasses["MyTestFixture"]; |
||||
projectNode.TestProject.TestClasses.Remove(testClass); |
||||
|
||||
ExtTreeNode testClassNode = null; |
||||
foreach (ExtTreeNode node in rootNode.Nodes) { |
||||
if (node.Text == "MyTestFixture") { |
||||
testClassNode = node; |
||||
break; |
||||
} |
||||
} |
||||
|
||||
Assert.IsNull(testClassNode); |
||||
Assert.AreEqual(1, projectNode.Nodes.Count); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Tests that the project node and the test fixture node
|
||||
/// are both disposed when the project node is disposed.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void DisposeProjectNode() |
||||
{ |
||||
rootNode.Dispose(); |
||||
rootNode.Remove(); |
||||
|
||||
Assert.IsTrue(rootNode.IsDisposed); |
||||
Assert.IsTrue(testFixtureNode.IsDisposed); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Tests that the TestProjectTreeNode.TestClassCollection.TestClassRemoved
|
||||
/// event handler is removed when the TestProjectTreeNode
|
||||
/// is disposed.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void ChangeTestClassResultAfterDisposingProjectNode() |
||||
{ |
||||
TestProjectTreeNode projectNode = (TestProjectTreeNode)rootNode; |
||||
projectNode.Dispose(); |
||||
|
||||
// Make sure the project node image index is
|
||||
// unaffected when the test class result is changed.
|
||||
Assert.AreEqual(TestTreeViewImageListIndex.TestNotRun, (TestTreeViewImageListIndex)projectNode.ImageIndex); |
||||
TestClass testClass = projectNode.TestProject.TestClasses["MyTestFixture"]; |
||||
testClass.Result = TestResultType.Failure; |
||||
Assert.AreEqual(TestTreeViewImageListIndex.TestNotRun, (TestTreeViewImageListIndex)projectNode.ImageIndex); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Tests that the TestProjectTreeNode.TestClassCollection.TestClassRemoved
|
||||
/// event handler is removed when the TestProjectTreeNode
|
||||
/// is disposed.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void AddTestClassResultAfterDisposingTestsProjectNode() |
||||
{ |
||||
TestProjectTreeNode projectNode = (TestProjectTreeNode)rootNode; |
||||
projectNode.Dispose(); |
||||
|
||||
// Make sure the project node child nodes are
|
||||
// unaffected when the test class is removed.
|
||||
Assert.AreEqual(1, projectNode.Nodes.Count); |
||||
TestClass testClass = projectNode.TestProject.TestClasses["MyTestFixture"]; |
||||
projectNode.TestProject.TestClasses.Remove(testClass); |
||||
Assert.AreEqual(1, projectNode.Nodes.Count); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Tests that the TestProjectTreeNode.TestClassCollection.TestClassAdded
|
||||
/// event handler is removed when the TestProjectTreeNode
|
||||
/// is disposed.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void RemoveTestClassResultAfterDisposingTestsProjectNode() |
||||
{ |
||||
TestProjectTreeNode projectNode = (TestProjectTreeNode)rootNode; |
||||
projectNode.Dispose(); |
||||
|
||||
// Make sure the project node child nodes are
|
||||
// unaffected when the test class is removed.
|
||||
Assert.AreEqual(1, projectNode.Nodes.Count); |
||||
MockClass mockClass = new MockClass("MyNewTestClass"); |
||||
TestClass testClass = new TestClass(mockClass); |
||||
projectNode.TestProject.TestClasses.Add(testClass); |
||||
Assert.AreEqual(1, projectNode.Nodes.Count); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,120 @@
@@ -0,0 +1,120 @@
|
||||
// <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.Windows.Forms; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using ICSharpCode.UnitTesting; |
||||
using NUnit.Framework; |
||||
using UnitTesting.Tests.Utils; |
||||
|
||||
namespace UnitTesting.Tests.Tree |
||||
{ |
||||
/// <summary>
|
||||
/// Tests TestTreeView.GetMethods.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class GetProjectsTestFixture |
||||
{ |
||||
Solution solution; |
||||
MSBuildProject project1; |
||||
MSBuildProject project2; |
||||
IProject[] projects; |
||||
DummyParserServiceTestTreeView treeView; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
solution = new Solution(); |
||||
project1 = new MSBuildProject(); |
||||
project1.Name = "A"; |
||||
ReferenceProjectItem refProjectItem = new ReferenceProjectItem(project1); |
||||
refProjectItem.Include = "NUnit.Framework"; |
||||
project1.Items.Add(refProjectItem); |
||||
solution.Folders.Add(project1); |
||||
|
||||
project2 = new MSBuildProject(); |
||||
project2.Name = "Z"; |
||||
refProjectItem = new ReferenceProjectItem(project2); |
||||
refProjectItem.Include = "NUnit.Framework"; |
||||
project2.Items.Add(refProjectItem); |
||||
solution.Folders.Add(project2); |
||||
|
||||
MockProjectContent projectContent = new MockProjectContent(); |
||||
projectContent.Project = project1; |
||||
|
||||
treeView = new DummyParserServiceTestTreeView(); |
||||
treeView.AddProjectContentForProject(projectContent); |
||||
treeView.AddSolution(solution); |
||||
projects = treeView.GetProjects(); |
||||
} |
||||
|
||||
[TearDown] |
||||
public void TearDown() |
||||
{ |
||||
if (treeView != null) { |
||||
treeView.Dispose(); |
||||
} |
||||
} |
||||
|
||||
[Test] |
||||
public void TwoProjects() |
||||
{ |
||||
Assert.AreEqual(2, projects.Length); |
||||
} |
||||
|
||||
[Test] |
||||
public void Project1Matches() |
||||
{ |
||||
bool found = false; |
||||
foreach (IProject project in projects) { |
||||
found = Object.ReferenceEquals(project, project1); |
||||
if (found) { |
||||
break; |
||||
} |
||||
} |
||||
Assert.IsTrue(found); |
||||
} |
||||
|
||||
[Test] |
||||
public void Project2Matches() |
||||
{ |
||||
bool found = false; |
||||
foreach (IProject project in projects) { |
||||
found = Object.ReferenceEquals(project, project2); |
||||
if (found) { |
||||
break; |
||||
} |
||||
} |
||||
Assert.IsTrue(found); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Tests that the TestTreeView.ResetTestResults method
|
||||
/// resets all the test results.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void ResetTestResults() |
||||
{ |
||||
foreach (IProject project in projects) { |
||||
TestProject testProject = treeView.GetTestProject(project); |
||||
MockClass mockClass = new MockClass("MyTestFixture"); |
||||
TestClass testClass = new TestClass(mockClass); |
||||
testClass.Result = TestResultType.Failure; |
||||
testProject.TestClasses.Add(testClass); |
||||
Assert.AreEqual(testProject.TestClasses.Result, TestResultType.Failure); |
||||
} |
||||
|
||||
treeView.ResetTestResults(); |
||||
foreach (IProject project in projects) { |
||||
TestProject testProject = treeView.GetTestProject(project); |
||||
Assert.AreEqual(testProject.TestClasses.Result, TestResultType.None); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,545 @@
@@ -0,0 +1,545 @@
|
||||
// <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.Windows.Forms; |
||||
|
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using ICSharpCode.UnitTesting; |
||||
using NUnit.Framework; |
||||
using UnitTesting.Tests.Utils; |
||||
|
||||
namespace UnitTesting.Tests.Tree |
||||
{ |
||||
/// <summary>
|
||||
/// Creates a test tree view with only one test class node.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class OneTestClassTestFixture |
||||
{ |
||||
ExtTreeNode rootNode; |
||||
TreeNodeCollection nodes; |
||||
DummyParserServiceTestTreeView dummyTreeView; |
||||
TestTreeView treeView; |
||||
MSBuildProject project; |
||||
MockProjectContent projectContent; |
||||
MockClass testClass; |
||||
TreeNodeCollection rootChildNodes; |
||||
ExtTreeNode rootNamespaceNode; |
||||
TreeNodeCollection rootNamespaceChildNodes; |
||||
ExtTreeNode testsNamespaceNode; |
||||
TreeNodeCollection testsNamespaceChildNodes; |
||||
ExtTreeNode testFixtureNode; |
||||
MockMethod testMethod; |
||||
TreeNodeCollection testFixtureChildNodes; |
||||
ExtTreeNode testNode; |
||||
ReferenceProjectItem nunitFrameworkReferenceItem; |
||||
|
||||
[SetUp] |
||||
public void SetUp() |
||||
{ |
||||
// Create a project to display in the test tree view.
|
||||
project = new MSBuildProject(); |
||||
project.Name = "TestProject"; |
||||
nunitFrameworkReferenceItem = new ReferenceProjectItem(project); |
||||
nunitFrameworkReferenceItem.Include = "NUnit.Framework"; |
||||
project.Items.Add(nunitFrameworkReferenceItem); |
||||
List<IProject> projects = new List<IProject>(); |
||||
projects.Add(project); |
||||
|
||||
// Add second non-test project.
|
||||
projects.Add(new MSBuildProject()); |
||||
|
||||
// Add a test class with a TestFixture attributes.
|
||||
projectContent = new MockProjectContent(); |
||||
projectContent.Language = LanguageProperties.None; |
||||
testClass = new MockClass("RootNamespace.Tests.MyTestFixture"); |
||||
testClass.Namespace = "RootNamespace.Tests"; |
||||
testClass.Attributes.Add(new MockAttribute("TestFixture")); |
||||
testClass.ProjectContent = projectContent; |
||||
projectContent.Classes.Add(testClass); |
||||
|
||||
// Add two methods to the test class only
|
||||
// one of which has test attributes.
|
||||
testMethod = new MockMethod("NameExists"); |
||||
testMethod.Attributes.Add(new MockAttribute("Test")); |
||||
testMethod.DeclaringType = testClass; |
||||
testClass.Methods.Add(testMethod); |
||||
testClass.Methods.Add(new MockMethod()); |
||||
|
||||
// Add a second class that has no test fixture attribute.
|
||||
MockClass nonTestClass = new MockClass(); |
||||
nonTestClass.ProjectContent = projectContent; |
||||
projectContent.Classes.Add(nonTestClass); |
||||
|
||||
// Init mock project content to be returned.
|
||||
dummyTreeView = new DummyParserServiceTestTreeView(); |
||||
dummyTreeView.AddProjectContentForProject(projectContent); |
||||
|
||||
// Load the projects into the test tree view.
|
||||
treeView = dummyTreeView as TestTreeView; |
||||
treeView.AddProjects(projects); |
||||
nodes = treeView.Nodes; |
||||
rootNode = (ExtTreeNode)treeView.Nodes[0]; |
||||
|
||||
// Expand the root node so any child nodes are
|
||||
// lazily created.
|
||||
rootNode.Expanding(); |
||||
rootChildNodes = rootNode.Nodes; |
||||
rootNamespaceNode = (ExtTreeNode)rootNode.Nodes[0]; |
||||
|
||||
// Expand the first namespace node.
|
||||
rootNamespaceNode.Expanding(); |
||||
rootNamespaceChildNodes = rootNamespaceNode.Nodes; |
||||
testsNamespaceNode = (ExtTreeNode)rootNamespaceNode.Nodes[0]; |
||||
|
||||
// Expand the tests namespace node.
|
||||
testsNamespaceNode.Expanding(); |
||||
testsNamespaceChildNodes = testsNamespaceNode.Nodes; |
||||
testFixtureNode = (ExtTreeNode)testsNamespaceNode.Nodes[0]; |
||||
|
||||
// Expand the test node.
|
||||
testFixtureNode.Expanding(); |
||||
testFixtureChildNodes = testFixtureNode.Nodes; |
||||
testNode = (ExtTreeNode)testFixtureChildNodes[0]; |
||||
} |
||||
|
||||
[TearDown] |
||||
public void TearDown() |
||||
{ |
||||
if (treeView != null) { |
||||
treeView.Dispose(); |
||||
} |
||||
} |
||||
|
||||
[Test] |
||||
public void OneRootNode() |
||||
{ |
||||
Assert.AreEqual(1, nodes.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void RootNodeText() |
||||
{ |
||||
Assert.AreEqual(project.Name, rootNode.Text); |
||||
} |
||||
|
||||
[Test] |
||||
public void RootNodeIsTestProjectNode() |
||||
{ |
||||
Assert.IsInstanceOfType(typeof(TestProjectTreeNode), rootNode); |
||||
} |
||||
|
||||
[Test] |
||||
public void SelectedProjectWhenNoNodeSelected() |
||||
{ |
||||
treeView.SelectedNode = null; |
||||
Assert.IsNull(treeView.SelectedProject); |
||||
} |
||||
|
||||
[Test] |
||||
public void SelectedProject() |
||||
{ |
||||
treeView.SelectedNode = rootNode; |
||||
Assert.AreSame(project, treeView.SelectedProject); |
||||
} |
||||
|
||||
[Test] |
||||
public void SelectedClass() |
||||
{ |
||||
Assert.IsNull(treeView.SelectedClass); |
||||
} |
||||
|
||||
[Test] |
||||
public void SelectedMethod() |
||||
{ |
||||
Assert.IsNull(treeView.SelectedMethod); |
||||
} |
||||
|
||||
[Test] |
||||
public void RootNodeImageIndex() |
||||
{ |
||||
Assert.AreEqual(TestTreeViewImageListIndex.TestNotRun, (TestTreeViewImageListIndex)rootNode.ImageIndex); |
||||
} |
||||
|
||||
[Test] |
||||
public void RootNodeHasOneChild() |
||||
{ |
||||
Assert.AreEqual(1, rootChildNodes.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void RootNamespaceNodeText() |
||||
{ |
||||
Assert.AreEqual("RootNamespace", rootNamespaceNode.Text); |
||||
} |
||||
|
||||
[Test] |
||||
public void RootNamespaceNodeIsTestNamespaceNode() |
||||
{ |
||||
Assert.IsInstanceOfType(typeof(TestNamespaceTreeNode), rootNamespaceNode); |
||||
} |
||||
|
||||
[Test] |
||||
public void RootNamespaceNodeHasOneChild() |
||||
{ |
||||
Assert.AreEqual(1, rootNamespaceChildNodes.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestsNamespaceNodeText() |
||||
{ |
||||
Assert.AreEqual("Tests", testsNamespaceNode.Text); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestsNamespaceNodeIsNamespaceNode() |
||||
{ |
||||
Assert.IsInstanceOfType(typeof(TestNamespaceTreeNode), testsNamespaceNode); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestsNamespaceNodeHasOneChild() |
||||
{ |
||||
Assert.AreEqual(1, testsNamespaceChildNodes.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestFixtureNodeText() |
||||
{ |
||||
Assert.AreEqual("MyTestFixture", testFixtureNode.Text); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestFixtureNodeIsTestClassNode() |
||||
{ |
||||
Assert.IsInstanceOfType(typeof(TestClassTreeNode), testFixtureNode); |
||||
} |
||||
|
||||
[Test] |
||||
public void SelectedProjectWhenClassProject() |
||||
{ |
||||
treeView.SelectedNode = testFixtureNode; |
||||
Assert.AreSame(project, treeView.SelectedProject); |
||||
} |
||||
|
||||
[Test] |
||||
public void SelectedClassWhenClassSelected() |
||||
{ |
||||
treeView.SelectedNode = testFixtureNode; |
||||
Assert.AreSame(testClass, treeView.SelectedClass); |
||||
} |
||||
|
||||
[Test] |
||||
public void SelectedTestProjectWhenClassSelected() |
||||
{ |
||||
treeView.SelectedNode = testFixtureNode; |
||||
TestProject testProject = ((TestProjectTreeNode)rootNode).TestProject; |
||||
Assert.AreSame(testProject, treeView.SelectedTestProject); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestFixtureHasOneChildNode() |
||||
{ |
||||
Assert.AreEqual(1, testFixtureChildNodes.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestMethodIsTestMethodNode() |
||||
{ |
||||
Assert.IsInstanceOfType(typeof(TestMethodTreeNode), testNode); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestMethodNodeText() |
||||
{ |
||||
Assert.AreEqual("NameExists", testNode.Text); |
||||
} |
||||
|
||||
[Test] |
||||
public void SelectedClassWhenMethodSelected() |
||||
{ |
||||
treeView.SelectedNode = testNode; |
||||
Assert.AreSame(testClass, treeView.SelectedClass); |
||||
} |
||||
|
||||
[Test] |
||||
public void SelectedMethodWhenMethodSelected() |
||||
{ |
||||
treeView.SelectedNode = testNode; |
||||
Assert.AreSame(testMethod, treeView.SelectedMethod); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestMethodFails() |
||||
{ |
||||
TestResult result = new TestResult("RootNamespace.Tests.MyTestFixture.NameExists"); |
||||
result.IsFailure = true; |
||||
TestProjectTreeNode projectNode = (TestProjectTreeNode)rootNode; |
||||
projectNode.TestProject.UpdateTestResult(result); |
||||
|
||||
Assert.AreEqual(TestTreeViewImageListIndex.TestFailed, (TestTreeViewImageListIndex)testNode.ImageIndex); |
||||
Assert.AreEqual(TestTreeViewImageListIndex.TestFailed, (TestTreeViewImageListIndex)testFixtureNode.ImageIndex); |
||||
Assert.AreEqual(TestTreeViewImageListIndex.TestFailed, (TestTreeViewImageListIndex)testsNamespaceNode.ImageIndex); |
||||
Assert.AreEqual(TestTreeViewImageListIndex.TestFailed, (TestTreeViewImageListIndex)rootNamespaceNode.ImageIndex); |
||||
Assert.AreEqual(TestTreeViewImageListIndex.TestFailed, (TestTreeViewImageListIndex)rootNode.ImageIndex); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestMethodPasses() |
||||
{ |
||||
TestResult result = new TestResult("RootNamespace.Tests.MyTestFixture.NameExists"); |
||||
result.IsSuccess = true; |
||||
TestProjectTreeNode projectNode = (TestProjectTreeNode)rootNode; |
||||
projectNode.TestProject.UpdateTestResult(result); |
||||
|
||||
Assert.AreEqual(TestTreeViewImageListIndex.TestPassed, (TestTreeViewImageListIndex)testNode.ImageIndex); |
||||
Assert.AreEqual(TestTreeViewImageListIndex.TestPassed, (TestTreeViewImageListIndex)testFixtureNode.ImageIndex); |
||||
Assert.AreEqual(TestTreeViewImageListIndex.TestPassed, (TestTreeViewImageListIndex)testsNamespaceNode.ImageIndex); |
||||
Assert.AreEqual(TestTreeViewImageListIndex.TestPassed, (TestTreeViewImageListIndex)rootNamespaceNode.ImageIndex); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestMethodIgnored() |
||||
{ |
||||
TestResult result = new TestResult("RootNamespace.Tests.MyTestFixture.NameExists"); |
||||
result.IsIgnored = true; |
||||
TestProjectTreeNode projectNode = (TestProjectTreeNode)rootNode; |
||||
projectNode.TestProject.UpdateTestResult(result); |
||||
|
||||
Assert.AreEqual(TestTreeViewImageListIndex.TestIgnored, (TestTreeViewImageListIndex)testNode.ImageIndex); |
||||
Assert.AreEqual(TestTreeViewImageListIndex.TestIgnored, (TestTreeViewImageListIndex)testFixtureNode.ImageIndex); |
||||
Assert.AreEqual(TestTreeViewImageListIndex.TestIgnored, (TestTreeViewImageListIndex)testFixtureNode.SelectedImageIndex); |
||||
Assert.AreEqual(TestTreeViewImageListIndex.TestIgnored, (TestTreeViewImageListIndex)rootNamespaceNode.ImageIndex); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestMethodResultSetBackToNoneAfterReset() |
||||
{ |
||||
TestMethodIgnored(); |
||||
|
||||
TestProjectTreeNode projectNode = (TestProjectTreeNode)rootNode; |
||||
projectNode.TestProject.ResetTestResults(); |
||||
|
||||
Assert.AreEqual(TestTreeViewImageListIndex.TestNotRun, (TestTreeViewImageListIndex)testNode.ImageIndex); |
||||
Assert.AreEqual(TestTreeViewImageListIndex.TestNotRun, (TestTreeViewImageListIndex)testFixtureNode.ImageIndex); |
||||
Assert.AreEqual(TestTreeViewImageListIndex.TestNotRun, (TestTreeViewImageListIndex)rootNode.ImageIndex); |
||||
Assert.AreEqual(TestTreeViewImageListIndex.TestNotRun, (TestTreeViewImageListIndex)testsNamespaceNode.ImageIndex); |
||||
Assert.AreEqual(TestTreeViewImageListIndex.TestNotRun, (TestTreeViewImageListIndex)rootNamespaceNode.ImageIndex); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Tests that a new method node is added to the test class node.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void NewMethodAdded() |
||||
{ |
||||
TestProjectTreeNode projectNode = (TestProjectTreeNode)rootNode; |
||||
TestClass testClass = projectNode.TestProject.TestClasses["RootNamespace.Tests.MyTestFixture"]; |
||||
|
||||
MockMethod method = new MockMethod("NewMethod"); |
||||
method.DeclaringType = testClass.Class; |
||||
method.Attributes.Add(new MockAttribute("Test")); |
||||
testClass.TestMethods.Add(new TestMethod(method)); |
||||
|
||||
ExtTreeNode newMethodNode = null; |
||||
foreach (ExtTreeNode node in testFixtureNode.Nodes) { |
||||
if (node.Text == "NewMethod") { |
||||
newMethodNode = node; |
||||
break; |
||||
} |
||||
} |
||||
|
||||
Assert.AreEqual(2, testFixtureNode.Nodes.Count); |
||||
Assert.IsNotNull(newMethodNode); |
||||
Assert.IsInstanceOfType(typeof(TestMethodTreeNode), newMethodNode); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Tests that when a test method is removed from a test class the
|
||||
/// TestClassTreeNode updates itself and removes the test method.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void MethodRemoved() |
||||
{ |
||||
TestProjectTreeNode projectNode = (TestProjectTreeNode)rootNode; |
||||
TestClass testClass = projectNode.TestProject.TestClasses["RootNamespace.Tests.MyTestFixture"]; |
||||
|
||||
TestMethodTreeNode methodNode = (TestMethodTreeNode)testFixtureNode.Nodes[0]; |
||||
TestMethod testMethod = testClass.TestMethods[0]; |
||||
testClass.TestMethods.Remove(testMethod); |
||||
|
||||
Assert.AreEqual(0, testFixtureNode.Nodes.Count); |
||||
Assert.IsTrue(methodNode.IsDisposed); |
||||
|
||||
// Make sure the TestMethod.Dispose call removes all
|
||||
// event handlers by changing the TestMethod's test
|
||||
// result and seeing if the test method node is
|
||||
// affected even though we have removed it from the tree.
|
||||
|
||||
// Make sure the test method result is not already a failure.
|
||||
testMethod.Result = TestResultType.None; |
||||
testMethod.Result = TestResultType.Failure; |
||||
Assert.AreEqual(TestTreeViewImageListIndex.TestNotRun, |
||||
(TestTreeViewImageListIndex)methodNode.ImageIndex, |
||||
"Disposed TestMethodTreeNode was affected by TestMethod result change"); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Tests that when a test class is removed the removed class
|
||||
/// node is not changed when one of the class's methods is removed.
|
||||
/// The test makes sure that the TestClassTreeNode.Dispose
|
||||
/// removes the TestMethods.TestMethodRemoved event handler.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void ClassRemoved() |
||||
{ |
||||
TestProjectTreeNode projectNode = (TestProjectTreeNode)rootNode; |
||||
TestClass testClass = projectNode.TestProject.TestClasses["RootNamespace.Tests.MyTestFixture"]; |
||||
TestMethodTreeNode methodNode = (TestMethodTreeNode)testFixtureNode.Nodes[0]; |
||||
|
||||
testFixtureNode.Expanding(); |
||||
|
||||
// Sanity check - test fixture node should have one method node.
|
||||
Assert.AreEqual(1, testFixtureNode.Nodes.Count); |
||||
|
||||
projectNode.TestProject.TestClasses.Remove(testClass); |
||||
|
||||
// Method node should be disposed when parent class
|
||||
// node is disposed.
|
||||
Assert.IsTrue(methodNode.IsDisposed); |
||||
|
||||
// Make sure the TestClass.Dispose call removes all
|
||||
// event handlers.
|
||||
testClass.TestMethods.RemoveAt(0); |
||||
|
||||
Assert.AreEqual(1, testFixtureNode.Nodes.Count, |
||||
"Should still have one child node."); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// The test project tree node should be removed when it no longer
|
||||
/// references the NUnit.Framework assembly.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void TestProjectNUnitReferenceRemoved() |
||||
{ |
||||
TestProjectTreeNode projectNode = (TestProjectTreeNode)rootNode; |
||||
projectNode.TestProject.Project.Items.Remove(nunitFrameworkReferenceItem); |
||||
|
||||
treeView.ProjectReferencesChanged(projectNode.TestProject.Project); |
||||
|
||||
Assert.AreEqual(0, treeView.Nodes.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void UnknownProjectHasReferenceRemoved() |
||||
{ |
||||
MSBuildProject project = new MSBuildProject(); |
||||
treeView.ProjectReferencesChanged(project); |
||||
|
||||
Assert.AreEqual(1, treeView.Nodes.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void UnknownProjectHasNUnitReferenceAdded() |
||||
{ |
||||
project = new MSBuildProject(); |
||||
project.Name = "NewProject"; |
||||
nunitFrameworkReferenceItem = new ReferenceProjectItem(project); |
||||
nunitFrameworkReferenceItem.Include = "NUnit.Framework"; |
||||
project.Items.Add(nunitFrameworkReferenceItem); |
||||
|
||||
treeView.ProjectReferencesChanged(project); |
||||
|
||||
ExtTreeNode newProjectNode = null; |
||||
foreach (ExtTreeNode node in treeView.Nodes) { |
||||
if (node.Text == "NewProject") { |
||||
newProjectNode = node; |
||||
break; |
||||
} |
||||
} |
||||
|
||||
Assert.AreEqual(2, treeView.Nodes.Count); |
||||
Assert.IsNotNull(newProjectNode); |
||||
} |
||||
|
||||
[Test] |
||||
public void ProjectRemoved() |
||||
{ |
||||
TestProjectTreeNode projectNode = (TestProjectTreeNode)rootNode; |
||||
treeView.RemoveProject(projectNode.TestProject.Project); |
||||
|
||||
Assert.AreEqual(0, treeView.Nodes.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void OwnerStateWhenProjectNodeSelected() |
||||
{ |
||||
treeView.SelectedNode = rootNode; |
||||
Assert.AreEqual(TestTreeView.TestTreeViewState.None, (TestTreeView.TestTreeViewState)treeView.InternalState); |
||||
} |
||||
|
||||
[Test] |
||||
public void OwnerStateWhenTestClassNodeSelected() |
||||
{ |
||||
treeView.SelectedNode = testFixtureNode; |
||||
Assert.AreEqual(TestTreeView.TestTreeViewState.SourceCodeItemSelected, (TestTreeView.TestTreeViewState)treeView.InternalState); |
||||
} |
||||
|
||||
[Test] |
||||
public void OwnerStateWhenTestMethodNodeSelected() |
||||
{ |
||||
treeView.SelectedNode = testNode; |
||||
Assert.AreEqual(TestTreeView.TestTreeViewState.SourceCodeItemSelected, (TestTreeView.TestTreeViewState)treeView.InternalState); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Tests that the TestProject.TestClasses.TestClassRemoved
|
||||
/// event handler is removed when the TestTreeNamespaceNode
|
||||
/// is disposed.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void RemoveClassAfterDisposingTestsNamespaceNode() |
||||
{ |
||||
testsNamespaceNode.Dispose(); |
||||
testsNamespaceNode.Remove(); |
||||
|
||||
TestProjectTreeNode projectNode = (TestProjectTreeNode)rootNode; |
||||
|
||||
// Make sure the tests namespace node child nodes are
|
||||
// unaffected when the test class is removed.
|
||||
Assert.AreEqual(1, testsNamespaceNode.Nodes.Count); |
||||
projectNode.TestProject.TestClasses.Remove("RootNamespace.Tests.MyTestFixture"); |
||||
Assert.AreEqual(1, testsNamespaceNode.Nodes.Count); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Tests that the TestNamespaceTreeNode.TestClassCollection.TestClassRemoved
|
||||
/// event handler is removed when the TestTreeNamespaceNode
|
||||
/// is disposed.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void ChangeTestClassResultAfterDisposingTestsNamespaceNode() |
||||
{ |
||||
testsNamespaceNode.Dispose(); |
||||
testsNamespaceNode.Remove(); |
||||
|
||||
TestProjectTreeNode projectNode = (TestProjectTreeNode)rootNode; |
||||
|
||||
// Make sure the tests namespace node image index is
|
||||
// unaffected when the test class test result is changed.
|
||||
Assert.AreEqual(TestTreeViewImageListIndex.TestNotRun, (TestTreeViewImageListIndex)testsNamespaceNode.ImageIndex); |
||||
TestClass testClass = projectNode.TestProject.TestClasses["RootNamespace.Tests.MyTestFixture"]; |
||||
testClass.Result = TestResultType.Failure; |
||||
Assert.AreEqual(TestTreeViewImageListIndex.TestNotRun, (TestTreeViewImageListIndex)testsNamespaceNode.ImageIndex); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,303 @@
@@ -0,0 +1,303 @@
|
||||
// <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.Windows.Forms; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using ICSharpCode.UnitTesting; |
||||
using NUnit.Framework; |
||||
using UnitTesting.Tests.Utils; |
||||
|
||||
namespace UnitTesting.Tests.Tree |
||||
{ |
||||
/// <summary>
|
||||
/// Tests that the UnitTestPad loads the test tree view when
|
||||
/// a new solution is opened.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class SolutionOpenedTestFixture : UnitTestsPad |
||||
{ |
||||
Solution solution; |
||||
MSBuildProject project; |
||||
MockProjectContent projectContent = new MockProjectContent(); |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
solution = new Solution(); |
||||
project = new MSBuildProject(); |
||||
projectContent.Project = project; |
||||
projectContent.Language = LanguageProperties.None; |
||||
ReferenceProjectItem refProjectItem = new ReferenceProjectItem(project); |
||||
refProjectItem.Include = "NUnit.Framework"; |
||||
project.Items.Add(refProjectItem); |
||||
solution.Folders.Add(project); |
||||
|
||||
base.SolutionLoaded(solution); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestTreeHasNodes() |
||||
{ |
||||
Assert.AreEqual(1, base.TestTreeView.Nodes.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void CloseSolution() |
||||
{ |
||||
base.SolutionClosed(); |
||||
|
||||
Assert.AreEqual(0, base.TestTreeView.Nodes.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void SolutionFolderRemoved() |
||||
{ |
||||
base.SolutionFolderRemoved(project); |
||||
|
||||
Assert.AreEqual(0, base.TestTreeView.Nodes.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void ProjectAdded() |
||||
{ |
||||
MSBuildProject project = new MSBuildProject(); |
||||
project.Name = "NewProject"; |
||||
ReferenceProjectItem refProjectItem = new ReferenceProjectItem(project); |
||||
refProjectItem.Include = "NUnit.Framework"; |
||||
project.Items.Add(refProjectItem); |
||||
|
||||
base.ProjectAdded(project); |
||||
|
||||
Assert.AreEqual(2, base.TestTreeView.Nodes.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void ReferenceProjectItemRemoved() |
||||
{ |
||||
ProjectItem refProjectItem = project.Items[0]; |
||||
project.Items.Remove(refProjectItem); |
||||
|
||||
base.ProjectItemRemoved(refProjectItem); |
||||
|
||||
Assert.AreEqual(0, base.TestTreeView.Nodes.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void ReferenceProjectItemAdded() |
||||
{ |
||||
MSBuildProject project = new MSBuildProject(); |
||||
project.Name = "NewProject"; |
||||
|
||||
base.ProjectAdded(project); |
||||
|
||||
// Project should not be added at first.
|
||||
Assert.AreEqual(1, base.TestTreeView.Nodes.Count); |
||||
|
||||
ReferenceProjectItem refProjectItem = new ReferenceProjectItem(project); |
||||
refProjectItem.Include = "NUnit.Framework"; |
||||
project.Items.Add(refProjectItem); |
||||
|
||||
base.ProjectItemAdded(refProjectItem); |
||||
|
||||
// Project should be added since it has a reference to
|
||||
// NUnit.
|
||||
Assert.AreEqual(2, base.TestTreeView.Nodes.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void ReferenceProjectItemAddedTwice() |
||||
{ |
||||
MSBuildProject project = new MSBuildProject(); |
||||
project.Name = "NewProject"; |
||||
ReferenceProjectItem refProjectItem = new ReferenceProjectItem(project); |
||||
refProjectItem.Include = "NUnit.Framework"; |
||||
project.Items.Add(refProjectItem); |
||||
|
||||
base.ProjectAdded(project); |
||||
|
||||
project.Items.Add(refProjectItem); |
||||
|
||||
base.ProjectItemAdded(refProjectItem); |
||||
|
||||
Assert.AreEqual(2, base.TestTreeView.Nodes.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void ParserInfoUpdated() |
||||
{ |
||||
DefaultCompilationUnit newUnit = new DefaultCompilationUnit(projectContent); |
||||
MockClass mockClass = new MockClass("MyTestFixture"); |
||||
mockClass.Attributes.Add(new MockAttribute("TestFixture")); |
||||
mockClass.ProjectContent = projectContent; |
||||
mockClass.SetCompoundClass(mockClass); |
||||
newUnit.Classes.Add(mockClass); |
||||
|
||||
ExtTreeNode rootNode = (ExtTreeNode)base.TestTreeView.Nodes[0]; |
||||
rootNode.Expanding(); |
||||
|
||||
base.UpdateParseInfo(null, newUnit); |
||||
|
||||
Assert.AreEqual(1, rootNode.Nodes.Count); |
||||
Assert.AreEqual("MyTestFixture", rootNode.Nodes[0].Text); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetTestProjectFromProject() |
||||
{ |
||||
TestProjectTreeNode projectNode = (TestProjectTreeNode)base.TestTreeView.Nodes[0]; |
||||
TestProject expectedTestProject = projectNode.TestProject; |
||||
|
||||
Assert.AreSame(expectedTestProject, base.TestTreeView.GetTestProject(project)); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Tests that an empty project node after being expanded
|
||||
/// will update itself if a new class is added to the project.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void ClassNodeAddedAfterProjectNodeExpanded() |
||||
{ |
||||
// Expand the project node.
|
||||
TestProjectTreeNode projectNode = (TestProjectTreeNode)base.TestTreeView.Nodes[0]; |
||||
projectNode.Expanding(); |
||||
|
||||
// Add a new class to a non-empty namespace so it gets
|
||||
// added to a new namespace node.
|
||||
MockClass mockClass = new MockClass("RootNamespace.MyTestFixture"); |
||||
TestClass testClass = new TestClass(mockClass); |
||||
projectNode.TestProject.TestClasses.Add(testClass); |
||||
|
||||
Assert.AreEqual(1, projectNode.Nodes.Count, |
||||
"Project node should have one child node."); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Tests the following:
|
||||
///
|
||||
/// A parent namespace node has been expanded and initially
|
||||
/// there are no namespace nodes below it, just one test
|
||||
/// class. Then a new test class is added which should
|
||||
/// cause a new namespace node to be added to the existing
|
||||
/// node.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void ClassNodeAddedAfterNamespaceNodeExpanded() |
||||
{ |
||||
ClassNodeAddedAfterProjectNodeExpanded(); |
||||
|
||||
// Expand the namespace node.
|
||||
TestProjectTreeNode projectNode = (TestProjectTreeNode)base.TestTreeView.Nodes[0]; |
||||
TestNamespaceTreeNode parentNamespaceNode = (TestNamespaceTreeNode)projectNode.Nodes[0]; |
||||
parentNamespaceNode.Expanding(); |
||||
|
||||
// Add a new class to a namespace so it gets
|
||||
// added to a new namespace node.
|
||||
MockClass mockClass = new MockClass("RootNamespace.Tests.MyTestFixture"); |
||||
TestClass testClass = new TestClass(mockClass); |
||||
projectNode.TestProject.TestClasses.Add(testClass); |
||||
|
||||
// Get the newly added namespace node.
|
||||
TestNamespaceTreeNode namespaceNode = null; |
||||
foreach (ExtTreeNode node in parentNamespaceNode.Nodes) { |
||||
namespaceNode = node as TestNamespaceTreeNode; |
||||
if (namespaceNode != null) { |
||||
break; |
||||
} |
||||
} |
||||
|
||||
Assert.AreEqual(2, parentNamespaceNode.Nodes.Count, |
||||
"Namespace node should have two child nodes."); |
||||
Assert.IsNotNull(namespaceNode, "Namespace node has not been added"); |
||||
Assert.AreEqual("Tests", namespaceNode.Text); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Adds a new test class in the non-existant namespace
|
||||
/// RootNamepace.Tests, expands both these namespace tree nodes
|
||||
/// and then removes the test class from the TestProject.TestClasses
|
||||
/// collection. The test then checks that the two namespace
|
||||
/// nodes are removed from the tree.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void EmptyNamespaceNodesRemoved() |
||||
{ |
||||
// Expand the project node.
|
||||
TestProjectTreeNode projectNode = (TestProjectTreeNode)base.TestTreeView.Nodes[0]; |
||||
projectNode.Expanding(); |
||||
|
||||
// Add a new class to a non-empty namespace so it gets
|
||||
// added to a new namespace node.
|
||||
MockClass mockClass = new MockClass("RootNamespace.Tests.MyTestFixture"); |
||||
TestClass testClass = new TestClass(mockClass); |
||||
projectNode.TestProject.TestClasses.Add(testClass); |
||||
|
||||
// Expand RootNamespace tree node.
|
||||
TestNamespaceTreeNode rootNamespaceNode = (TestNamespaceTreeNode)projectNode.Nodes[0]; |
||||
rootNamespaceNode.Expanding(); |
||||
|
||||
// Expand the Tests namespace tree node.
|
||||
TestNamespaceTreeNode testsNamespaceNode = (TestNamespaceTreeNode)rootNamespaceNode.Nodes[0]; |
||||
testsNamespaceNode.Expanding(); |
||||
|
||||
// Get the test class node.
|
||||
TestClassTreeNode classNode = (TestClassTreeNode)testsNamespaceNode.Nodes[0]; |
||||
|
||||
// Remove the test class from the test project.
|
||||
projectNode.TestProject.TestClasses.Remove(testClass); |
||||
|
||||
Assert.AreEqual(0, projectNode.Nodes.Count, |
||||
"Namespace nodes should have been removed from project node."); |
||||
|
||||
// Make sure the two namespace nodes are properly disposed.
|
||||
Assert.IsTrue(testsNamespaceNode.IsDisposed); |
||||
Assert.IsTrue(rootNamespaceNode.IsDisposed); |
||||
|
||||
// Make sure the test class node has been disposed.
|
||||
Assert.IsTrue(classNode.IsDisposed); |
||||
|
||||
// Make sure the namespace node Dispose method removes
|
||||
// the TestProject.TestClasses.TestClassAdded event handler.
|
||||
Assert.AreEqual(0, testsNamespaceNode.Nodes.Count); |
||||
projectNode.TestProject.TestClasses.Add(testClass); |
||||
Assert.AreEqual(0, testsNamespaceNode.Nodes.Count); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns a dummy toolstrip so the UnitTestsPad can be
|
||||
/// tested. If the default method is called the AddInTree
|
||||
/// is referenced which is not available during testing.
|
||||
/// </summary>
|
||||
protected override ToolStrip CreateToolStrip(string name) |
||||
{ |
||||
return new ToolStrip(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns a dummy ContextMenuStrip so the UnitTestsPad can be
|
||||
/// tested. If the default method is called the AddInTree
|
||||
/// is referenced which is not available during testing.
|
||||
/// </summary>
|
||||
protected override ContextMenuStrip CreateContextMenu(string name) |
||||
{ |
||||
return new ContextMenuStrip(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns a dummy tree view where we can mock the
|
||||
/// IProjectContent that will be used by the TestTreeView.
|
||||
/// </summary>
|
||||
protected override TestTreeView CreateTestTreeView() |
||||
{ |
||||
DummyParserServiceTestTreeView treeView = new DummyParserServiceTestTreeView(); |
||||
treeView.AddProjectContentForProject(projectContent); |
||||
return treeView; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,290 @@
@@ -0,0 +1,290 @@
|
||||
// <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.Windows.Forms; |
||||
|
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using ICSharpCode.UnitTesting; |
||||
using NUnit.Framework; |
||||
using UnitTesting.Tests.Utils; |
||||
|
||||
namespace UnitTesting.Tests.Tree |
||||
{ |
||||
/// <summary>
|
||||
/// Tests that when a namespace tree node has a class and another
|
||||
/// namespace as a child the image index is updated correctly.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class TwoTestClassesInDifferentNamesTestFixture |
||||
{ |
||||
Solution solution; |
||||
ExtTreeNode rootNode; |
||||
TreeNodeCollection nodes; |
||||
DummyParserServiceTestTreeView dummyTreeView; |
||||
TestTreeView treeView; |
||||
MSBuildProject project; |
||||
MockClass testClass1; |
||||
MockClass testClass2; |
||||
ExtTreeNode projectNamespaceNode; |
||||
TestProject testProject; |
||||
MockProjectContent projectContent; |
||||
|
||||
[SetUp] |
||||
public void SetUp() |
||||
{ |
||||
// Create solution.
|
||||
solution = new Solution(); |
||||
|
||||
// Create a project to display in the test tree view.
|
||||
project = new MSBuildProject(); |
||||
project.Name = "TestProject"; |
||||
ReferenceProjectItem nunitFrameworkReferenceItem = new ReferenceProjectItem(project); |
||||
nunitFrameworkReferenceItem.Include = "NUnit.Framework"; |
||||
project.Items.Add(nunitFrameworkReferenceItem); |
||||
|
||||
// Add a test class with a TestFixture attributes.
|
||||
projectContent = new MockProjectContent(); |
||||
projectContent.Language = LanguageProperties.None; |
||||
testClass1 = new MockClass("Project.Tests.MyTestFixture"); |
||||
testClass1.Attributes.Add(new MockAttribute("TestFixture")); |
||||
testClass1.ProjectContent = projectContent; |
||||
projectContent.Classes.Add(testClass1); |
||||
|
||||
testClass2 = new MockClass("Project.MyTestFixture"); |
||||
testClass2.Attributes.Add(new MockAttribute("TestFixture")); |
||||
testClass2.ProjectContent = projectContent; |
||||
projectContent.Classes.Add(testClass2); |
||||
|
||||
// Init mock project content to be returned.
|
||||
dummyTreeView = new DummyParserServiceTestTreeView(); |
||||
dummyTreeView.AddProjectContentForProject(projectContent); |
||||
|
||||
// Load the projects into the test tree view.
|
||||
treeView = dummyTreeView as TestTreeView; |
||||
solution.Folders.Add(project); |
||||
treeView.AddSolution(solution); |
||||
nodes = treeView.Nodes; |
||||
rootNode = (ExtTreeNode)treeView.Nodes[0]; |
||||
|
||||
treeView.SelectedNode = rootNode; |
||||
testProject = treeView.SelectedTestProject; |
||||
} |
||||
|
||||
[TearDown] |
||||
public void TearDown() |
||||
{ |
||||
if (treeView != null) { |
||||
treeView.Dispose(); |
||||
} |
||||
} |
||||
|
||||
public void ExpandRootNode() |
||||
{ |
||||
// Expand the root node so any child nodes are lazily created.
|
||||
rootNode.Expanding(); |
||||
projectNamespaceNode = (ExtTreeNode)rootNode.Nodes[0]; |
||||
} |
||||
|
||||
[Test] |
||||
public void TestClass2PassedAfterTestClass1Failed() |
||||
{ |
||||
ExpandRootNode(); |
||||
|
||||
TestClass testClass1 = testProject.TestClasses["Project.Tests.MyTestFixture"]; |
||||
testClass1.Result = TestResultType.Failure; |
||||
|
||||
TestClass testClass2 = testProject.TestClasses["Project.MyTestFixture"]; |
||||
testClass2.Result = TestResultType.Success; |
||||
|
||||
Assert.AreEqual(TestTreeViewImageListIndex.TestFailed, (TestTreeViewImageListIndex)projectNamespaceNode.ImageIndex); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestClass2PassedAfterTestClass1Ignored() |
||||
{ |
||||
ExpandRootNode(); |
||||
|
||||
TestClass testClass1 = testProject.TestClasses["Project.Tests.MyTestFixture"]; |
||||
testClass1.Result = TestResultType.Ignored; |
||||
|
||||
TestClass testClass2 = testProject.TestClasses["Project.MyTestFixture"]; |
||||
testClass2.Result = TestResultType.Success; |
||||
|
||||
Assert.AreEqual(TestTreeViewImageListIndex.TestIgnored, (TestTreeViewImageListIndex)projectNamespaceNode.ImageIndex); |
||||
} |
||||
|
||||
[Test] |
||||
public void ExpandProjectNodeAfterOnePassOneFail() |
||||
{ |
||||
TestClass testClass1 = testProject.TestClasses["Project.Tests.MyTestFixture"]; |
||||
testClass1.Result = TestResultType.Failure; |
||||
|
||||
TestClass testClass2 = testProject.TestClasses["Project.MyTestFixture"]; |
||||
testClass2.Result = TestResultType.Success; |
||||
|
||||
ExpandRootNode(); |
||||
Assert.AreEqual(TestTreeViewImageListIndex.TestFailed, (TestTreeViewImageListIndex)projectNamespaceNode.ImageIndex); |
||||
} |
||||
|
||||
[Test] |
||||
public void AddNewClass() |
||||
{ |
||||
ExtTreeNode projectNamespaceNode = ExpandProjectNamespaceNode(); |
||||
ExtTreeNode testsNamespaceNode = ExpandTestsNamespaceNode(); |
||||
|
||||
MockClass mockClass = new MockClass("Project.Tests.MyNewTestFixture"); |
||||
mockClass.Attributes.Add(new MockAttribute("TestFixture")); |
||||
mockClass.ProjectContent = projectContent; |
||||
TestClass newTestClass = new TestClass(mockClass); |
||||
testProject.TestClasses.Add(newTestClass); |
||||
|
||||
ExtTreeNode newTestClassNode = null; |
||||
foreach (ExtTreeNode node in testsNamespaceNode.Nodes) { |
||||
if (node.Text == "MyNewTestFixture") { |
||||
newTestClassNode = node; |
||||
break; |
||||
} |
||||
} |
||||
newTestClass.Result = TestResultType.Failure; |
||||
|
||||
// New test class node should be added to the test namespace node.
|
||||
Assert.AreEqual(2, testsNamespaceNode.Nodes.Count); |
||||
Assert.IsNotNull(newTestClassNode); |
||||
|
||||
// Make sure the namespace node image index is affected by the
|
||||
// new test class added.
|
||||
Assert.AreEqual(TestTreeViewImageListIndex.TestFailed, (TestTreeViewImageListIndex)testsNamespaceNode.SelectedImageIndex); |
||||
|
||||
// Project namespace node should have two child nodes, one for the
|
||||
// Tests namespace and one test class node.
|
||||
Assert.AreEqual(2, projectNamespaceNode.Nodes.Count); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Tests that the test class is removed from the tree.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void RemoveClass() |
||||
{ |
||||
AddNewClass(); |
||||
|
||||
ExtTreeNode projectNamespaceNode = ExpandProjectNamespaceNode(); |
||||
ExtTreeNode testsNamespaceNode = ExpandTestsNamespaceNode(); |
||||
|
||||
// Reset the new TestClass result after it was modified
|
||||
// in the AddNewClass call.
|
||||
TestClass newTestClass = testProject.TestClasses["Project.Tests.MyNewTestFixture"]; |
||||
newTestClass.Result = TestResultType.None; |
||||
|
||||
// Locate the class we are going to remove.
|
||||
TestClass testClass = testProject.TestClasses["Project.Tests.MyTestFixture"]; |
||||
testProject.TestClasses.Remove(testClass); |
||||
|
||||
ExtTreeNode testClassNode = null; |
||||
foreach (ExtTreeNode node in testsNamespaceNode.Nodes) { |
||||
if (node.Text == "MyTestFixture") { |
||||
testClassNode = node; |
||||
break; |
||||
} |
||||
} |
||||
testClass.Result = TestResultType.Failure; |
||||
|
||||
Assert.AreEqual(1, testsNamespaceNode.Nodes.Count); |
||||
Assert.IsNull(testClassNode); |
||||
|
||||
// Make sure the namespace node image index is NOT affected by the
|
||||
// test class just removed.
|
||||
Assert.AreEqual(TestTreeViewImageListIndex.TestNotRun, (TestTreeViewImageListIndex)testsNamespaceNode.SelectedImageIndex); |
||||
|
||||
// Check that the test class does not affect the project namespace node
|
||||
// image index either.
|
||||
Assert.AreEqual(TestTreeViewImageListIndex.TestNotRun, (TestTreeViewImageListIndex)projectNamespaceNode.ImageIndex); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Tests that after all the child nodes from a namespace node are removed
|
||||
/// the namespace node removes itself.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void RemoveNamespaceNode() |
||||
{ |
||||
ExtTreeNode projectNamespaceNode = ExpandProjectNamespaceNode(); |
||||
ExtTreeNode testsNamespaceNode = ExpandTestsNamespaceNode(); |
||||
|
||||
// Locate the class we are going to remove.
|
||||
TestClass testClass = testProject.TestClasses["Project.Tests.MyTestFixture"]; |
||||
testProject.TestClasses.Remove(testClass); |
||||
|
||||
ExtTreeNode testClassNode = null; |
||||
foreach (ExtTreeNode node in testsNamespaceNode.Nodes) { |
||||
if (node.Text == "MyTestFixture") { |
||||
testClassNode = node; |
||||
break; |
||||
} |
||||
} |
||||
Assert.IsNull(testClassNode); |
||||
|
||||
// Project namespace node should only have one child node.
|
||||
Assert.AreEqual(1, projectNamespaceNode.Nodes.Count); |
||||
Assert.AreEqual("MyTestFixture", projectNamespaceNode.Nodes[0].Text); |
||||
} |
||||
|
||||
[Test] |
||||
public void RemoveClassFromNamespaceNodeWithNonClassNodeChildren() |
||||
{ |
||||
ExtTreeNode projectNamespaceNode = ExpandProjectNamespaceNode(); |
||||
ExtTreeNode testsNamespaceNode = ExpandTestsNamespaceNode(); |
||||
|
||||
// Add a dummy tree node to the tests namespace node to make
|
||||
// sure the TestNamespaceTreeNode handles non-TestClassTreeNode
|
||||
// children when removing a class.
|
||||
testsNamespaceNode.Nodes.Insert(0, new ExtTreeNode()); |
||||
|
||||
// Locate the class we are going to remove.
|
||||
TestClass testClass = testProject.TestClasses["Project.Tests.MyTestFixture"]; |
||||
testProject.TestClasses.Remove(testClass); |
||||
|
||||
ExtTreeNode testClassNode = null; |
||||
foreach (ExtTreeNode node in testsNamespaceNode.Nodes) { |
||||
if (node.Text == "MyTestFixture") { |
||||
testClassNode = node; |
||||
break; |
||||
} |
||||
} |
||||
Assert.IsNull(testClassNode); |
||||
Assert.AreEqual(1, testsNamespaceNode.Nodes.Count); |
||||
} |
||||
|
||||
ExtTreeNode ExpandProjectNamespaceNode() |
||||
{ |
||||
ExpandRootNode(); |
||||
foreach (ExtTreeNode node in rootNode.Nodes) { |
||||
if (node.Text == "Project") { |
||||
node.Expanding(); |
||||
return node; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
ExtTreeNode ExpandTestsNamespaceNode() |
||||
{ |
||||
ExtTreeNode projectNamespaceNode = ExpandProjectNamespaceNode(); |
||||
foreach (ExtTreeNode childNode in projectNamespaceNode.Nodes) { |
||||
if (childNode.Text == "Tests") { |
||||
childNode.Expanding(); |
||||
return childNode; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,128 @@
@@ -0,0 +1,128 @@
|
||||
// <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; |
||||
|
||||
namespace UnitTesting.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class UnitTestCommandLineTests |
||||
{ |
||||
MSBuildProject project; |
||||
UnitTestApplicationStartHelper helper; |
||||
|
||||
[SetUp] |
||||
public void SetUp() |
||||
{ |
||||
project = new MSBuildProject(); |
||||
project.FileName = @"C:\Projects\MyTests\MyTests.csproj"; |
||||
project.AssemblyName = "MyTests"; |
||||
project.OutputType = OutputType.Library; |
||||
helper = new UnitTestApplicationStartHelper(); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestResultsFile() |
||||
{ |
||||
helper.Initialize(project, null, null); |
||||
helper.NoLogo = false; |
||||
helper.ShadowCopy = true; |
||||
helper.Results = @"C:\results.txt"; |
||||
|
||||
string expectedCommandLine = "\"C:\\Projects\\MyTests\\MyTests.dll\" /results=\"C:\\results.txt\""; |
||||
Assert.AreEqual(expectedCommandLine, helper.GetArguments()); |
||||
} |
||||
|
||||
[Test] |
||||
public void NoLogo() |
||||
{ |
||||
helper.Initialize(project, null, null); |
||||
helper.NoLogo = true; |
||||
helper.ShadowCopy = true; |
||||
|
||||
string expectedCommandLine = "\"C:\\Projects\\MyTests\\MyTests.dll\" /nologo"; |
||||
Assert.AreEqual(expectedCommandLine, helper.GetArguments()); |
||||
} |
||||
|
||||
[Test] |
||||
public void NoShadowCopy() |
||||
{ |
||||
helper.Initialize(project, null, null); |
||||
helper.NoLogo = false; |
||||
helper.ShadowCopy = false; |
||||
|
||||
string expectedCommandLine = "\"C:\\Projects\\MyTests\\MyTests.dll\" /noshadow"; |
||||
Assert.AreEqual(expectedCommandLine, helper.GetArguments()); |
||||
} |
||||
|
||||
[Test] |
||||
public void Threaded() |
||||
{ |
||||
helper.Initialize(project, null, null); |
||||
helper.NoLogo = false; |
||||
helper.ShadowCopy = true; |
||||
helper.Threaded = true; |
||||
|
||||
string expectedCommandLine = "\"C:\\Projects\\MyTests\\MyTests.dll\" /thread"; |
||||
Assert.AreEqual(expectedCommandLine, helper.GetArguments()); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestFixture() |
||||
{ |
||||
helper.Initialize(project, null, null); |
||||
helper.NoLogo = false; |
||||
helper.ShadowCopy = true; |
||||
helper.Fixture = "TestFixture"; |
||||
|
||||
string expectedCommandLine = "\"C:\\Projects\\MyTests\\MyTests.dll\" /fixture=\"TestFixture\""; |
||||
Assert.AreEqual(expectedCommandLine, helper.GetArguments()); |
||||
} |
||||
|
||||
[Test] |
||||
public void XmlOutputFile() |
||||
{ |
||||
helper.Initialize(project, null, null); |
||||
helper.NoLogo = false; |
||||
helper.ShadowCopy = true; |
||||
helper.XmlOutputFile = @"C:\NUnit.xml"; |
||||
|
||||
string expectedCommandLine = "\"C:\\Projects\\MyTests\\MyTests.dll\" /xml=\"C:\\NUnit.xml\""; |
||||
Assert.AreEqual(expectedCommandLine, helper.GetArguments()); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestMethod() |
||||
{ |
||||
helper.Initialize(project, null, null); |
||||
helper.NoLogo = false; |
||||
helper.ShadowCopy = true; |
||||
helper.Fixture = "TestFixture"; |
||||
helper.Test = "Test"; |
||||
|
||||
string expectedCommandLine = "\"C:\\Projects\\MyTests\\MyTests.dll\" /fixture=\"TestFixture\" /testMethodName=\"TestFixture.Test\""; |
||||
Assert.AreEqual(expectedCommandLine, helper.GetArguments()); |
||||
} |
||||
|
||||
[Test] |
||||
public void FullCommandLine() |
||||
{ |
||||
helper.Initialize(project, null, null); |
||||
helper.NoLogo = true; |
||||
helper.ShadowCopy = true; |
||||
|
||||
FileUtility.ApplicationRootPath = @"C:\SharpDevelop"; |
||||
|
||||
string expectedFullCommandLine = "\"C:\\SharpDevelop\\bin\\Tools\\NUnit\\nunit-console.exe\" \"C:\\Projects\\MyTests\\MyTests.dll\" /nologo"; |
||||
Assert.AreEqual(expectedFullCommandLine, helper.GetCommandLine()); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,123 @@
@@ -0,0 +1,123 @@
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
<PropertyGroup> |
||||
<OutputType>Library</OutputType> |
||||
<RootNamespace>UnitTesting.Tests</RootNamespace> |
||||
<AssemblyName>UnitTesting.Tests</AssemblyName> |
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
||||
<ProjectGuid>{44A8DE09-CAB9-49D8-9CFC-5EB0A552F181}</ProjectGuid> |
||||
<AllowUnsafeBlocks>False</AllowUnsafeBlocks> |
||||
<NoStdLib>False</NoStdLib> |
||||
<RegisterForComInterop>False</RegisterForComInterop> |
||||
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies> |
||||
<BaseAddress>4194304</BaseAddress> |
||||
<PlatformTarget>AnyCPU</PlatformTarget> |
||||
<FileAlignment>4096</FileAlignment> |
||||
<WarningLevel>4</WarningLevel> |
||||
<TreatWarningsAsErrors>false</TreatWarningsAsErrors> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> |
||||
<BaseIntermediateOutputPath>obj\</BaseIntermediateOutputPath> |
||||
<IntermediateOutputPath>obj\Debug\</IntermediateOutputPath> |
||||
<OutputPath>..\..\..\..\..\bin\UnitTests\</OutputPath> |
||||
<Optimize>False</Optimize> |
||||
<DefineConstants>DEBUG;TRACE</DefineConstants> |
||||
<DebugSymbols>true</DebugSymbols> |
||||
<DebugType>Full</DebugType> |
||||
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> |
||||
<BaseIntermediateOutputPath>obj\</BaseIntermediateOutputPath> |
||||
<IntermediateOutputPath>obj\Release\</IntermediateOutputPath> |
||||
<OutputPath>..\..\..\..\..\bin\UnitTests\</OutputPath> |
||||
<Optimize>True</Optimize> |
||||
<DefineConstants>TRACE</DefineConstants> |
||||
<DebugSymbols>false</DebugSymbols> |
||||
<DebugType>None</DebugType> |
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow> |
||||
</PropertyGroup> |
||||
<ItemGroup> |
||||
<Reference Include="System" /> |
||||
<Reference Include="System.Xml" /> |
||||
<Reference Include="nunit.framework"> |
||||
<HintPath>..\..\..\..\Tools\NUnit\nunit.framework.dll</HintPath> |
||||
<SpecificVersion>False</SpecificVersion> |
||||
</Reference> |
||||
<Reference Include="System.Windows.Forms" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<Compile Include="AssemblyInfo.cs" /> |
||||
<Compile Include="TestableConditionTests.cs" /> |
||||
<Compile Include="Utils\MockTestTreeView.cs" /> |
||||
<Compile Include="Utils\MockMember.cs" /> |
||||
<Compile Include="Utils\MockClass.cs" /> |
||||
<Compile Include="Utils\MockMethod.cs" /> |
||||
<Compile Include="Utils\MockMemberNode.cs" /> |
||||
<Compile Include="Utils\MockAmbience.cs" /> |
||||
<None Include="..\..\..\..\..\bin\SharpDevelop.exe"> |
||||
<Link>SharpDevelop.exe</Link> |
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> |
||||
</None> |
||||
<Compile Include="Utils\ResourceManager.cs" /> |
||||
<Compile Include="Utils\MockProjectContent.cs" /> |
||||
<Compile Include="Utils\MockAttribute.cs" /> |
||||
<Compile Include="Tree\OneTestClassTestFixture.cs" /> |
||||
<Compile Include="Utils\DummyParserServiceTestTreeView.cs" /> |
||||
<Compile Include="Project\IsTestProjectTests.cs" /> |
||||
<Compile Include="Project\TestProjectWithOneClassTestFixture.cs" /> |
||||
<Compile Include="Project\IsTestClassTests.cs" /> |
||||
<Compile Include="Project\IsTestMethodTests.cs" /> |
||||
<Compile Include="Project\ClassRootNamespaceTests.cs" /> |
||||
<Compile Include="Project\TwoProjectRootNamespacesTestFixture.cs" /> |
||||
<Compile Include="Project\DuplicateProjectRootNamespaceTestFixture.cs" /> |
||||
<Compile Include="Project\EmptyRootNamespaceTestFixture.cs" /> |
||||
<Compile Include="Project\ClassWithTwoChildNamespacesTestFixture.cs" /> |
||||
<Compile Include="Tree\ClassWithNoRootNamespaceTestFixture.cs" /> |
||||
<Compile Include="Project\TestClassWithOneMethodTestFixture.cs" /> |
||||
<Compile Include="Tree\SolutionOpenedTestFixture.cs" /> |
||||
<Compile Include="Tree\GetProjectsTestFixture.cs" /> |
||||
<Compile Include="TestResultsReaderTests.cs" /> |
||||
<Compile Include="UnitTestCommandLineTests.cs" /> |
||||
<Compile Include="Project\GetMethodNameTests.cs" /> |
||||
<Compile Include="Project\GetQualifiedClassNameTests.cs" /> |
||||
<Compile Include="Project\TestClassWithTwoMethodsTestFixture.cs" /> |
||||
<Compile Include="Project\ThreeTestMethodsTestResultsTestFixture.cs" /> |
||||
<Compile Include="Project\ThreeTestClassesTestResultsTestFixture.cs" /> |
||||
<Compile Include="Utils\MockParameter.cs" /> |
||||
<Compile Include="Tree\TwoTestClassesInDifferentNamespacesTestFixture.cs" /> |
||||
<Compile Include="Project\EmptyProjectTestFixture.cs" /> |
||||
<Compile Include="Project\TestMethodsInBaseClassTestFixture.cs" /> |
||||
<Compile Include="Project\DuplicateClassNameTestFixture.cs" /> |
||||
<Compile Include="Project\DuplicateMethodNameTestFixture.cs" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<ProjectReference Include="..\UnitTesting.csproj"> |
||||
<Project>{1F261725-6318-4434-A1B1-6C70CE4CD324}</Project> |
||||
<Name>UnitTesting</Name> |
||||
</ProjectReference> |
||||
<ProjectReference Include="..\..\..\..\Main\Core\Project\ICSharpCode.Core.csproj"> |
||||
<Project>{35CEF10F-2D4C-45F2-9DD1-161E0FEC583C}</Project> |
||||
<Name>ICSharpCode.Core</Name> |
||||
</ProjectReference> |
||||
<ProjectReference Include="..\..\..\..\Main\Base\Project\ICSharpCode.SharpDevelop.csproj"> |
||||
<Project>{2748AD25-9C63-4E12-877B-4DCE96FBED54}</Project> |
||||
<Name>ICSharpCode.SharpDevelop</Name> |
||||
</ProjectReference> |
||||
<ProjectReference Include="..\..\..\..\Main\ICSharpCode.SharpDevelop.Dom\Project\ICSharpCode.SharpDevelop.Dom.csproj"> |
||||
<Project>{924EE450-603D-49C1-A8E5-4AFAA31CE6F3}</Project> |
||||
<Name>ICSharpCode.SharpDevelop.Dom</Name> |
||||
</ProjectReference> |
||||
<Folder Include="Utils" /> |
||||
<ProjectReference Include="..\..\..\..\Libraries\ICSharpCode.TextEditor\Project\ICSharpCode.TextEditor.csproj"> |
||||
<Project>{2D18BE89-D210-49EB-A9DD-2246FBB3DF6D}</Project> |
||||
<Name>ICSharpCode.TextEditor</Name> |
||||
</ProjectReference> |
||||
<ProjectReference Include="..\..\..\..\Libraries\NRefactory\Project\NRefactory.csproj"> |
||||
<Project>{3A9AE6AA-BC07-4A2F-972C-581E3AE2F195}</Project> |
||||
<Name>NRefactory</Name> |
||||
</ProjectReference> |
||||
<Folder Include="Tree" /> |
||||
<Folder Include="Project" /> |
||||
</ItemGroup> |
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" /> |
||||
</Project> |
@ -0,0 +1,33 @@
@@ -0,0 +1,33 @@
|
||||
// <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 System; |
||||
|
||||
namespace UnitTesting.Tests.Utils |
||||
{ |
||||
/// <summary>
|
||||
/// Provides a way to return dummy data for IProjectContents
|
||||
/// without having to use the ParserService.
|
||||
/// </summary>
|
||||
public class DummyParserServiceTestTreeView : TestTreeView |
||||
{ |
||||
IProjectContent projectContent; |
||||
|
||||
public void AddProjectContentForProject(IProjectContent projectContent) |
||||
{ |
||||
this.projectContent = projectContent; |
||||
} |
||||
|
||||
public override IProjectContent GetProjectContent(IProject project) |
||||
{ |
||||
return projectContent; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,92 @@
@@ -0,0 +1,92 @@
|
||||
// <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 System; |
||||
|
||||
namespace UnitTesting.Tests.Utils |
||||
{ |
||||
public class MockAmbience : IAmbience |
||||
{ |
||||
public MockAmbience() |
||||
{ |
||||
} |
||||
|
||||
public ConversionFlags ConversionFlags { |
||||
get { |
||||
return ConversionFlags.None; |
||||
} |
||||
set { |
||||
} |
||||
} |
||||
|
||||
public string Convert(ModifierEnum modifier) |
||||
{ |
||||
return String.Empty; |
||||
} |
||||
|
||||
public string Convert(IClass c) |
||||
{ |
||||
return String.Empty; |
||||
} |
||||
|
||||
public string ConvertEnd(IClass c) |
||||
{ |
||||
return String.Empty; |
||||
} |
||||
|
||||
public string Convert(IField field) |
||||
{ |
||||
return String.Empty; |
||||
} |
||||
|
||||
public string Convert(IProperty property) |
||||
{ |
||||
return String.Empty; |
||||
} |
||||
|
||||
public string Convert(IEvent e) |
||||
{ |
||||
return String.Empty; |
||||
} |
||||
|
||||
public string Convert(IMethod m) |
||||
{ |
||||
return String.Empty; |
||||
} |
||||
|
||||
public string ConvertEnd(IMethod m) |
||||
{ |
||||
return String.Empty; |
||||
} |
||||
|
||||
public string Convert(IParameter param) |
||||
{ |
||||
return String.Empty; |
||||
} |
||||
|
||||
public string Convert(IReturnType returnType) |
||||
{ |
||||
return String.Empty; |
||||
} |
||||
|
||||
public string WrapAttribute(string attribute) |
||||
{ |
||||
return String.Empty; |
||||
} |
||||
|
||||
public string WrapComment(string comment) |
||||
{ |
||||
return String.Empty; |
||||
} |
||||
|
||||
public string GetIntrinsicTypeName(string dotNetTypeName) |
||||
{ |
||||
return String.Empty; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,46 @@
@@ -0,0 +1,46 @@
|
||||
// <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 System; |
||||
|
||||
namespace UnitTesting.Tests.Utils |
||||
{ |
||||
public class MockAttribute : IAttribute |
||||
{ |
||||
string name = String.Empty; |
||||
|
||||
public MockAttribute() |
||||
{ |
||||
} |
||||
|
||||
public MockAttribute(string name) |
||||
{ |
||||
this.name = name; |
||||
} |
||||
|
||||
public AttributeTarget AttributeTarget { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public string Name { |
||||
get { |
||||
return name; |
||||
} |
||||
set { |
||||
name = value; |
||||
} |
||||
} |
||||
|
||||
public int CompareTo(object obj) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,382 @@
@@ -0,0 +1,382 @@
|
||||
// <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 System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace UnitTesting.Tests.Utils |
||||
{ |
||||
public class MockClass : IClass |
||||
{ |
||||
IProjectContent projectContent; |
||||
DomRegion region = DomRegion.Empty; |
||||
IList<IAttribute> attributes = new List<IAttribute>(); |
||||
List<IMethod> methods = new List<IMethod>(); |
||||
string fullyQualifiedName = String.Empty; |
||||
string name = String.Empty; |
||||
string ns = String.Empty; |
||||
IClass compoundClass; |
||||
IClass baseClass; |
||||
|
||||
public MockClass() |
||||
{ |
||||
} |
||||
|
||||
public MockClass(string fullyQualifiedName) |
||||
{ |
||||
FullyQualifiedName = fullyQualifiedName; |
||||
} |
||||
|
||||
public string FullyQualifiedName { |
||||
get { |
||||
return fullyQualifiedName; |
||||
} |
||||
set { |
||||
fullyQualifiedName = value; |
||||
int index = fullyQualifiedName.LastIndexOf('.'); |
||||
if (index > 0) { |
||||
name = fullyQualifiedName.Substring(index + 1); |
||||
ns = fullyQualifiedName.Substring(0, index); |
||||
} else { |
||||
name = fullyQualifiedName; |
||||
} |
||||
} |
||||
} |
||||
|
||||
public IReturnType DefaultReturnType { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public string DotNetName { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public string Name { |
||||
get { |
||||
return name; |
||||
} |
||||
set { |
||||
name = value; |
||||
} |
||||
} |
||||
|
||||
public string Namespace { |
||||
get { |
||||
return ns; |
||||
} |
||||
set { |
||||
ns = value; |
||||
} |
||||
} |
||||
|
||||
public ClassType ClassType { |
||||
get { |
||||
return ClassType.Class; |
||||
} |
||||
} |
||||
|
||||
public IProjectContent ProjectContent { |
||||
get { |
||||
return projectContent; |
||||
} |
||||
set { |
||||
projectContent = value; |
||||
} |
||||
} |
||||
|
||||
public ICompilationUnit CompilationUnit { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public DomRegion Region { |
||||
get { |
||||
return region; |
||||
} |
||||
set { |
||||
region = value; |
||||
} |
||||
} |
||||
|
||||
public DomRegion BodyRegion { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public List<IReturnType> BaseTypes { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public List<IClass> InnerClasses { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public List<IField> Fields { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public List<IProperty> Properties { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public List<IMethod> Methods { |
||||
get { |
||||
return methods; |
||||
} |
||||
} |
||||
|
||||
public List<IEvent> Events { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public IList<ITypeParameter> TypeParameters { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public IEnumerable<IClass> ClassInheritanceTree { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public IClass BaseClass { |
||||
get { |
||||
return baseClass; |
||||
} |
||||
set { |
||||
baseClass = value; |
||||
} |
||||
} |
||||
|
||||
public IReturnType BaseType { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool HasPublicOrInternalStaticMembers { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool HasExtensionMethods { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public IClass DeclaringType { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public ModifierEnum Modifiers { |
||||
get { |
||||
return ModifierEnum.None; |
||||
} |
||||
set { |
||||
} |
||||
} |
||||
|
||||
public IList<IAttribute> Attributes { |
||||
get { |
||||
return attributes; |
||||
} |
||||
} |
||||
|
||||
public string Documentation { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsAbstract { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsSealed { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsStatic { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsConst { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsVirtual { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsPublic { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsProtected { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsPrivate { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsInternal { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsPartial { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
set { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsReadonly { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsProtectedAndInternal { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsProtectedOrInternal { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsOverride { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsOverridable { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsNew { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsSynthetic { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public object UserData { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
set { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public IReturnType GetBaseType(int index) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public IClass GetCompoundClass() |
||||
{ |
||||
return compoundClass; |
||||
} |
||||
|
||||
public void SetCompoundClass(IClass c) |
||||
{ |
||||
compoundClass = c; |
||||
} |
||||
|
||||
public IClass GetInnermostClass(int caretLine, int caretColumn) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public List<IClass> GetAccessibleTypes(IClass callingClass) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public IMember SearchMember(string memberName, LanguageProperties language) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public bool IsTypeInInheritanceTree(IClass possibleBaseClass) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public bool IsAccessible(IClass callingClass, bool isClassInInheritanceTree) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public bool MustBeShown(IClass callingClass, bool showStatic, bool isClassInInheritanceTree) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public int CompareTo(object obj) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,215 @@
@@ -0,0 +1,215 @@
|
||||
// <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 System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace UnitTesting.Tests.Utils |
||||
{ |
||||
public class MockMember : IMember |
||||
{ |
||||
public MockMember() |
||||
{ |
||||
} |
||||
|
||||
public string FullyQualifiedName { |
||||
get { |
||||
return String.Empty; |
||||
} |
||||
} |
||||
|
||||
public DomRegion Region { |
||||
get { |
||||
return DomRegion.Empty; |
||||
} |
||||
} |
||||
|
||||
public string Name { |
||||
get { |
||||
return String.Empty; |
||||
} |
||||
} |
||||
|
||||
public string Namespace { |
||||
get { |
||||
return String.Empty; |
||||
} |
||||
} |
||||
|
||||
public string DotNetName { |
||||
get { |
||||
return String.Empty; |
||||
} |
||||
} |
||||
|
||||
public IReturnType ReturnType { |
||||
get { |
||||
return null; |
||||
} |
||||
set { |
||||
} |
||||
} |
||||
|
||||
public IClass DeclaringType { |
||||
get { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
public ModifierEnum Modifiers { |
||||
get { |
||||
return ModifierEnum.None; |
||||
} |
||||
set { |
||||
} |
||||
} |
||||
|
||||
public IList<IAttribute> Attributes { |
||||
get { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
public string Documentation { |
||||
get { |
||||
return String.Empty; |
||||
} |
||||
} |
||||
|
||||
public bool IsAbstract { |
||||
get { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public bool IsSealed { |
||||
get { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public bool IsStatic { |
||||
get { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public bool IsConst { |
||||
get { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public bool IsVirtual { |
||||
get { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public bool IsPublic { |
||||
get { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
public bool IsProtected { |
||||
get { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public bool IsPrivate { |
||||
get { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public bool IsInternal { |
||||
get { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public bool IsPartial { |
||||
get { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public bool IsReadonly { |
||||
get { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public bool IsProtectedAndInternal { |
||||
get { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public bool IsProtectedOrInternal { |
||||
get { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public bool IsOverride { |
||||
get { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public bool IsOverridable { |
||||
get { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public bool IsNew { |
||||
get { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public bool IsSynthetic { |
||||
get { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public object UserData { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
set { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsAccessible(IClass callingClass, bool isClassInInheritanceTree) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public bool MustBeShown(IClass callingClass, bool showStatic, bool isClassInInheritanceTree) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public int CompareTo(object obj) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public object Clone() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
} |
@ -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 ICSharpCode.SharpDevelop.Dom; |
||||
using ICSharpCode.SharpDevelop.Gui.ClassBrowser; |
||||
using System; |
||||
|
||||
namespace UnitTesting.Tests.Utils |
||||
{ |
||||
public class MockMemberNode : MemberNode |
||||
{ |
||||
public MockMemberNode(IMethod method) : base(method) |
||||
{ |
||||
} |
||||
|
||||
protected override IAmbience GetAmbience() |
||||
{ |
||||
return new MockAmbience(); |
||||
} |
||||
} |
||||
} |
@ -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 ICSharpCode.SharpDevelop.Dom; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace UnitTesting.Tests.Utils |
||||
{ |
||||
public class MockMethod : IMethod |
||||
{ |
||||
IClass declaringType; |
||||
DomRegion region = DomRegion.Empty; |
||||
IList<IAttribute> attributes = new List<IAttribute>(); |
||||
string name = String.Empty; |
||||
IList<IParameter> parameters = new List<IParameter>(); |
||||
|
||||
public MockMethod() : this(String.Empty) |
||||
{ |
||||
} |
||||
|
||||
public MockMethod(string name) |
||||
{ |
||||
this.name = name; |
||||
} |
||||
|
||||
public IList<ITypeParameter> TypeParameters { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsConstructor { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public DomRegion BodyRegion { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public IList<IParameter> Parameters { |
||||
get { |
||||
return parameters; |
||||
} |
||||
} |
||||
|
||||
public bool IsExtensionMethod { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public string FullyQualifiedName { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public DomRegion Region { |
||||
get { |
||||
return region; |
||||
} |
||||
set { |
||||
region = value; |
||||
} |
||||
} |
||||
|
||||
public string Name { |
||||
get { |
||||
return name; |
||||
} |
||||
set { |
||||
name = value; |
||||
} |
||||
} |
||||
|
||||
public string Namespace { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public string DotNetName { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public IReturnType ReturnType { |
||||
get { |
||||
return null; |
||||
} |
||||
set { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public IClass DeclaringType { |
||||
get { |
||||
return declaringType; |
||||
} |
||||
set { |
||||
declaringType = value; |
||||
} |
||||
} |
||||
|
||||
public ModifierEnum Modifiers { |
||||
get { |
||||
return ModifierEnum.None; |
||||
} |
||||
set { |
||||
} |
||||
} |
||||
|
||||
public IList<IAttribute> Attributes { |
||||
get { |
||||
return attributes; |
||||
} |
||||
} |
||||
|
||||
public string Documentation { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsAbstract { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsSealed { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsStatic { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsConst { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsVirtual { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsPublic { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsProtected { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsPrivate { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsInternal { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsPartial { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsReadonly { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsProtectedAndInternal { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsProtectedOrInternal { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsOverride { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsOverridable { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsNew { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsSynthetic { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public object UserData { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
set { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsAccessible(IClass callingClass, bool isClassInInheritanceTree) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public bool MustBeShown(IClass callingClass, bool showStatic, bool isClassInInheritanceTree) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public int CompareTo(object obj) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public object Clone() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,88 @@
@@ -0,0 +1,88 @@
|
||||
// <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; |
||||
|
||||
namespace UnitTesting.Tests.Utils |
||||
{ |
||||
public class MockParameter : IParameter |
||||
{ |
||||
public MockParameter() |
||||
{ |
||||
} |
||||
|
||||
public string Name { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public IReturnType ReturnType { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
set { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public IList<IAttribute> Attributes { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public ParameterModifiers Modifiers { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public DomRegion Region { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public string Documentation { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsOut { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsRef { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsParams { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsOptional { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public int CompareTo(object obj) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,163 @@
@@ -0,0 +1,163 @@
|
||||
// <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 System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace UnitTesting.Tests.Utils |
||||
{ |
||||
public class MockProjectContent : IProjectContent |
||||
{ |
||||
IDomProject project; |
||||
LanguageProperties language; |
||||
List<IClass> classes = new List<IClass>(); |
||||
|
||||
public MockProjectContent() |
||||
{ |
||||
} |
||||
|
||||
public event EventHandler ReferencedContentsChanged; |
||||
|
||||
public XmlDoc XmlDoc { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public ICollection<IClass> Classes { |
||||
get { |
||||
return classes; |
||||
} |
||||
} |
||||
|
||||
public ICollection<string> NamespaceNames { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public ICollection<IProjectContent> ReferencedContents { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public LanguageProperties Language { |
||||
get { |
||||
return language; |
||||
} |
||||
set { |
||||
language = value; |
||||
} |
||||
} |
||||
|
||||
public IUsing DefaultImports { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public IDomProject Project { |
||||
get { |
||||
return project; |
||||
} |
||||
set { |
||||
project = value; |
||||
} |
||||
} |
||||
|
||||
public SystemTypes SystemTypes { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public string GetXmlDocumentation(string memberTag) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void AddClassToNamespaceList(IClass addClass) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void RemoveCompilationUnit(ICompilationUnit oldUnit) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void UpdateCompilationUnit(ICompilationUnit oldUnit, ICompilationUnit parserOutput, string fileName) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public IClass GetClass(string typeName) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public IClass GetClass(string typeName, int typeParameterCount) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public bool NamespaceExists(string name) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public ArrayList GetNamespaceContents(string nameSpace) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public IClass GetClass(string typeName, int typeParameterCount, LanguageProperties language, bool lookInReferences) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public bool NamespaceExists(string name, LanguageProperties language, bool lookInReferences) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void AddNamespaceContents(System.Collections.ArrayList list, string subNameSpace, LanguageProperties language, bool lookInReferences) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public string SearchNamespace(string name, IClass curType, ICompilationUnit unit, int caretLine, int caretColumn) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public SearchTypeResult SearchType(SearchTypeRequest request) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public FilePosition GetPosition(string fullMemberName) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void Dispose() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
void OnReferencedContentsChanged() |
||||
{ |
||||
if (ReferencedContentsChanged != null) { |
||||
ReferencedContentsChanged(this, new EventArgs()); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,52 @@
@@ -0,0 +1,52 @@
|
||||
// <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 System; |
||||
|
||||
namespace UnitTesting.Tests |
||||
{ |
||||
public class MockTestTreeView : ITestTreeView |
||||
{ |
||||
IMember selectedMethod; |
||||
IClass selectedClass; |
||||
IProject selectedProject; |
||||
|
||||
public MockTestTreeView() |
||||
{ |
||||
} |
||||
|
||||
public IMember SelectedMethod { |
||||
get { |
||||
return selectedMethod; |
||||
} |
||||
set { |
||||
selectedMethod = value; |
||||
} |
||||
} |
||||
|
||||
public IClass SelectedClass { |
||||
get { |
||||
return selectedClass; |
||||
} |
||||
set { |
||||
selectedClass = value; |
||||
} |
||||
} |
||||
|
||||
public IProject SelectedProject { |
||||
get { |
||||
return selectedProject; |
||||
} |
||||
set { |
||||
selectedProject = value; |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
// <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.Core; |
||||
using System; |
||||
using System.Reflection; |
||||
|
||||
namespace UnitTesting.Tests.Utils |
||||
{ |
||||
/// <summary>
|
||||
/// This class is used to register any bitmaps used by
|
||||
/// SharpDevelop so any references to the ResourceManager that
|
||||
/// ask for bitmaps succeed.
|
||||
/// </summary>
|
||||
public class ResourceManager |
||||
{ |
||||
static bool initialized; |
||||
|
||||
ResourceManager() |
||||
{ |
||||
} |
||||
|
||||
public static void Initialize() |
||||
{ |
||||
if (!initialized) { |
||||
initialized = true; |
||||
Assembly exe = Assembly.Load("SharpDevelop"); |
||||
ResourceService.RegisterNeutralImages(new System.Resources.ResourceManager("Resources.BitmapResources", exe)); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,64 @@
@@ -0,0 +1,64 @@
|
||||
Microsoft Visual Studio Solution File, Format Version 9.00 |
||||
# SharpDevelop 2.1.0.1856 |
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTesting", "UnitTesting.csproj", "{1F261725-6318-4434-A1B1-6C70CE4CD324}" |
||||
EndProject |
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTesting.Tests", "Test\UnitTesting.Tests.csproj", "{44A8DE09-CAB9-49D8-9CFC-5EB0A552F181}" |
||||
EndProject |
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.Core", "..\..\..\Main\Core\Project\ICSharpCode.Core.csproj", "{35CEF10F-2D4C-45F2-9DD1-161E0FEC583C}" |
||||
EndProject |
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.SharpDevelop", "..\..\..\Main\Base\Project\ICSharpCode.SharpDevelop.csproj", "{2748AD25-9C63-4E12-877B-4DCE96FBED54}" |
||||
EndProject |
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.SharpDevelop.Dom", "..\..\..\Main\ICSharpCode.SharpDevelop.Dom\Project\ICSharpCode.SharpDevelop.Dom.csproj", "{924EE450-603D-49C1-A8E5-4AFAA31CE6F3}" |
||||
EndProject |
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.TextEditor", "..\..\..\Libraries\ICSharpCode.TextEditor\Project\ICSharpCode.TextEditor.csproj", "{2D18BE89-D210-49EB-A9DD-2246FBB3DF6D}" |
||||
EndProject |
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NRefactory", "..\..\..\Libraries\NRefactory\Project\NRefactory.csproj", "{3A9AE6AA-BC07-4A2F-972C-581E3AE2F195}" |
||||
EndProject |
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.SharpDevelop.Widgets", "..\..\..\Main\ICSharpCode.SharpDevelop.Widgets\Project\ICSharpCode.SharpDevelop.Widgets.csproj", "{8035765F-D51F-4A0C-A746-2FD100E19419}" |
||||
EndProject |
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormsUI", "..\..\..\Libraries\DockPanel_Src\WinFormsUI\WinFormsUI.csproj", "{D3C782BA-178E-4235-A3BA-8C11DEBB6BEE}" |
||||
EndProject |
||||
Global |
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution |
||||
Debug|Any CPU = Debug|Any CPU |
||||
Release|Any CPU = Release|Any CPU |
||||
EndGlobalSection |
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution |
||||
{1F261725-6318-4434-A1B1-6C70CE4CD324}.Debug|Any CPU.Build.0 = Debug|Any CPU |
||||
{1F261725-6318-4434-A1B1-6C70CE4CD324}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
||||
{1F261725-6318-4434-A1B1-6C70CE4CD324}.Release|Any CPU.Build.0 = Release|Any CPU |
||||
{1F261725-6318-4434-A1B1-6C70CE4CD324}.Release|Any CPU.ActiveCfg = Release|Any CPU |
||||
{44A8DE09-CAB9-49D8-9CFC-5EB0A552F181}.Debug|Any CPU.Build.0 = Debug|Any CPU |
||||
{44A8DE09-CAB9-49D8-9CFC-5EB0A552F181}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
||||
{44A8DE09-CAB9-49D8-9CFC-5EB0A552F181}.Release|Any CPU.Build.0 = Release|Any CPU |
||||
{44A8DE09-CAB9-49D8-9CFC-5EB0A552F181}.Release|Any CPU.ActiveCfg = Release|Any CPU |
||||
{35CEF10F-2D4C-45F2-9DD1-161E0FEC583C}.Debug|Any CPU.Build.0 = Debug|Any CPU |
||||
{35CEF10F-2D4C-45F2-9DD1-161E0FEC583C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
||||
{35CEF10F-2D4C-45F2-9DD1-161E0FEC583C}.Release|Any CPU.Build.0 = Release|Any CPU |
||||
{35CEF10F-2D4C-45F2-9DD1-161E0FEC583C}.Release|Any CPU.ActiveCfg = Release|Any CPU |
||||
{2748AD25-9C63-4E12-877B-4DCE96FBED54}.Debug|Any CPU.Build.0 = Debug|Any CPU |
||||
{2748AD25-9C63-4E12-877B-4DCE96FBED54}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
||||
{2748AD25-9C63-4E12-877B-4DCE96FBED54}.Release|Any CPU.Build.0 = Release|Any CPU |
||||
{2748AD25-9C63-4E12-877B-4DCE96FBED54}.Release|Any CPU.ActiveCfg = Release|Any CPU |
||||
{924EE450-603D-49C1-A8E5-4AFAA31CE6F3}.Debug|Any CPU.Build.0 = Debug|Any CPU |
||||
{924EE450-603D-49C1-A8E5-4AFAA31CE6F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
||||
{924EE450-603D-49C1-A8E5-4AFAA31CE6F3}.Release|Any CPU.Build.0 = Release|Any CPU |
||||
{924EE450-603D-49C1-A8E5-4AFAA31CE6F3}.Release|Any CPU.ActiveCfg = Release|Any CPU |
||||
{2D18BE89-D210-49EB-A9DD-2246FBB3DF6D}.Debug|Any CPU.Build.0 = Debug|Any CPU |
||||
{2D18BE89-D210-49EB-A9DD-2246FBB3DF6D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
||||
{2D18BE89-D210-49EB-A9DD-2246FBB3DF6D}.Release|Any CPU.Build.0 = Release|Any CPU |
||||
{2D18BE89-D210-49EB-A9DD-2246FBB3DF6D}.Release|Any CPU.ActiveCfg = Release|Any CPU |
||||
{3A9AE6AA-BC07-4A2F-972C-581E3AE2F195}.Debug|Any CPU.Build.0 = Debug|Any CPU |
||||
{3A9AE6AA-BC07-4A2F-972C-581E3AE2F195}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
||||
{3A9AE6AA-BC07-4A2F-972C-581E3AE2F195}.Release|Any CPU.Build.0 = Release|Any CPU |
||||
{3A9AE6AA-BC07-4A2F-972C-581E3AE2F195}.Release|Any CPU.ActiveCfg = Release|Any CPU |
||||
{8035765F-D51F-4A0C-A746-2FD100E19419}.Debug|Any CPU.Build.0 = Debug|Any CPU |
||||
{8035765F-D51F-4A0C-A746-2FD100E19419}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
||||
{8035765F-D51F-4A0C-A746-2FD100E19419}.Release|Any CPU.Build.0 = Release|Any CPU |
||||
{8035765F-D51F-4A0C-A746-2FD100E19419}.Release|Any CPU.ActiveCfg = Release|Any CPU |
||||
{D3C782BA-178E-4235-A3BA-8C11DEBB6BEE}.Debug|Any CPU.Build.0 = Debug|Any CPU |
||||
{D3C782BA-178E-4235-A3BA-8C11DEBB6BEE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
||||
{D3C782BA-178E-4235-A3BA-8C11DEBB6BEE}.Release|Any CPU.Build.0 = Release|Any CPU |
||||
{D3C782BA-178E-4235-A3BA-8C11DEBB6BEE}.Release|Any CPU.ActiveCfg = Release|Any CPU |
||||
EndGlobalSection |
||||
EndGlobal |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue