8000 Add SkippableTheoryAttribute · gitextensions/libgit2sharp@15e20b1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 15e20b1

Browse files
dahlbyknulltoken
authored andcommitted
Add SkippableTheoryAttribute
1 parent 678b268 commit 15e20b1

File tree

2 files changed

+57
-13
lines changed

2 files changed

+57
-13
lines changed

LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
</Reference>
5050
<Reference Include="System" />
5151
<Reference Include="System.Core" />
52+
<Reference Include="System.Xml" />
5253
<Reference Include="xunit">
5354
<HintPath>..\Lib\xUnit\xunit.dll</HintPath>
5455
</Reference>

LibGit2Sharp.Tests/TestHelpers/SkippableFactAttribute.cs

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@
5959
//* only do so under a license that complies with this license.
6060
//**********************************************************************
6161
using System.Collections.Generic;
62+
using System.Linq;
63+
using System.Xml;
6264
using Xunit;
65+
using Xunit.Extensions;
6366
using Xunit.Sdk;
6467

6568
namespace LibGit2Sharp.Tests.TestHelpers
@@ -68,24 +71,64 @@ class SkippableFactAttribute : FactAttribute
6871
{
6972
protected override IEnumerable<ITestCommand> EnumerateTestCommands(IMethodInfo method)
7073
{
71-
yield return new SkippableTestCommand(method);
74+
return base.EnumerateTestCommands(method).Select(SkippableTestCommand.Wrap(method));
7275
}
76+
}
77+
78+
class SkippableTheoryAttribute : TheoryAttribute
79+
{
80+
protected override IEnumerable<ITestCommand> EnumerateTestCommands(IMethodInfo method)
81+
{
82+
return base.EnumerateTestCommands(method).Select(SkippableTestCommand.Wrap(method));
83+
}
84+
}
7385

74-
class SkippableTestCommand : FactCommand
86+
class SkippableTestCommand : ITestCommand
87+
{
88+
public static Func<ITestCommand, ITestCommand> Wrap(IMethodInfo method)
7589
{
76-
public SkippableTestCommand(IMethodInfo method) : base(method) { }
90+
return c => new SkippableTestCommand(method, c);
91+
}
7792

78-
public override MethodResult Execute(object testClass)
93+
private readonly IMethodInfo method;
94+
private readonly ITestCommand inner;
95+
96+
private SkippableTestCommand(IMethodInfo method, ITestCommand inner)
97+
{
98+
this.method = method;
99+
this.inner = inner;
100+
}
101+
102+
public MethodResult Execute(object testClass)
103+
{
104+
try
79105
{
80-
try
81-
{
82-
return base.Execute(testClass);
83-
}
84-
catch (SkipException e)
85-
{
86-
return new SkipResult(testMethod, DisplayName, e.Reason);
87-
}
106+
return inner.Execute(testClass);
88107
}
108+
catch (SkipException e)
109+
{
110+
return new SkipResult(method, DisplayName, e.Reason);
111+
}
112+
}
113+
114+
public XmlNode ToStartXml()
115+
{
116+
return inner.ToStartXml();
117+
}
118+
119+
public string DisplayName
120+
{
121+
get { return inner.DisplayName; }
122+
}
123+
124+
public bool ShouldCreateInstance
125+
{
126+
get { return inner.ShouldCreateInstance; }
127+
}
128+
129+
public int Timeout
130+
{
131+
get { return inner.Timeout; }
89132
}
90133
}
91134

@@ -96,6 +139,6 @@ public SkipException(string reason)
96139
Reason = reason;
97140
}
98141

99-
public string Reason { get; set; }
142+
public string Reason { get; private set; }
100143
}
101144
}

0 commit comments

Comments
 (0)
0