public static StepDescriptor ToSynchronousStep <TContext>(string name, Action <TContext> step)
 {
     try
     {
         return(new StepDescriptor(ParseName(name), new StepExecutor <TContext>(step).Execute));
     }
     catch (Exception ex)
     {
         return(StepDescriptor.CreateInvalid(ex));
     }
 }
 public static StepDescriptor ToSynchronousStep(Action step)
 {
     try
     {
         var methodInfo = step.GetMethodInfo();
         EnsureNotGenerated(methodInfo);
         return(new StepDescriptor(methodInfo, new StepExecutor(step).Execute));
     }
     catch (Exception ex)
     {
         return(StepDescriptor.CreateInvalid(ex));
     }
 }
Exemple #3
0
        public void It_should_create_descriptor_from_exception()
        {
            var ex         = new Exception("foo");
            var descriptor = StepDescriptor.CreateInvalid(ex);

            Assert.That(descriptor.IsValid, Is.False);
            Assert.That(descriptor.CreationException, Is.SameAs(ex));
            Assert.That(descriptor.RawName, Is.EqualTo("<INVALID STEP>"));
            Assert.That(descriptor.Parameters, Is.Empty);

            var actual = Assert.ThrowsAsync <Exception>(() => descriptor.StepInvocation(null, null));

            Assert.That(actual, Is.SameAs(ex));
        }
Exemple #4
0
        public void Invalid_step_descriptors_should_make_scenario_failing_immediately_without_execution()
        {
            var step1 = TestStep.Create(Step_that_should_not_run);
            var step2 = StepDescriptor.CreateInvalid(new Exception("reason1"));
            var step3 = StepDescriptor.CreateInvalid(new Exception("reason2"));
            var ex    = Assert.Throws <AggregateException>(() => _runner.Test().TestScenario(step1, step2, step3));

            Assert.That(ex.InnerExceptions.Select(x => x.Message).ToArray(),
                        Is.EqualTo(new[] { "Scenario steps initialization failed.", "reason1", "reason2" }));

            var steps = _feature.GetFeatureResult().GetScenarios().Single().GetSteps();

            StepResultExpectation.AssertEqual(steps,
                                              new StepResultExpectation(1, 3, "Step that should not run", ExecutionStatus.NotRun),
                                              new StepResultExpectation(2, 3, "<INVALID STEP>", ExecutionStatus.Failed, "Step 2: reason1"),
                                              new StepResultExpectation(3, 3, "<INVALID STEP>", ExecutionStatus.Failed, "Step 3: reason2"));
        }
        public StepDescriptor ToStep <T>(Expression <T> stepExpression)
        {
            try
            {
                var contextParameter = stepExpression.Parameters[0];
                var methodExpression = GetMethodExpression(stepExpression);

                var arguments = ProcessArguments(methodExpression, contextParameter);

                return(new StepDescriptor(methodExpression.Method, CompileStepAction(methodExpression, contextParameter), arguments)
                {
                    PredefinedStepType = GetStepTypeName(contextParameter)
                });
            }
            catch (Exception ex)
            {
                return(StepDescriptor.CreateInvalid(ex));
            }
        }
Exemple #6
0
        public void Invalid_step_descriptors_should_make_composite_failing_immediately_without_execution()
        {
            TestCompositeStep Composite_step() => new TestCompositeStep(
                TestStep.Create(Step_that_should_not_run),
                StepDescriptor.CreateInvalid(new Exception("reason1")),
                StepDescriptor.CreateInvalid(new Exception("reason2")));

            var ex = Assert.Throws <AggregateException>(() => _runner.Test()
                                                        .TestScenario(
                                                            TestStep.CreateComposite(Composite_step),
                                                            TestStep.Create(Step_that_should_not_run)));

            Assert.That(ex.InnerExceptions.Select(x => x.Message).ToArray(),
                        Is.EqualTo(new[] { "Sub-steps initialization failed.", "reason1", "reason2" }));

            var mainSteps = _feature.GetFeatureResult().GetScenarios().Single().GetSteps().ToArray();

            StepResultExpectation.AssertEqual(mainSteps[0].GetSubSteps(),
                                              new StepResultExpectation("1.", 1, 3, "Step that should not run", ExecutionStatus.NotRun),
                                              new StepResultExpectation("1.", 2, 3, "<INVALID STEP>", ExecutionStatus.Failed, "Step 1.2: reason1"),
                                              new StepResultExpectation("1.", 3, 3, "<INVALID STEP>", ExecutionStatus.Failed, "Step 1.3: reason2"));
            Assert.That(mainSteps[1].Status, Is.EqualTo(ExecutionStatus.NotRun));
        }