Exemplo n.º 1
0
        public void writes_contextual_logging_into_results()
        {
            theContext.Reporting.ReporterFor <DivReport>().Add("1");
            theContext.Reporting.ReporterFor <ListReport>().Add("2");

            var results = theContext.FinalizeResults(3);

            results.Reporting.Count().ShouldBe(2);
        }
Exemplo n.º 2
0
        public SpecResults Execute(Specification specification)
        {
            var plan    = specification.CreatePlan(_library);
            var timings = new Timings();

            timings.Start(specification);

            IExecutionContext execution = null;

            using (timings.Subject("Context", "Creation"))
            {
                execution = _system.CreateContext();
            }

            var context = new SpecContext(specification, timings, new NulloResultObserver(), StopConditions,
                                          execution);

            context.Reporting.As <Reporting>().StartDebugListening();

            var executor = new SynchronousExecutor(context);

            plan.AcceptVisitor(executor);



            execution.Dispose();
            context.Dispose();

            return(context.FinalizeResults(1));
        }
Exemplo n.º 3
0
        private void finish()
        {
            _execution.AfterExecution(_context);
            _request.SpecExecutionFinished(_context.FinalizeResults(1));


            _context.SafeDispose();
            _execution.SafeDispose();
            _reset.Set();
        }
        //[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 gatherer = new LineStepGatherer(context);
                        plan.AcceptVisitor(gatherer);

                        foreach (var line in gatherer.Lines)
                        {
                            line.Execute(context);
                        }

                        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");
        }
        public void record_and_save_file()
        {
            var data = new ClientData();

            var library = TestingContext.Library;


            var hierarchy = TestingContext.Hierarchy;

            hierarchy.GetAllSpecs().Each(header =>
            {
                Debug.WriteLine("Running " + header.name);

                var spec = XmlReader.ReadFromFile(header.Filename);
                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(header, context.FinalizeResults(1));
                    }
                }
            });



            data.hierarchy = hierarchy;
            data.fixtures  = library.Models.Where(x => x.implementation.Contains("StoryTeller.Samples")).ToArray();

            var json = JsonSerialization.ToIndentedJson(data);

            var clientPath = ".".ToFullPath().ParentDirectory().ParentDirectory().ParentDirectory().ParentDirectory().AppendPath("client");

            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));
        }
        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);
        }
Exemplo n.º 8
0
        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));
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        public SpecResults Execute()
        {
            _reset = new ManualResetEvent(false);

            _thread = new Thread(() =>
            {
                try
                {
                    execute();
                }

#if NET46
                catch (ThreadAbortException)
                {
                    // nothing, it's handled below
                }
#endif
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            })
            {
                Name = "StoryTeller-Test-Execution"
            };

            _thread.Start();

            var timedout = !_reset.WaitOne(_stopConditions.TimeoutInSeconds.Seconds());
            _finished = true;

            if (_wasCancelled)
            {
                return(null);
            }

            if (_catastrophicException != null)
            {
                throw new StorytellerExecutionException(_catastrophicException);
            }
            if (_context?.CatastrophicException != null)
            {
                throw new StorytellerExecutionException(_context.CatastrophicException);
            }



            if (timedout && !_wasCancelled)
            {
                var result = timeoutMessage();

                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));;
        }