Esempio n. 1
0
        public void fetch()
        {
            var comparison = new StringListComparison("expected", c => new String[] { "red", "blue", "green" });
            var task       = comparison.Fetch(SpecContext.ForTesting());

            task.Wait();

            task.Result.Select(x => x.Get("expected"))
            .ShouldHaveTheSameElementsAs("red", "blue", "green");
        }
        public void execute_delegates()
        {
            var action  = Substitute.For <System.Action <ISpecContext> >();
            var grammar = new ActionGrammar("do something", action);

            var context = SpecContext.ForTesting();

            grammar.Execute(new StepValues("foo"), context).ToArray();

            action.Received().Invoke(context);
        }
        public void execute_delegates()
        {
            var action  = MockRepository.GenerateMock <System.Action <ISpecContext> >();
            var grammar = new ActionGrammar("do something", action);

            var context = SpecContext.ForTesting();

            grammar.Execute(new StepValues("foo"), context).ToArray();

            action.AssertWasCalled(x => x.Invoke(context));
        }
        public void fetch()
        {
            var task = comparer.Fetch(SpecContext.ForTesting());

            task.Wait();

            var values = task.Result;

            values.Count().ShouldBe(3);
            values[0].Get("City").ShouldBe("Austin");
            values[1].Get("Address1").ShouldBe("2 Road");
            values[2].Get("DistanceFromOffice").ShouldBe(15.0);
        }
Esempio n. 5
0
        public void execute_logs_a_step_result_error()
        {
            var context = SpecContext.ForTesting();

            var step = new InvalidGrammarStep(new StepValues("the id"), "grammar is wonky");

            step.Execute(context);

            var result = context.Results.Single().ShouldBeOfType <StepResult>();

            result.id.ShouldBe("the id");
            result.status.ShouldBe(ResultStatus.error);
            result.error.ShouldBe("grammar is wonky");
        }
        public void execute_happy_path()
        {
            var wasCalled = false;
            var section   = new Section("Math")
            {
                id = "4"
            };
            var action  = new SilentAction("Fixture", Stage.setup, x => wasCalled = true, section);
            var context = SpecContext.ForTesting();

            action.Execute(context);

            wasCalled.ShouldBe(true);
        }
        public void execute_happy()
        {
            var grammar = ValueCheckMethod.For(new Target(), x => x.Fullname(null, null));
            var values  = new StepValues("1");

            values.Store("first", "Mat");
            values.Store("last", "Cauthon");
            values.Store("expected", "Mat Cauthon");

            var context = SpecContext.ForTesting();
            var result  = grammar.Execute(values, context).Single();

            result.cell.ShouldBe("expected");
            result.Status.ShouldBe(ResultStatus.success);
        }
        public void exceptions_are_critical()
        {
            var context = SpecContext.ForTesting();
            var ex      = new DivideByZeroException();

            var section = new Section("Math")
            {
                id = "5"
            };
            var action = SilentAction.AsCritical("Fixture", Stage.teardown, x => { throw ex; }, section);

            action.Execute(context);

            context.CanContinue().ShouldBe(false);
        }
Esempio n. 9
0
        public void process_delayed_runtime_convertor_that_fails_with_a_null()
        {
            var context = SpecContext.ForTesting();
            var values  = new StepValues("1");

            values.RegisterDelayedConversion("a", "1", new StubRuntimeConverter("1", null));

            values.DoDelayedConversions(context);

            var result = values.Errors.Single().ShouldBeOfType <CellResult>();

            result.Status.ShouldBe(ResultStatus.error);
            result.cell.ShouldBe("a");
            result.error.ShouldContain("The converter was not able to create a value. Check the formatting.");
        }
