public void accept_visitor() { var executor = MockRepository.GenerateMock <IStepExecutor>(); var action = new SilentAction("Fixture", Stage.setup, x => { }, new Section("Math")); action.AcceptVisitor(executor); executor.AssertWasCalled(x => x.Line(action)); }
public void accept_visitor() { var executor = Substitute.For <ILineStepGatherer>(); var action = new SilentAction("Fixture", Stage.setup, x => { }, new Section("Math")); action.AcceptVisitor(executor); executor.Received().Line(action); }
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 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); }
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"); }
private IEnumerable<IExecutionStep> toExecutionSteps(FixtureLibrary library, Fixture fixture) { var setup = SilentAction.AsCritical("Fixture", Stage.setup, x => { fixture.Context = x; fixture.SetUp(); }, this); setup.Subject = Key + ":SetUp"; yield return setup; // Ignore comments! foreach (var step in Children.OfType<Step>()) { var grammar = fixture.GrammarFor(step.Key); yield return grammar.CreatePlan(step, library); } var teardown = SilentAction.AsCritical("Fixture", Stage.teardown, x => fixture.TearDown(), this); teardown.Subject = Key + ":TearDown"; yield return teardown; }
/// <summary> /// Do not raise errors while execution the action /// </summary> /// <param name="silent">Indicates that the action should be silent</param> /// <param name="action"></param> public static void DontRaiseError(bool silent, SilentAction action) { // Heuristic : // Do not notify changes in the model when we are not interested // in the errors raised while performing the action Util.DontNotify(() => { if (silent) { try { SilentCount += 1; if (SilentCount == 1) { BeSilent = true; action(); } else { action(); } } finally { SilentCount -= 1; if (SilentCount == 0) { BeSilent = false; } } } else { action(); } }); }
/// <summary> /// Do not raise errors while execution the action /// </summary> /// <param name="action"></param> public static void DontRaiseError(SilentAction action) { DontRaiseError(true, action); }