Example #1
0
 public void Run(nspec instance)
 {
     if (CanRun(instance))
     {
         ContextUtils.RunAndHandleException(InvokeHooks, instance, ref exception);
     }
 }
Example #2
0
        public void Exercise(nspec instance)
        {
            if (example.ShouldSkip(instance.tagsFilter))
            {
                return;
            }

            example.HasRun = true;

            if (example.Pending)
            {
                ContextUtils.RunAndHandleException(example.RunPending, instance, ref example.Exception);

                return;
            }

            var stopWatch = example.StartTiming();

            using (new ConsoleCatcher(output => example.CapturedOutput = output))
            {
                context.BeforeChain.Run(instance);

                context.ActChain.Run(instance);

                if (CanRun())
                {
                    ContextUtils.RunAndHandleException(example.Run, instance, ref example.Exception);
                }

                context.AfterChain.Run(instance);
            }

            // when an expected exception is thrown and is set to be cleared by 'expect<>',
            // a subsequent exception thrown in 'after' hooks would go unnoticed, so do not clear in this case

            if (context.AfterChain.AnyThrew())
            {
                context.ClearExpectedException = false;
            }

            example.StopTiming(stopWatch);
        }
Example #3
0
        public void BuildMethodLevel(List <Type> classHierarchy)
        {
            var methods = ContextUtils.GetMethodsFromHierarchy(classHierarchy, methodSelector);

            var asyncMethods = ContextUtils.GetMethodsFromHierarchy(classHierarchy, asyncMethodSelector);

            if (reversed)
            {
                methods.Reverse();
                asyncMethods.Reverse();
            }

            if (methods.Count > 0)
            {
                ClassHook = instance => methods.Do(m => m.Invoke(instance, null));
            }

            if (asyncMethods.Count > 0)
            {
                AsyncClassHook = instance => asyncMethods.Do(m => new AsyncMethodLevelBefore(m).Run(instance));
            }
        }