public void Execute(SpecContext context) { using (context.Timings.Subject(Type, Subject)) { Values.DoDelayedConversions(context); if (Values.Errors.Any()) { var result = Values.ToConversionErrorResult(); result.position = Position; context.LogResult(result); return; } try { var result = execute(context); result.position = Position; context.LogResult(result); } catch (Exception ex) { context.LogException(Values.id, ex, Position); } } }
protected override Task executeSteps(SpecContext context, IList<ILineExecution> lines, CancellationToken token) { _steps = lines; Context = context; _observer.SendProgress(new SpecProgress(Context.Specification.id, Context.Counts, 0, _steps.Count)); _executionObserver.SpecStarted(Request); if (Request.Mode == ExecutionMode.stepthrough) { sendNextStepMessage(); } else if (Request.Mode == ExecutionMode.breakpoint) { RunToBreakpoint(); } else { return base.executeSteps(context, lines, token); } _hasStarted.SetResult(true); return _completion.Task; }
public StepthroughExecutor(IExecutionContext execution, SpecExecutionRequest request, IUserInterfaceObserver observer) { _context = new SpecContext(request.Specification, new Timings(), request.Observer, new StopConditions(), execution); _execution = execution; _request = request; _observer = observer; var gatherer = new ExecutionStepGatherer(_context); _request.Plan.AcceptVisitor(gatherer); _steps = gatherer.Lines; try { _execution.BeforeExecution(_context); } catch (Exception e) { _context.LogException(_request.Id, e, "BeforeExecution"); } _observer.SendProgress(new SpecProgress(_request.Id, _context.Counts, 0, _steps.Count)); sendNextStepMessage(); }
public void Execute(SpecContext context) { using (context.Timings.Subject("Grammar", _section.Key)) { var fetch = _comparison.Fetch(context); _expected.Each(x => { x.DoDelayedConversions(context); if (!x.Errors.Any()) return; context.LogResult(x.ToConversionErrorResult()); }); if (_expected.Any(x => x.HasErrors())) return; fetch.ContinueWith(t => { if (t.IsFaulted) { // TODO -- do the Flatten() trick here on the aggregated exception context.LogException(_section.id, t.Exception, Stage.before); return; } if (t.IsCompleted) { var result = CreateResults(_expected, t.Result); result.id = _section.id; context.LogResult(result); } }).Wait(); } }
public void Execute(SpecContext context) { foreach (var line in _lines) { line.Execute(context); } }
public InstrumentedExecutor(SpecContext context, SpecificationPlan plan, IUserInterfaceObserver observer) : base(context) { _observer = observer; _total = plan.Count(); _step = 0; _plan = plan; }
public static void RunAll(SpecContext context, SpecificationPlan plan) { var gatherer = new LineStepGatherer(context); plan.AcceptVisitor(gatherer); foreach (var line in gatherer.Lines) { if (!context.CanContinue()) break; line.Execute(context); } }
public void Execute(SpecContext context) { using (context.Timings.Subject(type, Subject)) try { Action(context); context.LogResult(new StepResult(Id, ResultStatus.ok) {position = Position}); } catch (Exception ex) { context.LogException(Node.id, ex, Position); } }
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); }
public void execute() { var grammar = ActionMethodGrammar.Create(x => x.Go(null, 0, 0), theTarget); grammar.Compile(new Fixture(), CellHandling.Basic()).ShouldBeOfType <Sentence>(); var values = new StepValues("id"); values.Store("name", "Jeremy"); values.Store("age", 41); values.Store("percentAwake", 50.1); ShouldBeTestExtensions.ShouldBe(grammar.Execute(values, SpecContext.Basic()).Any(), false); theTarget.Name.ShouldBe("Jeremy"); theTarget.Age.ShouldBe(41); theTarget.PercentAwake.ShouldBe(50.1); }
//[Fact] public void record_and_save_file() { var data = new ClientData(); var library = TestingContext.Library; var hierarchy = TestingContext.Hierarchy; hierarchy.GetAllSpecs().Each(x => x.path.ShouldNotBeNull()); hierarchy.GetAllSpecs().Each(spec => { data.specs.Add(spec.id, spec); using (var execution = theSystem.CreateContext()) { var observer = new RecordingObserver(data.results); using (var context = new SpecContext(spec, null, observer, new StopConditions(), execution) ) { context.Reporting.As <Reporting>().StartDebugListening(); var plan = spec.CreatePlan(library); var executor = new SynchronousExecutor(context); plan.AcceptVisitor(executor); observer.SpecExecutionFinished(spec, context.FinalizeResults(1)); } } }); data.specs.Values.Each(x => x.path.ShouldNotBeNull()); data.hierarchy = hierarchy; data.fixtures = library.Models.Where(x => x.implementation.Contains("StoryTeller.Samples")).ToArray(); var json = JsonSerialization.ToIndentedJson(data); var clientPath = TestingContext.FindClientFolder(); new FileSystem().WriteStringToFile(clientPath.AppendPath("all-spec-data.js"), "module.exports = " + json); Debug.WriteLine("Wrote file to all-spec-data.js"); }
private SpecResults buildResults(SpecContext context, Timings timings) { if (Request.IsCancelled) { return(null); } var catastrophic = context?.CatastrophicException; if (catastrophic != null) { throw new StorytellerExecutionException(catastrophic); } Finished = !_timeout.IsCompleted && !Request.IsCancelled; if (_timeout.IsCompleted && !Request.IsCancelled) { var result = timeoutMessage(timings); if (context == null) { var perf = timings.Finish(); return(new SpecResults { Counts = new Counts(0, 0, 1, 0), Duration = timings.Duration, Performance = perf.ToArray(), Attempts = Request.Plan.Attempts, Results = new IResultMessage[] { result }, WasAborted = false }); } context.LogResult(result, null); context.Cancel(); } return(context.FinalizeResults(Request.Plan.Attempts)); }
// If this fails, it's a catastrophic exception public SpecResults Execute(ISystem system, Timings timings) { _timeout = setupTimeout(); using (var execution = createExecutionContext(system, timings)) { if (Request.IsCancelled) { return(null); } using (var context = new SpecContext( Request.Specification, timings, Request.Observer, StopConditions, execution)) { if (Request.Specification.HasNoSteps()) { context.LogException(Request.Specification.id, new NotImplementedException("Empty specification with no implementation"), null, Stage.context); } beforeExecution(execution, context); var lines = determineLineSteps(context); startDebugListening(context); Logger.Starting(lines); if (lines.Any()) { var stepRunning = executeSteps(context, lines, Request.Cancellation); Task.WaitAny(stepRunning, _timeout); } execution.AfterExecution(context); return(buildResults(context, timings)); } } }
public void Execute(SpecContext context) { using (context.Timings.Subject(_type, Subject)) try { _action(context); context.LogResult(new StepResult(Id, ResultStatus.ok) { position = Position }); } catch (Exception ex) { context.LogException(_node.id, ex, Position); } }
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); } }
private void execute() { try { using (_timings.Subject("Context", "Creation")) { _execution = _system.CreateContext(); } } catch (Exception e) { _catastrophicException = e; _reset.Set(); return; } if (_request.IsCancelled) { return; } _context = new SpecContext(_request.Specification, _timings, _request.Observer, _stopConditions, _execution); try { _execution.BeforeExecution(_context); } catch (Exception e) { _context.LogException(_request.Id, e, "BeforeExecution"); } _context.Reporting.As <Reporting>().StartDebugListening(); var executor = _mode.BuildExecutor(_request.Plan, _context); _request.Plan.AcceptVisitor(executor); _execution.AfterExecution(_context); _reset.Set(); }
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"); }
public void FixtureSetup() { var lifecycle = BrowserForTesting.Use <TBrowser>(); var services = new InMemoryServiceLocator(); Context = new SpecContext(null, new Timings(), new NulloResultObserver(), new StopConditions(), services); var applicationUnderTest = new StubbedApplicationUnderTest { Browser = lifecycle }; applicationUnderTest.Driver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromMilliseconds(1000)); services.Add <IApplicationUnderTest>(applicationUnderTest); SetUp(); }
public void FixtureSetup() { var lifecycle = BrowserForTesting.Use <TBrowser>(); var simpleExecutionContext = new SimpleExecutionContext(); Context = new SpecContext(null, new Timings(), new NulloResultObserver(), new StopConditions(), simpleExecutionContext); var applicationUnderTest = new StubbedApplicationUnderTest { Browser = lifecycle }; applicationUnderTest.Driver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromMilliseconds(1000)); simpleExecutionContext.Register <IApplicationUnderTest>(applicationUnderTest); SetUp(); }
public static IEnumerable <PerfRecord> RunAll(SpecContext context, SpecificationPlan plan) { var gatherer = new LineStepGatherer(context); plan.AcceptVisitor(gatherer); context.Timings.Start(plan.Specification); foreach (var line in gatherer.Lines) { if (!context.CanContinue()) { break; } line.Execute(context); } return(context.FinalizeResults(1).Performance); }
public void Execute(SpecContext context) { using (context.Timings.Subject("Grammar", _section.Key)) { var fetch = _comparison.Fetch(context); _expected.Each(x => { x.DoDelayedConversions(context); if (!x.Errors.Any()) { return; } context.LogResult(x.ToConversionErrorResult()); }); if (_expected.Any(x => x.HasErrors())) { return; } fetch.ContinueWith(t => { if (t.IsFaulted) { // TODO -- do the Flatten() trick here on the aggregated exception context.LogException(_section.id, t.Exception, Stage.before); return; } if (t.IsCompleted) { var result = CreateResults(_expected, t.Result); result.id = _section.id; context.LogResult(result); } }).Wait(); } }
public SpecResults Execute(Specification specification) { var plan = specification.CreatePlan(_library); var timings = new Timings(); timings.Start(specification); IExecutionContext execution = null; var record = timings.Subject("Context", "Creation", 0); try { execution = _system.CreateContext(); } finally { timings.End(record); } var context = new SpecContext(specification, timings, new NulloResultObserver(), StopConditions, execution); context.Reporting.As <Reporting>().StartDebugListening(); var gatherer = new LineStepGatherer(context); plan.AcceptVisitor(gatherer); foreach (var line in gatherer.Lines) { line.Execute(context); } execution.Dispose(); context.Dispose(); return(context.FinalizeResults(1)); }
public string ToJsonString() { var verStr = SpecContext.Specification switch { Specification.ClientServer => SpecContext.ClientServer(SpecContext).RemovedVersion.ToJsonString(), Specification.ServerServer => SpecContext.ServerServer(SpecContext).RemovedVersion.ToJsonString(), Specification.ApplicationService => SpecContext.ApplicationService(SpecContext).RemovedVersion.ToJsonString(), Specification.IdentityService => SpecContext.IdentityService(SpecContext).RemovedVersion.ToJsonString(), Specification.PushGateway => SpecContext.PushGateway(SpecContext).RemovedVersion.ToJsonString(), Specification.Rooms => SpecContext.Rooms(SpecContext).RemovedVersion.ToJsonString(), _ => throw new InvalidDataException(Resources.UnknownMatrixApiType) }; var apiStr = SpecContext.Specification.ToJsonString(); return($"{MatrixSpecUrl}/{apiStr}/{verStr}.html#${Path}"); } }
public Task ExecuteAsync(SpecContext context, CancellationToken cancellation) { if (!IsAsync()) { return(Task.Factory.StartNew(() => Execute(context), cancellation)); } var record = context.Timings.Subject(Type, Subject, maximumRuntimeInMilliseconds); return(executeAsync(context).ContinueWith(t => { if (t.IsFaulted) { context.LogException(Values.id, t.Exception, record, Position); } else { var result = t.Result; result.position = Position; context.LogResult(result, record); } }, cancellation)); }
private void execute(EventWaitHandle reset) { try { using (_timings.Subject("Context", "Creation")) { _execution = _system.CreateContext(); } } catch (Exception e) { _catastrophicException = e; reset.Set(); return; } if (_request.IsCancelled) return; _context = new SpecContext(_request.Specification, _timings, _request.Observer, _stopConditions, _execution); try { _execution.BeforeExecution(_context); } catch (Exception e) { _context.LogException(_request.Id, e, "BeforeExecution"); } _context.Reporting.As<Reporting>().StartDebugListening(); var executor = _mode.BuildExecutor(_request.Plan, _context); _request.Plan.AcceptVisitor(executor); _execution.AfterExecution(_context); reset.Set(); }
public StepthroughExecutor(SpecContext context, SpecificationPlan plan, IUserInterfaceObserver observer) { _observer = observer; _context = context; plan.AcceptVisitor(this); }
private static void startDebugListening(SpecContext context) { context.Reporting.As <Reporting>().StartDebugListening(); }
public void SetUp() { values = new StepValues(Guid.NewGuid().ToString()); context = SpecContext.ForTesting(); theLineGrammar = MockRepository.GenerateMock<ILineGrammar>(); }
private static void ShouldSeeNoBudgetCategories(SpecContext context) { var budget = context.Get <BudgetModel>(); Assert.AreEqual(0, budget.Categories.Length); }
private StepResult findStepResult(SpecContext context) { return(context.Results.OfType <StepResult>().FirstOrDefault(x => x.id == _id)); }
protected virtual Task executeSteps(SpecContext context, IList<ILineExecution> lines, CancellationToken token) { return Task.Factory.StartNew(() => { foreach (var line in lines) { if (shouldStop(context)) { return; } execute(context, line).Wait(StopConditions.TimeoutInSeconds.Seconds()); Logger.LineComplete(context, line); } }, token); }
public SynchronousExecutor(SpecContext context) { _context = context; }
public MatrixSpecVersionsAttribute(IEnumerable <IdentityServiceVersion> supportedVersions) { SpecContext = new VersionsSpecContext <IdentityServiceVersion>(Specification.IdentityService, supportedVersions); }
private void beforeExecution(IExecutionContext execution, SpecContext context) { try { execution.BeforeExecution(context); } catch (Exception e) { context.LogException(Request.Id, e, "BeforeExecution"); } }
public MatrixSpecVersionsAttribute(IEnumerable <PushGatewayVersion> supportedVersions) { SpecContext = new VersionsSpecContext <PushGatewayVersion>(Specification.PushGateway, supportedVersions); }
private Task execute(SpecContext context, ILineExecution line) { var running = line.ExecuteAsync(context, Request.Cancellation); return(Task.WhenAny(running, _timeout)); }
public LinePlanTester() { values = new StepValues(Guid.NewGuid().ToString()); context = SpecContext.ForTesting(); theLineGrammar = Substitute.For <ILineGrammar>(); }
public IStepExecutor BuildExecutor(SpecificationPlan plan, SpecContext context) { return(new InstrumentedExecutor(context, plan, _observer)); }
protected bool shouldStop(SpecContext context) { return Request.IsCancelled || !context.CanContinue() || _timeout.IsCompleted; }
public LineStepGatherer(SpecContext context) { _context = context; }
private IList<ILineExecution> determineLineSteps(SpecContext context) { var gatherer = new LineStepGatherer(context); Request.Plan.AcceptVisitor(gatherer); return gatherer.Lines; }
public IStepExecutor BuildExecutor(SpecificationPlan plan, SpecContext context) { return new SynchronousExecutor(context); }
private Task execute(SpecContext context, ILineExecution line) { var running = Task.Factory.StartNew(() => { line.Execute(context); }, Request.Cancellation); return Task.WhenAny(running, _timeout); }
private static void ShouldSeeNoBudgetedItems(SpecContext context) { var budget = context.Get <BudgetModel>(); Assert.AreEqual(0, budget.Categories.SelectMany(c => c.Items).Count()); }
public MatrixSpecVersionsAttribute(IEnumerable <ServerServerVersion> supportedVersions) { SpecContext = new VersionsSpecContext <ServerServerVersion>(Specification.ServerServer, supportedVersions); }
public LinePlanTester() { values = new StepValues(Guid.NewGuid().ToString()); context = SpecContext.ForTesting(); theLineGrammar = Substitute.For<ILineGrammar>(); }
// If this fails, it's a catastrophic exception public SpecResults Execute(ISystem system, Timings timings) { _timeout = setupTimeout(); using (var execution = createExecutionContext(system, timings)) { if (Request.IsCancelled) { return null; } using (var context = new SpecContext( Request.Specification, timings, Request.Observer, StopConditions, execution)) { beforeExecution(execution, context); var lines = determineLineSteps(context); startDebugListening(context); Logger.Starting(lines); if (lines.Any()) { var stepRunning = executeSteps(context, lines, Request.Cancellation); Task.WaitAny(stepRunning, _timeout); } execution.AfterExecution(context); return buildResults(context, timings); } } }
protected bool shouldStop(SpecContext context) { return(Request.IsCancelled || !context.CanContinue() || _timeout.IsCompleted); }
public MatrixSpecVersionsAttribute(IEnumerable <RoomsVersion> supportedVersions) { SpecContext = new VersionsSpecContext <RoomsVersion>(Specification.Rooms, supportedVersions); }
public IStepExecutor BuildExecutor(SpecificationPlan plan, SpecContext context) { return new InstrumentedExecutor(context, plan, _observer); }
private static void startDebugListening(SpecContext context) { context.Reporting.As<Reporting>().StartDebugListening(); }
public void Execute(SpecContext context) { using (context.Timings.Subject(_type, Subject)) try { _action(context); } catch (Exception ex) { context.LogException(_node.id, ex, Position); } }
public void SetUp() { theContext = new SpecContext(new Specification(), null, new NulloResultObserver(), new StopConditions(), new SimpleExecutionContext()); }
public void SetUp() { theContext = new SpecContext(new Specification(), null, new NulloResultObserver(), new StopConditions(), new SimpleExecutionContext()); }
private SpecResults buildResults(SpecContext context, Timings timings ) { if (Request.IsCancelled) return null; var catastrophic = context?.CatastrophicException; if (catastrophic != null) { throw new StorytellerExecutionException(catastrophic); } Finished = !_timeout.IsCompleted && !Request.IsCancelled; if (_timeout.IsCompleted && !Request.IsCancelled) { var result = timeoutMessage(timings); if (context == null) { var perf = timings.Finish(); return new SpecResults { Counts = new Counts(0, 0, 1, 0), Duration = timings.Duration, Performance = perf.ToArray(), Attempts = Request.Plan.Attempts, Results = new IResultMessage[] { result }, WasAborted = false }; } context.LogResult(result); context.Cancel(); } return context.FinalizeResults(Request.Plan.Attempts); }
public void SetUp() { values = new StepValues(Guid.NewGuid().ToString()); context = SpecContext.ForTesting(); theLineGrammar = MockRepository.GenerateMock <ILineGrammar>(); }
public ExecutionStepGatherer(SpecContext context) { _context = context; }