-
Notifications
You must be signed in to change notification settings - Fork 750
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
36ce712
commit 0b31fac
Showing
10 changed files
with
107 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System.CodeDom; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace TechTalk.SpecFlow.Generator.UnitTestProvider | ||
{ | ||
public class MsTest2010GeneratorProvider : MsTestGeneratorProvider | ||
{ | ||
private const string CATEGORY_ATTR = "Microsoft.VisualStudio.TestTools.UnitTesting.TestCategoryAttribute"; | ||
|
||
public override void SetTestFixture(CodeTypeDeclaration typeDeclaration, string title, string description) | ||
{ | ||
base.SetTestFixture(typeDeclaration, title, description); | ||
|
||
featureCategories = null; | ||
} | ||
|
||
private IEnumerable<string> featureCategories = null; | ||
|
||
public override void SetTestFixtureCategories(CodeTypeDeclaration typeDeclaration, IEnumerable<string> categories) | ||
{ | ||
featureCategories = categories.ToArray(); | ||
} | ||
|
||
public override void SetTest(CodeMemberMethod memberMethod, string title) | ||
{ | ||
base.SetTest(memberMethod, title); | ||
if (featureCategories != null) | ||
SetCategories(memberMethod.CustomAttributes, featureCategories); | ||
} | ||
|
||
public override void SetTestCategories(CodeMemberMethod memberMethod, IEnumerable<string> categories) | ||
{ | ||
SetCategories(memberMethod.CustomAttributes, categories); | ||
} | ||
|
||
private void SetCategories(CodeAttributeDeclarationCollection customAttributes, IEnumerable<string> categories) | ||
{ | ||
foreach (var category in categories) | ||
{ | ||
customAttributes.Add( | ||
new CodeAttributeDeclaration( | ||
new CodeTypeReference(CATEGORY_ATTR), | ||
new CodeAttributeArgument( | ||
new CodePrimitiveExpression(category)))); | ||
} | ||
} | ||
|
||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace TechTalk.SpecFlow.UnitTestProvider | ||
{ | ||
public class MsTest2010RuntimeProvider : MsTestRuntimeProvider | ||
{ | ||
|
||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Linq.Expressions; | ||
using System.Reflection; | ||
|
||
namespace TechTalk.SpecFlow.UnitTestProvider | ||
{ | ||
internal static class UnitTestRuntimeProviderHelper | ||
{ | ||
public static Action<string> GetAssertMethod(string assemblyName, string typeName, string methodName) | ||
{ | ||
Assembly msTestAssembly = Assembly.Load(assemblyName); | ||
Type assertType = msTestAssembly.GetType(typeName, true); | ||
|
||
MethodInfo method = assertType.GetMethod(methodName, | ||
BindingFlags.Public | BindingFlags.Static, null, | ||
new Type[] { typeof(string) }, null); | ||
if (method == null) | ||
throw new SpecFlowException("Assert method not found: " + methodName); | ||
|
||
List<ParameterExpression> parameters = new List<ParameterExpression>(); | ||
foreach (ParameterInfo parameterInfo in method.GetParameters()) | ||
{ | ||
parameters.Add(Expression.Parameter(parameterInfo.ParameterType, parameterInfo.Name)); | ||
} | ||
var lambda = Expression.Lambda<Action<string>>( | ||
Expression.Call(method, parameters.Cast<Expression>().ToArray()), | ||
parameters.ToArray()); | ||
|
||
return lambda.Compile(); | ||
} | ||
|
||
} | ||
} |
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