﻿namespace Fixie.Samples.Skipped
{
    using System;
    using System.Reflection;

    public class CustomConvention : Convention
    {
        public CustomConvention()
        {
            Classes
                .InTheSameNamespaceAs(typeof(CustomConvention))
                .NameEndsWith("Tests");

            Methods
                .OrderBy(x => x.Name, StringComparer.Ordinal);

            CaseExecution
                .Skip(SkipDueToClassLevelSkipAttribute, @case => "Whole class skipped")
                .Skip(SkipDueToMethodLevelSkipAttribute);

            ClassExecution
                .Lifecycle<CreateInstancePerClass>();
        }

        static bool SkipDueToClassLevelSkipAttribute(MethodInfo testMethod)
            => testMethod.DeclaringType.Has<SkipAttribute>();

        static bool SkipDueToMethodLevelSkipAttribute(MethodInfo testMethod)
            => testMethod.Has<SkipAttribute>();
    }
}
﻿namespace Fixie.Samples.Skipped
{
    using System;

    public class CustomConvention : Convention
    {
        public CustomConvention()
        {
            Classes
                .InTheSameNamespaceAs(typeof(CustomConvention))
                .NameEndsWith("Tests");

            Methods
                .OrderBy(x => x.Name, StringComparer.Ordinal);

            ClassExecution
                .Lifecycle<SkipLifecycle>();
        }

        class SkipLifecycle : Lifecycle
        {
            public void Execute(TestClass testClass, Action<CaseAction> runCases)
            {
                var skipClass = testClass.Type.Has<SkipAttribute>();

                var instance = skipClass ? null : testClass.Construct();

                runCases(@case =>
                {
                    var skipMethod = @case.Method.Has<SkipAttribute>();

                    if (skipClass)
                        @case.Skip("Whole class skipped");
                    else if (!skipMethod)
                        @case.Execute(instance);
                });

                instance.Dispose();
            }
        }
    }
}
Rephrase the Skipped sample to use runtime skips rather than declarative skips, demonstrating how runtime skips are superior: we have case-by-case skippability, implicit skips by conditionally avoiding executing a case, and the ability to avoid instantiating a test class if it is entirely marked as skipped.
Rephrase the Skipped sample to use runtime skips rather than declarative skips, demonstrating how runtime skips are superior: we have case-by-case skippability, implicit skips by conditionally avoiding executing a case, and the ability to avoid instantiating a test class if it is entirely marked as skipped.
