Exemple #1
0
        private RunnableStep ToRunnableStep(StepDescriptor descriptor, int stepIndex, int totalStepsCount, string previousStepTypeName, ExtendableExecutor extendableExecutor, object scenarioContext)
        {
            var stepInfo  = new StepInfo(_metadataProvider.GetStepName(descriptor, previousStepTypeName), stepIndex + 1, totalStepsCount);
            var arguments = descriptor.Parameters.Select(p => new MethodArgument(p, _metadataProvider.GetParameterFormatter(p.ParameterInfo))).ToArray();

            return(new RunnableStep(stepInfo, descriptor.StepInvocation, arguments, _exceptionToStatusMapper, _progressNotifier, extendableExecutor, scenarioContext));
        }
Exemple #2
0
        public void It_should_allow_creating_step_descriptor_from_method()
        {
            var    predefinedStepType = "stepType";
            Action methodRef          = Some_step;

            var rawName    = methodRef.GetMethodInfo().Name;
            var parameters = new[]
            {
                ParameterDescriptor.FromConstant(ParameterInfoHelper.IntParameterInfo, 55),
                ParameterDescriptor.FromConstant(ParameterInfoHelper.IntParameterInfo, 32)
            };

            var descriptor = new StepDescriptor(methodRef.GetMethodInfo(), SomeStepInvocation, parameters)
            {
                PredefinedStepType = predefinedStepType
            };

            Assert.That(descriptor.PredefinedStepType, Is.EqualTo(predefinedStepType));
            Assert.That(descriptor.RawName, Is.EqualTo(rawName));
            Assert.That(descriptor.Parameters, Is.SameAs(parameters));
            Assert.That(descriptor.StepInvocation, Is.SameAs(SomeStepInvocation));
            Assert.That(descriptor.IsValid, Is.True);
            Assert.That(descriptor.CreationException, Is.Null);
            Assert.That(descriptor.IsNameFormattingRequired, Is.True);
        }
        public StepDescriptor GetStepDescriptor()
        {
            StepDescriptor desc = new StepDescriptor();

            desc.StepDescription = "Please insert the \"ISU Plain Calibration Document\" to perform FFC";

            return(desc);
        }
Exemple #4
0
        public StepDescriptor GetStepDescriptor()
        {
            StepDescriptor desc = new StepDescriptor();

            desc.StepDescription = "";

            return(desc);
        }
        public StepDescriptor GetStepDescriptor()
        {
            StepDescriptor desc = new StepDescriptor();

            desc.StepDescription = "Displays Line profile and histogram of the image";

            return(desc);
        }
Exemple #6
0
        public StepDescriptor GetStepDescriptor()
        {
            StepDescriptor desc = new StepDescriptor();

            desc.StepDescription = "Please insert the \"ISU Plain Calibration Document\" to verify light uniformity.";

            return(desc);
        }
Exemple #7
0
        public StepDescriptor GetStepDescriptor()
        {
            StepDescriptor desc = new StepDescriptor();

            desc.StepDescription = "Please insert the \"ISU Calibration Document\" with stripes to check the focus";

            return(desc);
        }
Exemple #8
0
        public void GetStepName_should_properly_convert_predefined_step_type(string inputStepType, string lastStepType, string expectedStepType)
        {
            var metadataProvider = new TestMetadataProvider(new DefaultNameFormatter());

            var descriptor = new StepDescriptor(inputStepType, "some_test_method", (o, a) => Task.FromResult(0));
            var stepName   = metadataProvider.GetStepName(descriptor, lastStepType);

            Assert.That(stepName.StepTypeName.ToString(), Is.EqualTo(expectedStepType));
        }
Exemple #9
0
 private void ValidateDescriptor(StepDescriptor descriptor)
 {
     if (descriptor.IsValid)
     {
         return;
     }
     HandleException(descriptor.CreationException);
     ProcessExceptions(false);
 }
