protected override void SetTestSemantics(PatternTest test, IMethodInfo method)
        {
            base.SetTestSemantics(test, method);

            test.TestInstanceActions.ExecuteTestInstanceChain.Around(
                delegate(PatternTestInstanceState state, Action<PatternTestInstanceState> action)
                {
                    Specify.ThrownBy(delegate { action(state); }).ShouldBeNull();

                    bool failed = false;
                    foreach (ISpecificationConstraint constraint in Specify.GetConstraints())
                    {
                        SpecificationResult result = constraint.Evaluate();
                        if (!result.Success)
                        {
                            failed = true;

                            using (Log.BeginSection(constraint.Description))
                            {
                                Log.Failures.WriteLine(result.Message);

                                if (result.StackTrace != null)
                                    Log.Failures.WriteLine(result.StackTrace);
                            }
                        }
                    }

                    if (failed)
                        throw new SilentTestException(TestOutcome.Failed);
                });
        }
예제 #2
0
        /// <summary>
        /// Creates a test builder.
        /// </summary>
        /// <param name="testModelBuilder">The test model builder.</param>
        /// <param name="test">The underlying test.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="testModelBuilder"/>
        /// or <paramref name="test"/> is null.</exception>
        public DefaultTestBuilder(ITestModelBuilder testModelBuilder, PatternTest test)
            : base(testModelBuilder)
        {
            if (test == null)
                throw new ArgumentNullException("test");

            this.test = test;
        }
예제 #3
0
        /// <summary>
        /// Creates a test builder.
        /// </summary>
        /// <param name="testModelBuilder">The test model builder.</param>
        /// <param name="test">The underlying test.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="testModelBuilder"/>
        /// or <paramref name="test"/> is null.</exception>
        public DefaultTestBuilder(ITestModelBuilder testModelBuilder, PatternTest test)
            : base(testModelBuilder)
        {
            if (test == null)
            {
                throw new ArgumentNullException("test");
            }

            this.test = test;
        }
예제 #4
0
        /// <inheritdoc />
        public ITestBuilder CreateChild(string name, ICodeElementInfo codeElement, ITestDataContextBuilder dataContextBuilder)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (dataContextBuilder == null)
            {
                throw new ArgumentNullException("dataContextBuilder");
            }

            PatternTest childTest = new PatternTest(name, codeElement, dataContextBuilder.ToPatternTestDataContext());

            test.AddChild(childTest);
            return(new DefaultTestBuilder(GetTestModelBuilder(), childTest));
        }
예제 #5
0
        private static IEnumerable <TestPartition> GenerateTestPartitions(IEnumerable <ITestCommand> commands)
        {
            TestPartition currentPartition = null;
            int           currentOrder     = int.MinValue;

            foreach (ITestCommand command in commands)
            {
                if (command.Test.Order != currentOrder)
                {
                    if (currentPartition != null)
                    {
                        yield return(currentPartition);

                        currentPartition = null;
                    }

                    currentOrder = command.Test.Order;
                }

                if (currentPartition == null)
                {
                    currentPartition = new TestPartition();
                }

                PatternTest test = command.Test as PatternTest;
                if (test != null && test.IsParallelizable && command.Dependencies.Count == 0)
                {
                    currentPartition.ParallelCommands.Add(command);
                }
                else
                {
                    currentPartition.SequentialCommands.Add(command);
                }
            }

            if (currentPartition != null)
            {
                yield return(currentPartition);
            }
        }
예제 #6
0
 /// <summary>
 /// Creates a pattern test model.
 /// </summary>
 public PatternTestModel()
 {
     RootTest = new PatternTest(Model.Tree.RootTest.RootTestName, null, new PatternTestDataContext(null));
     RootTest.Kind = TestKinds.Root;
 }
        private static void SetParallelizableRecursively(PatternTest parent)
        {
            foreach (PatternTest child in parent.Children)
            {
                child.IsParallelizable = true;

                SetParallelizableRecursively(child);
            }
        }
예제 #8
0
        /// <inheritdoc />
        public ITestBuilder CreateChild(string name, ICodeElementInfo codeElement, ITestDataContextBuilder dataContextBuilder)
        {
            if (name == null)
                throw new ArgumentNullException("name");
            if (dataContextBuilder == null)
                throw new ArgumentNullException("dataContextBuilder");

            PatternTest childTest = new PatternTest(name, codeElement, dataContextBuilder.ToPatternTestDataContext());
            test.AddChild(childTest);
            return new DefaultTestBuilder(GetTestModelBuilder(), childTest);
        }
예제 #9
0
 /// <summary>
 /// Creates a step.
 /// </summary>
 /// <remarks>
 /// <para>
 /// If <paramref name="isPrimary"/> is true, then all metadata from the <paramref name="test"/>
 /// is copied to the step.  Otherwise the new step will have no metadata initially.
 /// </para>
 /// </remarks>
 /// <param name="test">The test to which the step belongs.</param>
 /// <param name="parent">The parent step, or null if creating a root step.</param>
 /// <param name="name">The step name.</param>
 /// <param name="codeElement">The point of definition of the step, or null if unknown.</param>
 /// <param name="isPrimary">True if the test step is primary.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="name"/>
 /// or <paramref name="test"/> is null.</exception>
 public PatternTestStep(PatternTest test, Model.Tree.TestStep parent, string name, ICodeElementInfo codeElement, bool isPrimary)
     : base(test, parent, name, codeElement, isPrimary)
 {
 }
예제 #10
0
 /// <summary>
 /// Creates a primary step using the same name, code element and metadata
 /// as the test to which it belongs.
 /// </summary>
 /// <param name="test">The test to which the step belongs.</param>
 /// <param name="parent">The parent test step, or null if creating the root step.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="test"/> is null.</exception>
 public PatternTestStep(PatternTest test, Model.Tree.TestStep parent)
     : base(test, parent)
 {
 }
예제 #11
0
 /// <summary>
 /// Creates a pattern test model.
 /// </summary>
 public PatternTestModel()
 {
     RootTest      = new PatternTest(Model.Tree.RootTest.RootTestName, null, new PatternTestDataContext(null));
     RootTest.Kind = TestKinds.Root;
 }
예제 #12
0
 /// <summary>
 /// Creates a step.
 /// </summary>
 /// <remarks>
 /// <para>
 /// If <paramref name="isPrimary"/> is true, then all metadata from the <paramref name="test"/>
 /// is copied to the step.  Otherwise the new step will have no metadata initially.
 /// </para>
 /// </remarks>
 /// <param name="test">The test to which the step belongs.</param>
 /// <param name="parent">The parent step, or null if creating a root step.</param>
 /// <param name="name">The step name.</param>
 /// <param name="codeElement">The point of definition of the step, or null if unknown.</param>
 /// <param name="isPrimary">True if the test step is primary.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="name"/>
 /// or <paramref name="test"/> is null.</exception>
 public PatternTestStep(PatternTest test, Model.Tree.TestStep parent, string name, ICodeElementInfo codeElement, bool isPrimary)
     : base(test, parent, name, codeElement, isPrimary)
 {
 }
예제 #13
0
 /// <summary>
 /// Creates a primary step using the same name, code element and metadata
 /// as the test to which it belongs.
 /// </summary>
 /// <param name="test">The test to which the step belongs.</param>
 /// <param name="parent">The parent test step, or null if creating the root step.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="test"/> is null.</exception>
 public PatternTestStep(PatternTest test, Model.Tree.TestStep parent)
     : base(test, parent)
 {
 }