Пример #1
0
        /// <summary>
        /// Test execution happens in three phases: this is the first phase.
        /// </summary>
        /// <remarks>
        /// Here all contexts and all their examples are run, collecting distinct exceptions
        /// from context itself (befores/ acts/ it/ afters), beforeAll, afterAll.
        /// </remarks>
        public virtual void Run(bool failFast, nspec instance = null, bool recurse = true)
        {
            if (failFast && Parent.HasAnyFailures())
            {
                return;
            }

            var runningInstance = builtInstance ?? instance;

            using (new ConsoleCatcher(output => this.CapturedOutput = output))
            {
                BeforeAllChain.Run(runningInstance);
            }

            // intentionally using for loop to prevent collection was modified error in sample specs
            for (int i = 0; i < runnables.Count; i++)
            {
                if (failFast && HasAnyFailures())
                {
                    return;
                }

                runnables[i].Exercise(runningInstance);
            }

            if (recurse)
            {
                Contexts.Do(c => c.Run(failFast, runningInstance, recurse));
            }

            // TODO wrap this as well in a ConsoleCatcher, not before adding tests about it
            AfterAllChain.Run(runningInstance);
        }
Пример #2
0
        public override void Build(nspec unused = null)
        {
            BeforeAllChain.BuildMethodLevel(classHierarchy);

            BeforeChain.BuildMethodLevel(classHierarchy);

            ActChain.BuildMethodLevel(classHierarchy);

            AfterChain.BuildMethodLevel(classHierarchy);

            AfterAllChain.BuildMethodLevel(classHierarchy);

            try
            {
                var nspec = SpecType.CreateInstanceAs <nspec>();

                nspec.tagsFilter = tagsFilter ?? new Tags();

                base.Build(nspec);
            }
            catch (Exception ex)
            {
                cantCreateInstance = true;

                AddFailingExample(ex);
            }
        }
Пример #3
0
        /// <summary>
        /// Test execution happens in three phases: this is the second phase.
        /// </summary>
        /// <remarks>
        /// Here all contexts and all their examples are traversed again to set proper exception
        /// on examples, giving priority to exceptions from: inherithed beforeAll, beforeAll,
        /// context (befores/ acts/ it/ afters), afterAll, inherithed afterAll.
        /// </remarks>
        public virtual void AssignExceptions(bool recurse = true)
        {
            var beforeAllException = BeforeAllChain.AnyException();
            var afterAllException  = AfterAllChain.AnyException();

            for (int i = 0; i < runnables.Count; i++)
            {
                runnables[i].AssignException(beforeAllException, afterAllException);
            }

            if (recurse)
            {
                Contexts.Do(c => c.AssignExceptions(recurse));
            }
        }
Пример #4
0
        public override string ToString()
        {
            string levelText   = $"L{Level}";
            string exampleText = $"{Examples.Count} exm";
            string contextText = $"{Contexts.Count} ctx";

            var exception =
                BeforeAllChain.AnyException() ??
                BeforeChain.AnyException() ??
                ActChain.AnyException() ??
                AfterChain.AnyException() ??
                AfterAllChain.AnyException();

            string exceptionText = exception?.GetType().Name ?? String.Empty;

            return(String.Join(",", new []
            {
                Name, levelText, exampleText, contextText, exceptionText,
            }));
        }
Пример #5
0
        public Context(string name = "", string tags = null, bool isPending = false, Conventions conventions = null)
        {
            Name           = name.Replace("_", " ");
            Tags           = Domain.Tags.ParseTags(tags);
            this.isPending = isPending;

            Examples = new List <ExampleBase>();
            Contexts = new ContextCollection();

            if (conventions == null)
            {
                conventions = new DefaultConventions().Initialize();
            }

            runnables = new List <RunnableExample>();

            BeforeAllChain = new BeforeAllChain(this, conventions);
            BeforeChain    = new BeforeChain(this, conventions);
            ActChain       = new ActChain(this, conventions);
            AfterChain     = new AfterChain(this, conventions);
            AfterAllChain  = new AfterAllChain(this, conventions);
        }