Exemple #10
0
 public RunnableStep(RunnableStepContext stepContext, StepInfo info, StepDescriptor descriptor, MethodArgument[] arguments, IEnumerable <IStepDecorator> stepDecorators)
 {
     _stepContext         = stepContext;
     _invocation          = descriptor.StepInvocation;
     _arguments           = arguments;
     _decoratedStepMethod = DecoratingExecutor.DecorateStep(this, RunStepAsync, stepDecorators);
     _result = new StepResult(info);
     UpdateNameDetails();
     ValidateDescriptor(descriptor);
 }
        public void Should_allow_to_reconfigure_predefined_step_types(string formattedName, string expectedType, string expectedNameFormat)
        {
            var metadataProvider = new TestMetadataProvider(new DefaultNameFormatter(), new StepTypeConfiguration().UpdatePredefinedStepTypes("call", "invoke"));

            var descriptor = new StepDescriptor(formattedName, (o, a) => Task.FromResult(DefaultStepResultDescriptor.Instance));
            var step       = metadataProvider.GetStepName(descriptor, null);

            Assert.That(step.StepTypeName?.ToString(), Is.EqualTo(expectedType), "type");
            Assert.That(step.NameFormat, Is.EqualTo(expectedNameFormat), "name");
        }
        public void GetStepName_should_properly_infer_default_step_type_from_method_name(string methodName, string lastStepType, string expectedStepType, string expectedStepNameFormat)
        {
            var metadataProvider = new TestMetadataProvider(new DefaultNameFormatter());

            var descriptor = new StepDescriptor(methodName, (o, a) => Task.FromResult(DefaultStepResultDescriptor.Instance));
            var stepName   = metadataProvider.GetStepName(descriptor, lastStepType);

            Assert.That(stepName.StepTypeName?.ToString(), Is.EqualTo(expectedStepType));
            Assert.That(stepName.NameFormat, Is.EqualTo(expectedStepNameFormat));
        }
        public void GetStepName_should_not_extract_step_type_if_nothing_is_left_after_it()
        {
            var metadataProvider = new TestMetadataProvider(new DefaultNameFormatter());

            var descriptor = new StepDescriptor("given", (o, a) => Task.FromResult(DefaultStepResultDescriptor.Instance));
            var stepName   = metadataProvider.GetStepName(descriptor, null);

            Assert.That(stepName.StepTypeName, Is.EqualTo(null));
            Assert.That(stepName.NameFormat, Is.EqualTo("given"));
        }
        protected void AssertStep(StepDescriptor step, string expectedName, string expectedPredefinedStepType = null)
        {
            Assert.That(step.RawName, Is.EqualTo(expectedName), nameof(step.RawName));
            Assert.That(step.Parameters, Is.Empty, nameof(step.Parameters));
            Assert.That(step.PredefinedStepType, Is.EqualTo(expectedPredefinedStepType), nameof(step.PredefinedStepType));

            var ex = Assert.Throws <Exception>(() => step.StepInvocation.Invoke(null, null).GetAwaiter().GetResult());

            Assert.That(ex.Message, Is.EqualTo(expectedName));
        }
Exemple #15
0
        public void Should_disable_normalization_if_replacementString_is_empty(string repeatedStepReplacement)
        {
            var metadataProvider = new TestMetadataProvider(new DefaultNameFormatter(), new StepTypeConfiguration().UpdateRepeatedStepReplacement(repeatedStepReplacement));

            var stepTypeName = "given";

            var descriptor = new StepDescriptor(stepTypeName, "some_name", (o, a) => Task.FromResult(0));

            Assert.That(metadataProvider.GetStepName(descriptor, stepTypeName).StepTypeName.ToString(), Is.EqualTo(stepTypeName.ToUpperInvariant()));
        }