Esempio n. 10
0
        public void process_delayed_runtime_convertor_that_fails_with_exception()
        {
            var context = SpecContext.ForTesting();
            var values  = new StepValues("1");

            values.RegisterDelayedConversion("a", "1", new StubRuntimeConverter("1", new NotImplementedException()));

            values.DoDelayedConversions(context);

            var result = values.Errors.Single().ShouldBeOfType <CellResult>();

            result.Status.ShouldBe(ResultStatus.error);
            result.cell.ShouldBe("a");
            result.error.ShouldContain("NotImplementedException");
        }
Esempio n. 11
0
        public void process_delayed_runtime_converters_successfully()
        {
            var context = SpecContext.ForTesting();
            var values  = new StepValues("1");

            values.RegisterDelayedConversion("a", "1", new StubRuntimeConverter("1", 1));
            values.RegisterDelayedConversion("b", "2", new StubRuntimeConverter("2", 2));
            values.RegisterDelayedConversion("c", "3", new StubRuntimeConverter("3", 3));

            values.DoDelayedConversions(context);

            values.Get("a").ShouldBe(1);
            values.Get("b").ShouldBe(2);
            values.Get("c").ShouldBe(3);

            ShouldBeTestExtensions.ShouldBe(values.Errors.Any(), false);
        }
Esempio n. 12
0
        public async Task after_each_is_called_on_context_after_execution()
        {
            using (var system = new FakeStorytellerSystem())
            {
                await system.Warmup();

                system.AfterEachWasCalled.ShouldBeFalse();
                using (var context = system.CreateContext())
                {
                    var specContext = SpecContext.ForTesting();
                    context.BeforeExecution(specContext);

                    context.AfterExecution(specContext);
                    system.AfterEachWasCalled.ShouldBeTrue();
                }
            }
        }
        public void execute_sad()
        {
            var grammar = ValueCheckMethod.For(new Target(), x => x.Fullname(null, null));
            var values  = new StepValues("1");

            values.Store("first", "Mat");
            values.Store("last", "Cauthon");
            values.Store("expected", "Rand Al'Thor");

            var context = SpecContext.ForTesting();
            var result  = grammar.Execute(values, context).Single();

            // The method is working correctly, but the
            // test data should result in a failure
            result.cell.ShouldBe("expected");
            result.actual.ShouldBe("Mat Cauthon");
            result.Status.ShouldBe(ResultStatus.failed);
        }
Esempio n. 14
0
        public void after_each_is_called_as_context_is_finished()
        {
            using (var system = new FakeSerenitySystem())
            {
                system.AfterEachWasCalled.ShouldBe(0);

                var context1 = system.As <ISystem>().CreateContext();
                var scope1   = system.LastScope;

                var specContext = SpecContext.ForTesting();

                context1.AfterExecution(specContext);

                // uses the same scope for the spec
                system.LastScope.ShouldBeTheSameAs(scope1);
                system.LastContext.ShouldBeSameAs(specContext);
                system.AfterEachWasCalled.ShouldBe(1);
            }
        }
        public void execute_sad_path()
        {
            var context = SpecContext.ForTesting();
            var ex      = new DivideByZeroException();

            var section = new Section("Math")
            {
                id = "5"
            };
            var action = new SilentAction("Fixture", Stage.teardown, x => { throw ex; }, section);

            action.Execute(context);

            var result = context.Results.Single().ShouldBeOfType <StepResult>();

            result.id.ShouldBe(section.id);
            result.position.ShouldBe(Stage.teardown.ToString());
            result.status.ShouldBe(ResultStatus.error);
            result.error.ShouldContain("DivideByZeroException");
        }
Esempio n. 16
0
 public void SetUp()
 {
     values         = new StepValues(Guid.NewGuid().ToString());
     context        = SpecContext.ForTesting();
     theLineGrammar = MockRepository.GenerateMock <ILineGrammar>();
 }
 public LinePlanTester()
 {
     values         = new StepValues(Guid.NewGuid().ToString());
     context        = SpecContext.ForTesting();
     theLineGrammar = Substitute.For <ILineGrammar>();
 }