Skip to content

Commit

Permalink
new Attributes: Documentation, Exploratory, KownBug, WorkItem (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonwurzel authored and brendanconnolly committed Jan 5, 2018
1 parent da554bc commit 21c93b1
Show file tree
Hide file tree
Showing 9 changed files with 259 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/Xunit.Categories/DocumentationAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using Xunit.Sdk;

namespace Xunit.Categories
{
/// <summary>
/// For annotating tests that have a mainly documentative purpose, as sometimes a piece of code says more than a 1000 words API Documentation.
/// </summary>
[TraitDiscoverer(DocumentationDiscoverer.DiscovererTypeName, DiscovererUtil.AssemblyName)]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)]
public class DocumentationAttribute:Attribute,ITraitAttribute
{
public DocumentationAttribute(string workItemId)
{
this.WorkItemId = workItemId;
}

public DocumentationAttribute(long workItemId)
{
this.WorkItemId = workItemId.ToString();
}

public DocumentationAttribute()
{

}

public string WorkItemId { get; private set; }
}
}
23 changes: 23 additions & 0 deletions src/Xunit.Categories/DocumentationDiscoverer.cs
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 DocumentationDiscoverer : ITraitDiscoverer
{
internal const string DiscovererTypeName = DiscovererUtil.AssemblyName + "." + nameof(DocumentationDiscoverer);

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


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

if (!string.IsNullOrWhiteSpace(workItemId))
yield return new KeyValuePair<string, string>("Documentation", workItemId);

}
}
}
31 changes: 31 additions & 0 deletions src/Xunit.Categories/ExploratoryAttribute.cs
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 have a exploratory purpose like trying out an unknown API. Not neccessarily relating to your own code.
/// </summary>
/// <example>trying out LINQ for the first time, writing a piece of code to understand IEnumerable.Take and Skip.</example>
[TraitDiscoverer(ExploratoryDiscoverer.DiscovererTypeName, DiscovererUtil.AssemblyName)]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)]
public class ExploratoryAttribute:Attribute,ITraitAttribute
{
public ExploratoryAttribute(string workItemId)
{
this.WorkItemId = workItemId;
}

public ExploratoryAttribute(long workItemId)
{
this.WorkItemId = workItemId.ToString();
}

public ExploratoryAttribute()
{

}

public string WorkItemId { get; private set; }
}
}
23 changes: 23 additions & 0 deletions src/Xunit.Categories/ExploratoryDiscoverer.cs
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 ExploratoryDiscoverer : ITraitDiscoverer
{
internal const string DiscovererTypeName = DiscovererUtil.AssemblyName + "." + nameof(ExploratoryDiscoverer);

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


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

if (!string.IsNullOrWhiteSpace(workItemId))
yield return new KeyValuePair<string, string>("Exploratory", workItemId);

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

namespace Xunit.Categories
{
/// <summary>
/// For failing tests relating to known bugs that should not fail a build
/// </summary>
[TraitDiscoverer(KnownBugDiscoverer.DiscovererTypeName, DiscovererUtil.AssemblyName)]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)]
public class KnownBugAttribute:Attribute,ITraitAttribute
{
public KnownBugAttribute(string id)
{
this.Id = id;
}

public KnownBugAttribute(long id)
{
this.Id = id.ToString();
}

public KnownBugAttribute()
{

}

public string Id { get; private set; }
}
}
23 changes: 23 additions & 0 deletions src/Xunit.Categories/KnownBugDiscoverer.cs
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 KnownBugDiscoverer : ITraitDiscoverer
{
internal const string DiscovererTypeName = DiscovererUtil.AssemblyName + "." + nameof(KnownBugDiscoverer);

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


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

if (!string.IsNullOrWhiteSpace(bugId))
yield return new KeyValuePair<string, string>("KnownBug", bugId);

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

namespace Xunit.Categories
{
/// <summary>
/// For annotating tests that relate to a specific work item, not neccessarily a bug.
/// </summary>
[TraitDiscoverer(WorkItemDiscoverer.DiscovererTypeName, DiscovererUtil.AssemblyName)]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)]
public class WorkItemAttribute:Attribute,ITraitAttribute
{
public WorkItemAttribute(string workItemId)
{
this.WorkItemId = workItemId;
}

public WorkItemAttribute(long workItemId)
{
this.WorkItemId = workItemId.ToString();
}

public WorkItemAttribute()
{

}

public string WorkItemId { get; private set; }
}
}
23 changes: 23 additions & 0 deletions src/Xunit.Categories/WorkItemDiscoverer.cs
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 WorkItemDiscoverer : ITraitDiscoverer
{
internal const string DiscovererTypeName = DiscovererUtil.AssemblyName + "." + nameof(WorkItemDiscoverer);

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


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

if (!string.IsNullOrWhiteSpace(workItemId))
yield return new KeyValuePair<string, string>("WorkItem", workItemId);

}
}
}
46 changes: 46 additions & 0 deletions test/Xunit.Categories.Tests/Scratch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,52 @@ public void TestFeatureWithId()
throw new NotImplementedException("I've got your feature");
}

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

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

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

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

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





}

}

0 comments on commit 21c93b1

Please sign in to comment.