Exemple #16
0
        public ResultSets ReadArrayElements(NestedLoop args)
        {
            int    tests = 500;
            var    timer = new Stopwatch();
            Random rand  = new Random();

            // Initialize arrays
            loops    = args.Loop1;
            subLoops = args.Loop2;

            array = new int[subLoops];
            for (int i = 0; i < subLoops; i++)
            {
                array[i] = (int)(rand.NextDouble() * 2);
            }

            randIndexes = new int[loops];
            for (int i = 0; i < loops; i++)
            {
                randIndexes[i] = (int)(rand.NextDouble() * loops);
            }

            long baseTotal       = 0;
            long baseRandomTotal = 0;
            long randomTotal     = 0;
            long orderedTotal    = 0;

            for (int a = 0; a < tests; a++)
            {
                timer.Restart();
                BaseIncrement(loops, subLoops);
                baseTotal += timer.StopNanos();

                timer.Restart();
                BaseRandom(loops, subLoops);
                baseRandomTotal += timer.StopNanos();

                timer.Restart();
                ArrayOrdered(loops, subLoops);
                orderedTotal += timer.StopNanos();

                timer.Restart();
                ArrayRandom(loops, subLoops);
                randomTotal += timer.StopNanos();
            }

            return(ResultSets.builder("Array lookups by type")
                   .StartGroup((string)null)
                   .AddStepResult(StepDescriptor.Of("base (loop>loop>var++)", tests, loops, subLoops), baseTotal)
                   .AddStepResult(StepDescriptor.Of("base random (loop>array[i]>loop>var++)", tests, loops, subLoops), baseRandomTotal)
                   .AddStepResult(StepDescriptor.Of("random (loop>array[i]>loop>array[i])", tests, loops, subLoops), randomTotal)
                   .AddStepResult(StepDescriptor.Of("ordered (loop>loop>array[i])", tests, loops, subLoops), orderedTotal)
                   .EndGroup()
                   .Build());
        }
Exemple #17
0
        public void GetStepName_should_honor_IsNameFormattingRequired_flag(bool flag, string rawName, string expectedName)
        {
            var descriptor =
                new StepDescriptor(rawName, (o, a) => Task.FromResult(DefaultStepResultDescriptor.Instance))
            {
                IsNameFormattingRequired = flag
            };
            var stepName = _metadataProvider.GetStepName(descriptor, null);

            Assert.That(stepName.NameFormat, Is.EqualTo(expectedName));
        }
 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));
     }
 }
Exemple #19
0
        private static string GetStepElements(StepDescriptor step)
        {
            var s = String.Join(Environment.NewLine, step.Properties
                                .Where(p => p.CanBeElement)
                                .Select(p => String.Format(PROPERTYELEMENTTEMPLATE
                                                           , p.Name
                                                           , GetDataType(p.DataType)
                                                           , String.IsNullOrEmpty(p.Documentation) ? "" : String.Format(ELEMENTANNOTATION, p.Documentation)
                                                           )));

            return(s);
        }
        private static string GetStepElements(StepDescriptor step)
        {
            var s = String.Join(Environment.NewLine, step.Properties
                                .Where(p => p.CanBeElement)
                                .Select(p => String.Format(PropertyElementTemplate
                                                           , p.Name
                                                           , GetDataType(p.DataType)
                                                           , String.IsNullOrEmpty(p.Documentation) ? "" : String.Format(ElementAnnotation, p.Documentation)
                                                           )));

            return(s);
        }
        private static string GetStepAttributes(StepDescriptor step)
        {
            var s = String.Join(Environment.NewLine, step.Properties
                                .Where(p => p.CanBeAttribute)
                                .Select(p => String.Format(PropertyAttribuTetemplate
                                                           , PackageManager.ToCamelCase(p.Name)
                                                           , GetDataType(p.DataType)
                                                           , String.IsNullOrEmpty(p.Documentation) ? "" : String.Format(AttributeAnnotation, p.Documentation)
                                                           )));

            return(s);
        }
