-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add LocalTest attribute and discoverer
- Loading branch information
1 parent
fbaa2ea
commit 54825ed
Showing
3 changed files
with
63 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using Xunit.Sdk; | ||
|
||
namespace Xunit.Categories | ||
{ | ||
/// <summary> | ||
/// For tests that should only be executed locally and excluded from automated pipeline runs | ||
/// </summary> | ||
/// <example>trying out LINQ for the first time, writing a piece of code to understand IEnumerable.Take and Skip.</example> | ||
[TraitDiscoverer(LocalTestDiscoverer.DiscovererTypeName, DiscovererUtil.AssemblyName)] | ||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)] | ||
public class LocalTestAttribute:Attribute,ITraitAttribute | ||
{ | ||
public LocalTestAttribute(string id) | ||
{ | ||
this.Id = id; | ||
} | ||
|
||
public LocalTestAttribute(long id) | ||
{ | ||
this.Id = id.ToString(); | ||
} | ||
|
||
public LocalTestAttribute() | ||
{ | ||
|
||
} | ||
|
||
public string Id { get; } | ||
} | ||
} |
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,23 @@ | ||
using System.Collections.Generic; | ||
using Xunit.Abstractions; | ||
using Xunit.Sdk; | ||
|
||
namespace Xunit.Categories | ||
{ | ||
public class LocalTestDiscoverer : ITraitDiscoverer | ||
{ | ||
internal const string DiscovererTypeName = DiscovererUtil.AssemblyName + "." + nameof(LocalTestDiscoverer); | ||
|
||
public IEnumerable<KeyValuePair<string, string>> GetTraits(IAttributeInfo traitAttribute) | ||
{ | ||
var id = traitAttribute.GetNamedArgument<string>("Id"); | ||
|
||
|
||
yield return new KeyValuePair<string, string>("Category", "LocalTest"); | ||
|
||
if (!string.IsNullOrWhiteSpace(id)) | ||
yield return new KeyValuePair<string, string>("LocalTest", id); | ||
|
||
} | ||
} | ||
} |
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