Skip to content

Commit

Permalink
Add UnitTest Trait for #4
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanconnolly committed Aug 29, 2017
1 parent e1a31f3 commit f3fe554
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
28 changes: 28 additions & 0 deletions src/Xunit.Categories/UnitTestAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using Xunit.Sdk;

namespace Xunit.Categories
{
[TraitDiscoverer(UnitTestDiscoverer.DiscovererTypeName, DiscovererUtil.AssemblyName)]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)]
public class UnitTestAttribute:Attribute, ITraitAttribute
{
public UnitTestAttribute()
{

}

public UnitTestAttribute(string name)
{
this.Identifier = name;
}

public UnitTestAttribute(long id)
{
this.Identifier = id.ToString();
}

public string Identifier { get; private set; }

}
}
21 changes: 21 additions & 0 deletions src/Xunit.Categories/UnitTestDiscoverer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Collections.Generic;
using Xunit.Abstractions;
using Xunit.Sdk;

namespace Xunit.Categories
{
public class UnitTestDiscoverer:ITraitDiscoverer
{
internal const string DiscovererTypeName = DiscovererUtil.AssemblyName + "." + nameof(UnitTestDiscoverer);

public IEnumerable<KeyValuePair<string, string>> GetTraits(IAttributeInfo traitAttribute)
{
var name = traitAttribute.GetNamedArgument<string>("Identifier");

yield return new KeyValuePair<string, string>("Category", "UnitTest");

if (!string.IsNullOrWhiteSpace(name))
yield return new KeyValuePair<string, string>("UnitTest", name);
}
}
}
4 changes: 2 additions & 2 deletions src/Xunit.Categories/Xunit.Categories.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<Authors>Brendan Connolly</Authors>
<Company>Brendan Connolly</Company>
<Description>Friendly Traits for Xunit</Description>
<Version>2.0.0</Version>
<FileVersion>2.0.0</FileVersion>
<Version>2.0.1</Version>
<FileVersion>2.0.1</FileVersion>

<TargetFramework>netstandard1.1</TargetFramework>
</PropertyGroup>
Expand Down

0 comments on commit f3fe554

Please sign in to comment.