Exemple #22
0
        private static string GetStepAttributes(StepDescriptor step)
        {
            var s = String.Join(Environment.NewLine, step.Properties
                                .Where(p => p.CanBeAttribute)
                                .Select(p => String.Format(PROPERTYATTRIBUTETEMPLATE
                                                           , PackageManager.ToCamelCase(p.Name)
                                                           , GetDataType(p.DataType)
                                                           , String.IsNullOrEmpty(p.Documentation) ? "" : String.Format(ATTRIBUTEANNOTATION, p.Documentation)
                                                           )));

            return(s);
        }
 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));
     }
 }
        public void GetStepName_should_capture_name_from_step_descriptor_but_leave_parameters_unknown()
        {
            var descriptor = new StepDescriptor(
                "given",
                nameof(Feature_type.Some_step_with_argument),
                (o, a) => Task.FromResult(0),
                ParameterDescriptor.FromConstant(ParameterInfoHelper.GetMethodParameter <int>(new Feature_type().Some_step_with_argument), 5));

            var stepName = _metadataProvider.GetStepName(descriptor, null);

            Assert.That(stepName.StepTypeName.ToString(), Is.EqualTo("GIVEN"));
            Assert.That(stepName.NameFormat, Is.EqualTo("Some step with argument \"{0}\""));
            Assert.That(stepName.ToString(), Is.EqualTo("GIVEN Some step with argument \"<?>\""));
        }
Exemple #25
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 #26
0
        private RunnableStep ToRunnableStep(StepDescriptor descriptor, int stepIndex, int totalStepsCount, string previousStepTypeName, DecoratingExecutor decoratingExecutor, object scenarioContext, string groupPrefix)
        {
            var stepInfo        = new StepInfo(_metadataProvider.GetStepName(descriptor, previousStepTypeName), stepIndex + 1, totalStepsCount, groupPrefix);
            var arguments       = descriptor.Parameters.Select(p => new MethodArgument(p, _metadataProvider.GetParameterFormatter(p.ParameterInfo))).ToArray();
            var stepGroupPrefix = $"{stepInfo.GroupPrefix}{stepInfo.Number}.";

            return(new RunnableStep(
                       stepInfo,
                       new InvocationResultTransformer(this, descriptor.StepInvocation, decoratingExecutor, stepGroupPrefix).InvokeAsync,
                       arguments,
                       _exceptionProcessor,
                       _progressNotifier,
                       decoratingExecutor,
                       scenarioContext,
                       _metadataProvider.GetStepDecorators(descriptor)));
        }
        public void It_should_allow_creating_step_descriptor()
        {
            var predefinedStepType = "stepType";
            var rawName            = "rawName";
            var parameters         = new[]
            {
                ParameterDescriptor.FromConstant(ParameterInfoHelper.IntParameterInfo, 55),
                ParameterDescriptor.FromConstant(ParameterInfoHelper.IntParameterInfo, 32)
            };

            var descriptor = new StepDescriptor(predefinedStepType, rawName, SomeStepInvocation, parameters);

            Assert.That(descriptor.PredefinedStepType, Is.EqualTo(predefinedStepType));
            Assert.That(descriptor.RawName, Is.EqualTo(rawName));
            Assert.That(descriptor.Parameters, Is.SameAs(parameters));
            Assert.That(descriptor.StepInvocation, Is.SameAs(SomeStepInvocation));
        }
Exemple #28
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));
            }
        }
        private static IStepNameInfo CreateStepNameInfo(string type, string name, int args = 0)
        {
            Task <IStepResultDescriptor> Invocation(object ctx, object[] a) => Task.FromResult(DefaultStepResultDescriptor.Instance);

            void SomeFunction(int x)
            {
            }

            Action <int> fn    = SomeFunction;
            var          param = fn.GetMethodInfo().GetParameters().Single();


            var descriptor = new StepDescriptor(name, Invocation,
                                                Enumerable.Range(0, args).Select(a => ParameterDescriptor.FromConstant(param, a)).ToArray())
            {
                PredefinedStepType = type
            };

            return(new TestMetadataProvider().GetStepName(descriptor, ""));
        }