A game about forced loneliness, made by TACStudios
1using System; 2using System.Collections; 3using System.Reflection; 4using NUnit.Framework; 5using NUnit.Framework.Interfaces; 6using NUnit.Framework.Internal; 7using NUnit.Framework.Internal.Commands; 8using UnityEngine.TestRunner.NUnitExtensions.Runner; 9 10namespace UnityEngine.TestTools 11{ 12 internal class EnumerableRetryTestCommand : DelegatingTestCommand, IEnumerableTestMethodCommand 13 { 14 private int retryCount; 15 16 public EnumerableRetryTestCommand(RetryAttribute.RetryCommand commandToReplace) : base(commandToReplace.GetInnerCommand()) 17 { 18 retryCount = (int)typeof(RetryAttribute.RetryCommand) 19 .GetField("_retryCount", BindingFlags.NonPublic | BindingFlags.Instance) 20 .GetValue(commandToReplace); 21 } 22 23 public override TestResult Execute(ITestExecutionContext context) 24 { 25 throw new NotImplementedException("Use ExecuteEnumerable"); 26 } 27 28 public IEnumerable ExecuteEnumerable(ITestExecutionContext context) 29 { 30 var unityContext = (UnityTestExecutionContext)context; 31 int count = unityContext.EnumerableTestState.Retry; 32 var firstCycleAfterResume = count > 0; 33 34 while (count < retryCount || (firstCycleAfterResume && count <= retryCount)) 35 { 36 if (!firstCycleAfterResume) 37 { 38 count++; 39 } 40 41 firstCycleAfterResume = false; 42 43 unityContext.EnumerableTestState.Retry = count; 44 45 if (innerCommand is IEnumerableTestMethodCommand) 46 { 47 var executeEnumerable = ((IEnumerableTestMethodCommand)innerCommand).ExecuteEnumerable(context); 48 foreach (var iterator in executeEnumerable) 49 { 50 yield return iterator; 51 } 52 } 53 else 54 { 55 context.CurrentResult = innerCommand.Execute(context); 56 } 57 58 if (context.CurrentResult.ResultState != ResultState.Failure) 59 { 60 break; 61 } 62 } 63 64 unityContext.EnumerableTestState.Retry = 0; 65 } 66 } 67}