Browse Source

Fix MSpec test selection in Unit Tests window.

Run tests just for the class or namespace selected.
When a test member is selected run all tests for the
associated class (mspec.exe cannot run a single test/specification).
pull/32/merge
Matt Ward 13 years ago
parent
commit
e0567649e8
  1. 1
      src/AddIns/Analysis/MachineSpecifications/MachineSpecifications.Tests/MachineSpecifications.Tests.csproj
  2. 65
      src/AddIns/Analysis/MachineSpecifications/MachineSpecifications.Tests/Src/ClassFilterBuilderTests.cs
  3. 1
      src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/MachineSpecifications.csproj
  4. 9
      src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/BehaviorImportedTestMember.cs
  5. 39
      src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/ClassFilterBuilder.cs
  6. 12
      src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/ITestWithAssociatedType.cs
  7. 4
      src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/MSpecApplication.cs
  8. 7
      src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/MSpecTestClass.cs
  9. 7
      src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/MSpecTestMember.cs
  10. 2
      src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/MSpecTestProject.cs

1
src/AddIns/Analysis/MachineSpecifications/MachineSpecifications.Tests/MachineSpecifications.Tests.csproj

@ -72,7 +72,6 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Src\ClassFilterBuilderTests.cs" />
<Compile Include="Src\MSpecTestProjectTests.cs" /> <Compile Include="Src\MSpecTestProjectTests.cs" />
<Compile Include="Src\MSpecTestFrameworkTests.cs" /> <Compile Include="Src\MSpecTestFrameworkTests.cs" />
<Compile Include="Src\MSpecUnitTestMonitorTests.cs" /> <Compile Include="Src\MSpecUnitTestMonitorTests.cs" />

65
src/AddIns/Analysis/MachineSpecifications/MachineSpecifications.Tests/Src/ClassFilterBuilderTests.cs

@ -1,65 +0,0 @@
//// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
//// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
//
//using System;
//using System.Collections.Generic;
//using developwithpassion.specifications.extensions;
//using developwithpassion.specifications.rhinomocks;
//using ICSharpCode.SharpDevelop.Dom;
//using ICSharpCode.SharpDevelop.Project;
//using ICSharpCode.UnitTesting;
//using Machine.Specifications;
//using Machine.Fakes.Adapters.Rhinomocks;
//
//namespace ICSharpCode.MachineSpecifications.Tests
//{
// [Subject(typeof(ClassFilterBuilder))]
// public class When_building_class_filter_from_test_selection : Observes<ClassFilterBuilder>
// {
// const string NAMESPACE_FILTER = "Namespace";
// static DefaultClass classAddedExplicitly, classInNamespace, classOutsideNamespace, classNestedInAddedExplicitly, classNestedInClassInNamespace;
// static SelectedTests selectedTests;
// static IProjectContent projectContent;
// static IList<string> result;
//
// Establish ctx = () => {
// projectContent = fake.an<IProjectContent>();
// projectContent.setup(x => x.SystemTypes).Return(new SystemTypes(projectContent));
// var compilationUnit = new DefaultCompilationUnit(projectContent);
//
// classAddedExplicitly = new DefaultClass(compilationUnit, "ClassAddedExplicitly");
// classNestedInAddedExplicitly = new DefaultClass(compilationUnit, classAddedExplicitly);
// classNestedInAddedExplicitly.FullyQualifiedName = "ClassAddedExplicitly.InnerClass";
// classAddedExplicitly.InnerClasses.Add(classNestedInAddedExplicitly);
//
// classInNamespace = new DefaultClass(compilationUnit, "Namespace.OtherNamespace.ClassInNamespace");
// classNestedInClassInNamespace = new DefaultClass(compilationUnit, classInNamespace);
// classNestedInClassInNamespace.FullyQualifiedName = "Namespace.OtherNamespace.ClassInNamespace.InnerClass";
// classInNamespace.InnerClasses.Add(classNestedInClassInNamespace);
// classOutsideNamespace = new DefaultClass(compilationUnit, "Namespace2.ClassOutsideNamespac");
//
// var project = fake.an<IProject>();
// projectContent.setup(x => x.Classes).Return(new[]{classInNamespace, classOutsideNamespace});
//
// selectedTests = new SelectedTests(project, NAMESPACE_FILTER, classAddedExplicitly, null);
// };
//
// Because of = () =>
// result = sut.BuildFilterFor(selectedTests, projectContent);
//
// It should_add_dotnet_name_of_selected_test_class = () =>
// result.ShouldContain(classAddedExplicitly.DotNetName);
//
// It should_add_class_included_in_selected_namespace = () =>
// result.ShouldContain(classInNamespace.DotNetName);
//
// It should_not_include_class_not_included_in_namespace = () =>
// result.ShouldNotContain(classOutsideNamespace.DotNetName);
//
// It should_not_include_class_nested_in_selected_test_class = () =>
// result.ShouldNotContain(classNestedInAddedExplicitly.DotNetName);
//
// It should_include_class_nested_in_class_from_selected_namespace = () =>
// result.ShouldContain(classNestedInClassInNamespace.DotNetName);
// }
//}

