Ejemplo n.º 1
0
        public void ShouldPassAfter3RetriesAndTimeoutIsResetEachTime()
        {
            // Rather than testing with sleeps, this tests that the execution will occur in the correct
            // order by checking which commands are run when. As the retry command comes first, the
            // timeout will be reset each time it runs
            var            test    = TestBuilder.MakeTestFromMethod(typeof(HelperMethodForTimeoutsClass), nameof(HelperMethodForTimeoutsClass.ShouldPassAfter3RetriesAndTimeoutIsResetEachTime));
            SimpleWorkItem work    = TestBuilder.CreateWorkItem(test) as SimpleWorkItem;
            var            method  = typeof(SimpleWorkItem).GetMethod("MakeTestCommand", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly);
            TestCommand    command = (TestCommand)method.Invoke(work, null);

            Assert.That(command, Is.TypeOf(typeof(RetryAttribute.RetryCommand)));
            RetryAttribute.RetryCommand retryCommand = (RetryAttribute.RetryCommand)command;

            command = GetInnerCommand(retryCommand);

            Assert.That(command, Is.TypeOf(typeof(TimeoutCommand)));
            TimeoutCommand timeoutCommand = (TimeoutCommand)command;

            command = GetInnerCommand(timeoutCommand);

            Assert.That(command, Is.TypeOf(typeof(ApplyChangesToContextCommand)));
            ApplyChangesToContextCommand applyChangesToContextCommand = (ApplyChangesToContextCommand)command;

            command = GetInnerCommand(applyChangesToContextCommand);

            Assert.That(command, Is.TypeOf(typeof(TestMethodCommand)));
        }
 public EnumerableRetryTestCommand(RetryAttribute.RetryCommand commandToReplace) : base(commandToReplace.GetInnerCommand())
 {
     retryCount = (int)typeof(RetryAttribute.RetryCommand)
                  .GetField("_retryCount", BindingFlags.NonPublic | BindingFlags.Instance)
                  .GetValue(commandToReplace);
 }