Skip to content

Commit

Permalink
Expose the ability to attach categories to test methods even to the c…
Browse files Browse the repository at this point in the history
…one world.
  • Loading branch information
Tobbe Gyllebring committed Aug 2, 2018
1 parent 69bfeca commit e4ada0d
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 8 deletions.
9 changes: 9 additions & 0 deletions Source/Cone/IHaveCategories.cs
@@ -0,0 +1,9 @@
using System.Collections.Generic;

namespace Cone
{
public interface IHaveCategories
{
IEnumerable<string> Categories { get; }
}
}
2 changes: 1 addition & 1 deletion Source/Cone/ITestContext.cs
@@ -1,4 +1,4 @@
using Cone.Core;
using Cone.Core;

namespace Cone
{
Expand Down
5 changes: 2 additions & 3 deletions Source/Cone/ITestDescription.cs
@@ -1,10 +1,9 @@
using System.Collections.Generic;
using System.Collections.Generic;

namespace Cone
{
public interface IFixtureDescription
public interface IFixtureDescription : IHaveCategories
{
IEnumerable<string> Categories { get; }
string SuiteName { get; }
string SuiteType { get; }
string TestName { get; }
Expand Down
6 changes: 4 additions & 2 deletions Source/Cone/Runners/ConeTestMethodContext.cs
Expand Up @@ -15,8 +15,10 @@ public class ConeTestMethodContext : IConeAttributeProvider
public readonly IReadOnlyCollection<string> Categories;
public readonly ExpectedTestResult ExpectedResult;

public static ConeTestMethodContext Attributes(object[] attributes) =>
new ConeTestMethodContext(ExpectedTestResult.None, Null.Categories, attributes);
public static ConeTestMethodContext Attributes(object[] attributes) {
var categories = attributes.OfType<IHaveCategories>().SelectMany(x => x.Categories).ToArray();
return new ConeTestMethodContext(ExpectedTestResult.None, categories.Length == 0 ? Null.Categories : categories, attributes);
}

public ConeTestMethodContext(ExpectedTestResult result, IReadOnlyCollection<string> cats, object[] attributes) : this(null, result, cats, attributes) { }

Expand Down
4 changes: 2 additions & 2 deletions Source/Version.cs
Expand Up @@ -2,5 +2,5 @@
using System.Runtime.InteropServices;

[assembly: ComVisible(false)]
[assembly: AssemblyVersion("2018.07.10")]
[assembly: AssemblyInformationalVersion("2018.07.10")]
[assembly: AssemblyVersion("2018.07.31")]
[assembly: AssemblyInformationalVersion("2018.07.31")]
24 changes: 24 additions & 0 deletions Specs/Cone.Specs/Runners/ConeTestMethodContextSpec.cs
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cone.Runners;

namespace Cone.Specs.Runners
{
[Describe(typeof(ConeTestMethodContext))]
public class ConeTestMethodContextSpec
{
class MyCategories : IHaveCategories
{
public string[] Categories;
IEnumerable<string> IHaveCategories.Categories => Categories;
}

public void extracts_categories_from_attributes() {
Check.With(() => ConeTestMethodContext.Attributes(new[] { new MyCategories { Categories = new[] { "MyCat" } } }))
.That(context => context.Categories.Contains("MyCat"));
}
}
}

0 comments on commit e4ada0d

Please sign in to comment.