Skip to content

Commit

Permalink
Add Specification trait (#23)
Browse files Browse the repository at this point in the history
* create specification trait

* rename to specification
  • Loading branch information
emragins committed Jul 2, 2023
1 parent 784bb30 commit dc407cd
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/Xunit.Categories/SpecificationAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using Xunit.Sdk;

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

}

public SpecificationAttribute(string id)
{
this.Identifier = id;
}

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

public string Identifier { get; private set; }

}
}
21 changes: 21 additions & 0 deletions src/Xunit.Categories/SpecificationDiscoverer.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 SpecificationDiscoverer:ITraitDiscoverer
{
internal const string DiscovererTypeName = DiscovererUtil.AssemblyName + "." + nameof(SpecificationDiscoverer);

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

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

if (!string.IsNullOrWhiteSpace(name))
yield return new KeyValuePair<string, string>("Specification", name);
}
}
}
10 changes: 10 additions & 0 deletions test/Xunit.Categories.Test/Scratch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ public void TestExploratory()
throw new NotImplementedException("I'm not that important, all the world knows about me, I'll be fixed in 2030");
}


[Fact]
[Specification]
[Specification(666)]
[Specification("666 a")]
public void TestSpecification()
{
throw new NotImplementedException("I'm not that important, all the world knows about me, I'll be fixed in 2030");
}

[Fact]
[WorkItem]
[WorkItem(666)]
Expand Down

0 comments on commit dc407cd

Please sign in to comment.