Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add environment variable controlled skipable LocalFactAttribute (#6009)
* Add environment variable controlled skipable LocalFactAttribute * Fix copyright header
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
src/contrib/testkits/Akka.TestKit.Xunit2/Attributes/LocalFactAttribute.cs
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,51 @@ | ||
//----------------------------------------------------------------------- | ||
// <copyright file="LocalFactAttribute.cs" company="Akka.NET Project"> | ||
// Copyright (C) 2013-2022 .NET Foundation <https://github.com/akkadotnet/akka.net> | ||
// </copyright> | ||
//----------------------------------------------------------------------- | ||
|
||
using System; | ||
using Xunit; | ||
|
||
namespace Akka.TestKit.Xunit2.Attributes | ||
{ | ||
/// <summary> | ||
/// <para> | ||
/// This custom XUnit Fact attribute will skip unit tests if the environment variable | ||
/// "XUNIT_SKIP_LOCAL_FACTS" exists and is set to the string "true" | ||
/// </para> | ||
/// <para> | ||
/// Note that the original <see cref="FactAttribute.Skip"/> property takes precedence over this attribute, | ||
/// any unit tests with <see cref="LocalFactAttribute"/> with its <see cref="FactAttribute.Skip"/> property | ||
/// set will always be skipped, regardless of the environment variable content. | ||
/// </para> | ||
/// </summary> | ||
public class LocalFactAttribute: FactAttribute | ||
{ | ||
private const string EnvironmentVariableName = "XUNIT_SKIP_LOCAL_FACTS"; | ||
|
||
private string _skip; | ||
|
||
/// <inheritdoc cref="FactAttribute.Skip"/> | ||
public override string Skip | ||
{ | ||
get | ||
{ | ||
if (_skip != null) | ||
return _skip; | ||
|
||
var skipLocal = Environment.GetEnvironmentVariable(EnvironmentVariableName)? | ||
.ToLowerInvariant(); | ||
return skipLocal is "true" ? SkipLocal ?? "Local facts are being skipped" : null; | ||
} | ||
set => _skip = value; | ||
} | ||
|
||
/// <summary> | ||
/// The reason why this unit test is being skipped by the <see cref="LocalFactAttribute"/>. | ||
/// Note that the original <see cref="FactAttribute.Skip"/> property takes precedence over this message. | ||
/// </summary> | ||
public string SkipLocal { get; set; } | ||
} | ||
} | ||
|