1
src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/MachineSpecifications.csproj

@ -99,6 +99,7 @@
<Compile Include="Configuration\AssemblyInfo.cs" /> <Compile Include="Configuration\AssemblyInfo.cs" />
<Compile Include="src\BehaviorImportedTestMember.cs" /> <Compile Include="src\BehaviorImportedTestMember.cs" />
<Compile Include="src\ClassFilterBuilder.cs" /> <Compile Include="src\ClassFilterBuilder.cs" />
<Compile Include="src\ITestWithAssociatedType.cs" />
<Compile Include="src\MSpecApplication.cs" /> <Compile Include="src\MSpecApplication.cs" />
<Compile Include="src\MSpecTestClass.cs" /> <Compile Include="src\MSpecTestClass.cs" />
<Compile Include="src\MSpecTestDebugger.cs" /> <Compile Include="src\MSpecTestDebugger.cs" />

9
src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/BehaviorImportedTestMember.cs

@ -10,11 +10,20 @@ namespace ICSharpCode.MachineSpecifications
{ {
public class BehaviorImportedTestMember : MSpecTestMember public class BehaviorImportedTestMember : MSpecTestMember
{ {
IMember parent;
public BehaviorImportedTestMember( public BehaviorImportedTestMember(
MSpecTestProject parentProject, MSpecTestProject parentProject,
IMember parent,
IMember behavior) IMember behavior)
: base(parentProject, behavior) : base(parentProject, behavior)
{ {
this.parent = parent;
}
public override string GetTypeName()
{
return parent.DeclaringTypeDefinition.FullName;
} }
} }
} }

39
src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/ClassFilterBuilder.cs

@ -3,6 +3,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using ICSharpCode.SharpDevelop.Dom; using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.UnitTesting; using ICSharpCode.UnitTesting;
@ -13,26 +14,24 @@ namespace ICSharpCode.MachineSpecifications
/// </summary> /// </summary>
public class ClassFilterBuilder public class ClassFilterBuilder
{ {
public IList<string> BuildFilterFor(IEnumerable<ITest> tests) { public IList<string> BuildFilterFor(IEnumerable<ITest> tests)
//var projectContent = @using; {
return GetFilter(tests).ToList();
var filter = new List<string>(); }
// if (tests.Class != null)
// filter.Add(tests.Class.DotNetName); IEnumerable<string> GetFilter(IEnumerable<ITest> tests)
// if (tests.NamespaceFilter != null) {
// foreach (var projectClass in projectContent.Classes) foreach (ITest test in tests) {
// if (projectClass.FullyQualifiedName.StartsWith(tests.NamespaceFilter + ".")) var testWithAssociatedType = test as ITestWithAssociatedType;
// Add(projectClass, to: filter); var testNamespace = test as TestNamespace;
if (testWithAssociatedType != null) {
return filter; yield return testWithAssociatedType.GetTypeName();
} else if (testNamespace != null) {
foreach (string filter in GetFilter(testNamespace.NestedTests)) {
yield return filter;
}
}
}
} }
//
// static void Add(IClass @class, IList<string> to)
// {
// var list = to;
// to.Add(@class.DotNetName);
// foreach (var innerClass in @class.InnerClasses)
// Add(innerClass, to: list);
// }
} }
} }

