Created
February 10, 2019 01:25
-
-
Save jnm2/0dfcf7dabfb8db76865c124d3a59b20f to your computer and use it in GitHub Desktop.
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
using System; | |
using NUnit.Framework; | |
using NUnit.Framework.Interfaces; | |
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method)] | |
public sealed class WaitForAmbientTasksAttribute : Attribute, ITestAction | |
{ | |
public ActionTargets Targets => ActionTargets.Test; | |
public void BeforeTest(ITest test) | |
{ | |
AmbientTasks.BeginContext(); | |
} | |
public void AfterTest(ITest test) | |
{ | |
switch (TestContext.CurrentContext.Result.Outcome.Status) | |
{ | |
case TestStatus.Failed: | |
case TestStatus.Inconclusive: | |
case TestStatus.Skipped: | |
return; | |
} | |
var task = AmbientTasks.WaitAllAsync(); | |
if (!task.IsCompleted) Assert.Fail("The test started ambient tasks but did not wait for them."); | |
task.GetAwaiter().GetResult(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment