Permalink
Browse files

Add SkippableTheoryAttribute

  • Loading branch information...
1 parent 678b268 commit 15e20b1dc7c0224eeba01d8909db032fbcaa822f @dahlbyk dahlbyk committed with nulltoken Mar 3, 2013
@@ -49,6 +49,7 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
+ <Reference Include="System.Xml" />
<Reference Include="xunit">
<HintPath>..\Lib\xUnit\xunit.dll</HintPath>
</Reference>
@@ -59,7 +59,10 @@
//* only do so under a license that complies with this license.
//**********************************************************************
using System.Collections.Generic;
+using System.Linq;
+using System.Xml;
using Xunit;
+using Xunit.Extensions;
using Xunit.Sdk;
namespace LibGit2Sharp.Tests.TestHelpers
@@ -68,24 +71,64 @@ class SkippableFactAttribute : FactAttribute
{
protected override IEnumerable<ITestCommand> EnumerateTestCommands(IMethodInfo method)
{
- yield return new SkippableTestCommand(method);
+ return base.EnumerateTestCommands(method).Select(SkippableTestCommand.Wrap(method));
}
+ }
+
+ class SkippableTheoryAttribute : TheoryAttribute
+ {
+ protected override IEnumerable<ITestCommand> EnumerateTestCommands(IMethodInfo method)
+ {
+ return base.EnumerateTestCommands(method).Select(SkippableTestCommand.Wrap(method));
+ }
+ }
- class SkippableTestCommand : FactCommand
+ class SkippableTestCommand : ITestCommand
+ {
+ public static Func<ITestCommand, ITestCommand> Wrap(IMethodInfo method)
{
- public SkippableTestCommand(IMethodInfo method) : base(method) { }
+ return c => new SkippableTestCommand(method, c);
+ }
- public override MethodResult Execute(object testClass)
+ private readonly IMethodInfo method;
+ private readonly ITestCommand inner;
+
+ private SkippableTestCommand(IMethodInfo method, ITestCommand inner)
+ {
+ this.method = method;
+ this.inner = inner;
+ }
+
+ public MethodResult Execute(object testClass)
+ {
+ try
{
- try
- {
- return base.Execute(testClass);
- }
- catch (SkipException e)
- {
- return new SkipResult(testMethod, DisplayName, e.Reason);
- }
+ return inner.Execute(testClass);
}
+ catch (SkipException e)
+ {
+ return new SkipResult(method, DisplayName, e.Reason);
+ }
+ }
+
+ public XmlNode ToStartXml()
+ {
+ return inner.ToStartXml();
+ }
+
+ public string DisplayName
+ {
+ get { return inner.DisplayName; }
+ }
+
+ public bool ShouldCreateInstance
+ {
+ get { return inner.ShouldCreateInstance; }
+ }
+
+ public int Timeout
+ {
+ get { return inner.Timeout; }
}
}
@@ -96,6 +139,6 @@ public SkipException(string reason)
Reason = reason;
}
- public string Reason { get; set; }
+ public string Reason { get; private set; }
}
}

0 comments on commit 15e20b1

Please sign in to comment.