-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from JoshKeegan/skipAndSpecflowIgnore
Implement dynamic Skip and Specflow ignore
- Loading branch information
Showing
29 changed files
with
549 additions
and
36 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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
VERSION=1.6.0# | ||
VERSION=1.7.0# | ||
|
||
clean: | ||
rm -r ../artefacts || true | ||
|
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,14 @@ | ||
using System; | ||
|
||
// ReSharper disable once CheckNamespace | ||
// ReSharper disable once IdentifierTypo | ||
namespace Xunit | ||
{ | ||
/// <summary> | ||
/// Do not use. | ||
/// Exists purely as a marker to replicate the exception thrown by Xunit.SkippableFact that SpecFlow.xUnit | ||
/// makes use of. That way we can intercept the exception that is throwing without also having our own runtime | ||
/// plugin, or adding a direct dependency on either of these other libraries. | ||
/// </summary> | ||
internal class SkipException : Exception { } | ||
} |
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
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
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
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,30 @@ | ||
using System; | ||
using System.Runtime.Serialization; | ||
|
||
namespace xRetry.Exceptions | ||
{ | ||
[Serializable] | ||
public class SkipTestException : Exception | ||
{ | ||
public readonly string Reason; | ||
|
||
public SkipTestException(string reason) | ||
: base("Test skipped. Reason: " + reason) | ||
{ | ||
Reason = reason; | ||
} | ||
|
||
protected SkipTestException(SerializationInfo info, StreamingContext context) | ||
: base(info, context) | ||
{ | ||
Reason = info.GetString(nameof(Reason)); | ||
} | ||
|
||
public override void GetObjectData(SerializationInfo info, StreamingContext context) | ||
{ | ||
info.AddValue(nameof(Reason), Reason); | ||
|
||
base.GetObjectData(info, context); | ||
} | ||
} | ||
} |
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,24 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace xRetry.Extensions | ||
{ | ||
public static class EnumerableExtensions | ||
{ | ||
public static bool ContainsAny<T>(this IEnumerable<T> values, T[] searchFor, IEqualityComparer<T> comparer = null) | ||
{ | ||
if (searchFor == null) | ||
{ | ||
throw new ArgumentNullException(nameof(searchFor)); | ||
} | ||
if (comparer == null) | ||
{ | ||
comparer = EqualityComparer<T>.Default; | ||
} | ||
|
||
return searchFor.Length != 0 && | ||
values.Any(val => searchFor.Any(search => comparer.Equals(val, search))); | ||
} | ||
} | ||
} |
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
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,39 @@ | ||
using System.Linq; | ||
using xRetry.Extensions; | ||
using Xunit.Abstractions; | ||
using Xunit.Sdk; | ||
|
||
namespace xRetry | ||
{ | ||
public class MessageTransformer | ||
{ | ||
private readonly string[] skipOnExceptionFullNames; | ||
|
||
public bool Skipped { get; private set; } | ||
|
||
public MessageTransformer(string[] skipOnExceptionFullNames) | ||
{ | ||
this.skipOnExceptionFullNames = skipOnExceptionFullNames; | ||
} | ||
|
||
/// <summary> | ||
/// Transforms a message received from an xUnit test into another message, replacing it | ||
/// where necessary to add additional functionality, e.g. dynamic skipping | ||
/// </summary> | ||
/// <param name="message"></param> | ||
/// <returns></returns> | ||
public IMessageSinkMessage Transform(IMessageSinkMessage message) | ||
{ | ||
// If this is a message saying that the test has been skipped, replace the message with skipping the test | ||
if (message is TestFailed failed && failed.ExceptionTypes.ContainsAny(skipOnExceptionFullNames)) | ||
{ | ||
string reason = failed.Messages?.FirstOrDefault(); | ||
Skipped = true; | ||
return new TestSkipped(failed.Test, reason); | ||
} | ||
|
||
// Otherwise this isn't a message saying the test is skipped, follow usual intercept for replay later behaviour | ||
return message; | ||
} | ||
} | ||
} |
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
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
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
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
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
Oops, something went wrong.