12
src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/ITestWithAssociatedType.cs

@ -0,0 +1,12 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
namespace ICSharpCode.MachineSpecifications
{
public interface ITestWithAssociatedType
{
string GetTypeName();
}
}

4
src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/MSpecApplication.cs

@ -67,17 +67,17 @@ namespace ICSharpCode.MachineSpecifications
string CreateFilterFile() string CreateFilterFile()
{ {
var classFilterBuilder = new ClassFilterBuilder(); var classFilterBuilder = new ClassFilterBuilder();
//var projectContent = SD.ParserService.GetProjectContent(project);
IList<string> filter = classFilterBuilder.BuildFilterFor(tests); IList<string> filter = classFilterBuilder.BuildFilterFor(tests);
string path = null; string path = null;
if (filter.Count > 0) { if (filter.Count > 0) {
path = Path.GetTempFileName(); path = Path.GetTempFileName();
using (var stream = new FileStream(path, FileMode.Create, FileAccess.Write)) using (var stream = new FileStream(path, FileMode.Create, FileAccess.Write))
using (var writer = new StreamWriter(stream)) using (var writer = new StreamWriter(stream)) {
foreach (string testClassName in filter) { foreach (string testClassName in filter) {
writer.WriteLine(testClassName); writer.WriteLine(testClassName);
} }
}
} }
return path; return path;
} }

7
src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/MSpecTestClass.cs

@ -12,7 +12,7 @@ using ICSharpCode.UnitTesting;
namespace ICSharpCode.MachineSpecifications namespace ICSharpCode.MachineSpecifications
{ {
public class MSpecTestClass : TestBase public class MSpecTestClass : TestBase, ITestWithAssociatedType
{ {
MSpecTestProject parentProject; MSpecTestProject parentProject;
FullTypeName fullTypeName; FullTypeName fullTypeName;
@ -24,6 +24,11 @@ namespace ICSharpCode.MachineSpecifications
BindResultToCompositeResultOfNestedTests(); BindResultToCompositeResultOfNestedTests();
} }
public string GetTypeName()
{
return fullTypeName.ReflectionName;
}
public override ITestProject ParentProject { public override ITestProject ParentProject {
get { return parentProject; } get { return parentProject; }
} }

7
src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/MSpecTestMember.cs

@ -10,7 +10,7 @@ using ICSharpCode.UnitTesting;
namespace ICSharpCode.MachineSpecifications namespace ICSharpCode.MachineSpecifications
{ {
public class MSpecTestMember : TestBase public class MSpecTestMember : TestBase, ITestWithAssociatedType
{ {
MSpecTestProject parentProject; MSpecTestProject parentProject;
string displayName; string displayName;
@ -63,5 +63,10 @@ namespace ICSharpCode.MachineSpecifications
}); });
} }
} }
public virtual string GetTypeName()
{
return member.DeclaringTypeDefinition.FullName;
}
} }
} }

2
src/AddIns/Analysis/MachineSpecifications/MachineSpecifications/src/MSpecTestProject.cs

@ -96,7 +96,7 @@ namespace ICSharpCode.MachineSpecifications
IEnumerable<IField> behaviorFields = ResolveBehaviorFieldsOf(field); IEnumerable<IField> behaviorFields = ResolveBehaviorFieldsOf(field);
IEnumerable<IField> behaviorMembers = behaviorFields.Where(HasItReturnType); IEnumerable<IField> behaviorMembers = behaviorFields.Where(HasItReturnType);
IEnumerable<BehaviorImportedTestMember> testMembersFromBehavior = behaviorMembers.Select(testField => IEnumerable<BehaviorImportedTestMember> testMembersFromBehavior = behaviorMembers.Select(testField =>
new BehaviorImportedTestMember(this, testField)); new BehaviorImportedTestMember(this, field, testField));
result.AddRange(testMembersFromBehavior); result.AddRange(testMembersFromBehavior);
} }
} }

Loading…
Cancel
Save