Example #1
0
        public void Execute(Fixture fixture, Action next)
        {
            foreach (var @case in fixture.Cases)
            {
                using (var console = new RedirectedConsole())
                {
                    @case.Fixture = fixture;

                    var stopwatch = new Stopwatch();
                    stopwatch.Start();

                    try
                    {
                        caseBehaviors.Execute(@case);
                    }
                    catch (Exception exception)
                    {
                        @case.Fail(exception);
                    }

                    stopwatch.Stop();

                    @case.Fixture  = null;
                    @case.Duration = stopwatch.Elapsed;
                    @case.Output   = console.Output;
                }

                Console.Write(@case.Output);
            }
        }
Example #2
0
        public void ShouldDoNothingWhenEmpty()
        {
            var context = new BreadCrumbs();
            var chain   = new BehaviorChain <BreadCrumbs>();

            chain.Execute(context);

            context.Crumbs.ShouldBeEmpty();
            context.Exceptions.ShouldBeEmpty();
        }
Example #3
0
        void PerformClassLifecycle(Class testClass, IReadOnlyList <Case> casesForThisInstance)
        {
            var instance = testClassFactory(testClass.Type);

            var fixture = new Fixture(testClass, instance, casesForThisInstance);

            fixtureBehaviors.Execute(fixture);

            (instance as IDisposable)?.Dispose();
        }
Example #4
0
        public void ShouldExecuteBehaviorsInOrder()
        {
            var context = new BreadCrumbs();
            var chain   = new BehaviorChain <BreadCrumbs>(
                new OuterBehavior(),
                new InnerBehavior()
                );

            chain.Execute(context);

            context.Crumbs.ShouldEqual(
                "Entering OuterBehavior",
                "Entering InnerBehavior",
                "Leaving InnerBehavior",
                "Leaving OuterBehavior");
        }
Example #5
0
        public void ShouldHandleUncaughtExceptionsAtEachStepInTheChainByLoggingThemToTheContextObject()
        {
            var context = new BreadCrumbs();
            var chain   = new BehaviorChain <BreadCrumbs>(
                new OuterBehavior(),
                new InnerBehavior(),
                new BuggyBehavior()
                );

            chain.Execute(context);

            context.Crumbs.ShouldEqual(
                "Entering OuterBehavior",
                "Entering InnerBehavior",
                "Entering BuggyBehavior",
                "Leaving InnerBehavior",
                "Leaving OuterBehavior");

            context.Exceptions.Single().Message.ShouldEqual("BuggyBehavior Threw!");
        }