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 EnumerableRepeatedTestCommand : DelegatingTestCommand, IEnumerableTestMethodCommand 13 { 14 private int repeatCount; 15 16 public EnumerableRepeatedTestCommand(RepeatAttribute.RepeatedTestCommand commandToReplace) : base(commandToReplace.GetInnerCommand()) 17 { 18 repeatCount = (int)typeof(RepeatAttribute.RepeatedTestCommand) 19 .GetField("repeatCount", 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.Repeat; 32 var firstCycleAfterResume = count > 0; 33 34 while (count < repeatCount || (firstCycleAfterResume && count <= repeatCount)) 35 { 36 if (!firstCycleAfterResume) 37 { 38 count++; 39 } 40 41 firstCycleAfterResume = false; 42 unityContext.EnumerableTestState.Repeat = count; 43 44 if (innerCommand is IEnumerableTestMethodCommand) 45 { 46 var executeEnumerable = ((IEnumerableTestMethodCommand)innerCommand).ExecuteEnumerable(context); 47 foreach (var iterator in executeEnumerable) 48 { 49 yield return iterator; 50 } 51 } 52 else 53 { 54 context.CurrentResult = innerCommand.Execute(context); 55 } 56 57 if (context.CurrentResult.ResultState != ResultState.Success) 58 { 59 break; 60 } 61 } 62 63 unityContext.EnumerableTestState.Repeat = 0; 64 } 65 } 66}