-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for executing tests in nested classes when parent class i…
…s targeted #4.
- Loading branch information
Showing
4 changed files
with
52 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,51 @@ | ||
namespace NUnitTDNet.Adapter | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
|
||
class Utilities | ||
{ | ||
public static string GetTestPath(MemberInfo member) | ||
public static string[] GetTestPaths(MemberInfo member) | ||
{ | ||
if (member is Type) | ||
{ | ||
Type type = (Type)member; | ||
return type.FullName; | ||
var targetType = (Type)member; | ||
var types = includeNestedTypes(targetType); | ||
var testPathList = new List<string>(); | ||
foreach (var type in types) | ||
{ | ||
testPathList.Add(type.FullName); | ||
} | ||
|
||
return testPathList.ToArray(); | ||
} | ||
|
||
if (member is MethodInfo) | ||
{ | ||
MethodInfo methodInfo = (MethodInfo)member; | ||
return methodInfo.DeclaringType.FullName + "." + methodInfo.Name; | ||
var testPath = methodInfo.DeclaringType.FullName + "." + methodInfo.Name; | ||
var testPaths = new string[] { testPath }; | ||
return testPaths; | ||
} | ||
|
||
throw new Exception("Member type not supported: " + member.GetType()); | ||
} | ||
|
||
static Type[] includeNestedTypes(Type type) | ||
{ | ||
var types = new List<Type>(); | ||
includeNestedTypes(types, type); | ||
return types.ToArray(); | ||
} | ||
|
||
static void includeNestedTypes(List<Type> types, Type type) | ||
{ | ||
types.Add(type); | ||
foreach (var nestedType in type.GetNestedTypes()) | ||
{ | ||
includeNestedTypes(types, nestedType); | ||
} | ||
} | ||
} | ||
} |