Esempio n. 1
0
        /// <summary>
        /// Code to be executed whenever a SpecFlow step definition binding is invoked.
        /// </summary>
        /// <param name="binding">The step definition method that is executed.</param>
        /// <param name="contextManager">Container for context objects.</param>
        /// <param name="arguments">Binding arguments passed.</param>
        /// <param name="testTracer">Test tracer.</param>
        /// <param name="duration">The duration of the step definition execution.</param>
        /// <returns>Result of the step definition binding invocation.</returns>
        public override object InvokeBinding(
            IBinding binding,
            IContextManager contextManager,
            object[] arguments,
            ITestTracer testTracer,
            out TimeSpan duration)
        {
            if (binding is StepDefinitionBinding)
            {
                TestProjectStepContext.CurrentStep = $"{contextManager.StepContext.StepInfo.StepDefinitionType} {contextManager.StepContext.StepInfo.Text}";

                if (contextManager.ScenarioContext.ScenarioInfo.Arguments.Count > 0)
                {
                    // If a scenario has arguments, it means it is an example from a Scenario Outline
                    // Similar to what SpecFlow itself does, we append the value from the first argument
                    // to the name of the current scenario to uniquely identify it
                    TestProjectStepContext.CurrentScenario = $"{contextManager.ScenarioContext.ScenarioInfo.Title} [{contextManager.ScenarioContext.ScenarioInfo.Arguments[0]}]";
                }
                else
                {
                    // If a scenario does not have arguments, we consider it to be a 'regular' scenario
                    // In this case, we use the Scenario title as the name of the test
                    TestProjectStepContext.CurrentScenario = contextManager.ScenarioContext.ScenarioInfo.Title;
                }
            }

            return(base.InvokeBinding(binding, contextManager, arguments, testTracer, out duration));
        }
 public StepArgumentTypeConverter(ITestTracer testTracer, IBindingRegistry bindingRegistry, IContextManager contextManager, IBindingInvoker bindingInvoker)
 {
     this.testTracer      = testTracer;
     this.bindingRegistry = bindingRegistry;
     this.contextManager  = contextManager;
     this.bindingInvoker  = bindingInvoker;
 }
Esempio n. 3
0
 public TestExecutionEngine(IStepFormatter stepFormatter, ITestTracer testTracer, IErrorProvider errorProvider, IStepArgumentTypeConverter stepArgumentTypeConverter,
                            SpecFlowConfiguration specFlowConfiguration, IBindingRegistry bindingRegistry, IUnitTestRuntimeProvider unitTestRuntimeProvider, IContextManager contextManager, IStepDefinitionMatchService stepDefinitionMatchService,
                            IDictionary <string, IStepErrorHandler> stepErrorHandlers, IBindingInvoker bindingInvoker, IObsoleteStepHandler obsoleteStepHandler, ICucumberMessageSender cucumberMessageSender, ITestResultFactory testResultFactory,
                            ITestPendingMessageFactory testPendingMessageFactory, ITestUndefinedMessageFactory testUndefinedMessageFactory,
                            ITestObjectResolver testObjectResolver = null, IObjectContainer testThreadContainer = null) //TODO: find a better way to access the container
 {
     _errorProvider           = errorProvider;
     _bindingInvoker          = bindingInvoker;
     _contextManager          = contextManager;
     _unitTestRuntimeProvider = unitTestRuntimeProvider;
     _bindingRegistry         = bindingRegistry;
     _specFlowConfiguration   = specFlowConfiguration;
     _testTracer                  = testTracer;
     _stepFormatter               = stepFormatter;
     _stepArgumentTypeConverter   = stepArgumentTypeConverter;
     _stepErrorHandlers           = stepErrorHandlers?.Values.ToArray();
     _stepDefinitionMatchService  = stepDefinitionMatchService;
     _testObjectResolver          = testObjectResolver;
     TestThreadContainer          = testThreadContainer;
     _obsoleteStepHandler         = obsoleteStepHandler;
     _cucumberMessageSender       = cucumberMessageSender;
     _testResultFactory           = testResultFactory;
     _testPendingMessageFactory   = testPendingMessageFactory;
     _testUndefinedMessageFactory = testUndefinedMessageFactory;
 }
Esempio n. 4
0
        /// <summary>
        /// Resolves the context manager and registers the provided test tracer.
        /// </summary>
        /// <param name="testTracer">The test tracer that will be registered.</param>
        /// <returns>An object that implements <see cref="IContextManager"/>.</returns>
        private IContextManager ResolveContextManager(ITestTracer testTracer)
        {
            var container      = this.CreateTestThreadObjectContainer(testTracer);
            var contextManager = container.Resolve <IContextManager>();

            return(contextManager);
        }
Esempio n. 5
0
 public GhprTestExecutionEngine(
     IStepFormatter stepFormatter,
     ITestTracer testTracer,
     IErrorProvider errorProvider,
     IStepArgumentTypeConverter stepArgumentTypeConverter,
     RuntimeConfiguration runtimeConfiguration,
     IBindingRegistry bindingRegistry,
     IUnitTestRuntimeProvider unitTestRuntimeProvider,
     IStepDefinitionSkeletonProvider stepDefinitionSkeletonProvider,
     IContextManager contextManager,
     IStepDefinitionMatchService stepDefinitionMatchService,
     IDictionary <string, IStepErrorHandler> stepErrorHandlers,
     IBindingInvoker bindingInvoker)
 {
     _engine = new TestExecutionEngine(stepFormatter,
                                       testTracer,
                                       errorProvider,
                                       stepArgumentTypeConverter,
                                       runtimeConfiguration,
                                       bindingRegistry,
                                       unitTestRuntimeProvider,
                                       stepDefinitionSkeletonProvider,
                                       contextManager,
                                       stepDefinitionMatchService,
                                       stepErrorHandlers,
                                       bindingInvoker);
     _reporter = new Reporter(TestingFramework.SpecFlow);
 }
 public StepArgumentTypeConverter(ITestTracer testTracer, IBindingRegistry bindingRegistry, IContextManager contextManager, IBindingInvoker bindingInvoker)
 {
     this.testTracer = testTracer;
     this.bindingRegistry = bindingRegistry;
     this.contextManager = contextManager;
     this.bindingInvoker = bindingInvoker;
 }
Esempio n. 7
0
 public GhprTestExecutionEngine(
     IStepFormatter stepFormatter,
     ITestTracer testTracer,
     IErrorProvider errorProvider,
     IStepArgumentTypeConverter stepArgumentTypeConverter,
     SpecFlowConfiguration specFlowConfiguration,
     IBindingRegistry bindingRegistry,
     IUnitTestRuntimeProvider unitTestRuntimeProvider,
     IStepDefinitionSkeletonProvider stepDefinitionSkeletonProvider,
     IContextManager contextManager,
     IStepDefinitionMatchService stepDefinitionMatchService,
     IDictionary <string, IStepErrorHandler> stepErrorHandlers,
     IBindingInvoker bindingInvoker,
     IObsoleteStepHandler obsoleteStepHandler,
     ITestObjectResolver testObjectResolver,
     IObjectContainer objectContainer)
 {
     _engine = new TestExecutionEngine(stepFormatter,
                                       testTracer,
                                       errorProvider,
                                       stepArgumentTypeConverter,
                                       specFlowConfiguration,
                                       bindingRegistry,
                                       unitTestRuntimeProvider,
                                       stepDefinitionSkeletonProvider,
                                       contextManager,
                                       stepDefinitionMatchService,
                                       stepErrorHandlers,
                                       bindingInvoker,
                                       obsoleteStepHandler,
                                       testObjectResolver,
                                       objectContainer);
 }
Esempio n. 8
0
        public object InvokeAction(object[] arguments, ITestTracer testTracer, out TimeSpan duration)
        {
            try
            {
                object    result;
                Stopwatch stopwatch = new Stopwatch();
                using (CreateCultureInfoScope())
                {
                    stopwatch.Start();
                    result = BindingAction.DynamicInvoke(arguments);
                    stopwatch.Stop();
                }

                if (RuntimeConfiguration.Current.TraceTimings && stopwatch.Elapsed >= RuntimeConfiguration.Current.MinTracedDuration)
                {
                    testTracer.TraceDuration(stopwatch.Elapsed, MethodInfo, arguments);
                }

                duration = stopwatch.Elapsed;
                return(result);
            }
            catch (ArgumentException ex)
            {
                throw errorProvider.GetCallError(MethodInfo, ex);
            }
            catch (TargetInvocationException invEx)
            {
                var ex = invEx.InnerException;
                ex = ex.PreserveStackTrace(errorProvider.GetMethodText(MethodInfo));
                throw ex;
            }
        }
Esempio n. 9
0
 public ContextManager(ITestTracer testTracer, IObjectContainer parentContainer)
 {
     featureContext       = new InternalContextManager <FeatureContext>(testTracer);
     scenarioContext      = new InternalContextManager <ScenarioContext>(testTracer);
     stepContext          = new StackedInternalContextManager <ScenarioStepContext>(testTracer);
     this.parentContainer = parentContainer;
 }
Esempio n. 10
0
 public ContextManager(ITestTracer testTracer, IObjectContainer testThreadContainer, IContainerBuilder containerBuilder)
 {
     this.featureContextManager  = new InternalContextManager <FeatureContext>(testTracer);
     this.scenarioContextManager = new InternalContextManager <ScenarioContext>(testTracer);
     this.stepContextManager     = new StackedInternalContextManager <ScenarioStepContext>(testTracer);
     this.testThreadContainer    = testThreadContainer;
     this.containerBuilder       = containerBuilder;
 }
Esempio n. 11
0
        /// <summary>
        /// Creates a test thread object container and registers the provided test tracer.
        /// </summary>
        /// <param name="testTracer">The test tracer that will be registered.</param>
        /// <returns>An object that implements <see cref="IObjectContainer"/>.</returns>
        private IObjectContainer CreateTestThreadObjectContainer(ITestTracer testTracer)
        {
            IObjectContainer container;

            TestObjectFactories.CreateTestRunner(
                out container,
                objectContainer => objectContainer.RegisterInstanceAs <ITestTracer>(testTracer));
            return(container);
        }
Esempio n. 12
0
 public TestRunnerManager(IObjectContainer globalContainer, IContainerBuilder containerBuilder, Configuration.SpecFlowConfiguration specFlowConfiguration, IRuntimeBindingRegistryBuilder bindingRegistryBuilder,
                          ITestTracer testTracer)
 {
     this.globalContainer        = globalContainer;
     this.containerBuilder       = containerBuilder;
     this.specFlowConfiguration  = specFlowConfiguration;
     this.bindingRegistryBuilder = bindingRegistryBuilder;
     this.testTracer             = testTracer;
 }
Esempio n. 13
0
        public TestRunner()
        {
            errorProvider = ObjectContainer.ErrorProvider;
            testTracer = ObjectContainer.TestTracer;
            unitTestRuntimeProvider = ObjectContainer.UnitTestRuntimeProvider;
            stepFormatter = ObjectContainer.StepFormatter;
 
            bindingRegistry = ObjectContainer.BindingRegistry;
            stepArgumentTypeConverter = ObjectContainer.StepArgumentTypeConverter;
        }
Esempio n. 14
0
        public TestRunner()
        {
            errorProvider           = ObjectContainer.ErrorProvider;
            testTracer              = ObjectContainer.TestTracer;
            unitTestRuntimeProvider = ObjectContainer.UnitTestRuntimeProvider;
            stepFormatter           = ObjectContainer.StepFormatter;

            bindingRegistry           = ObjectContainer.BindingRegistry;
            stepArgumentTypeConverter = ObjectContainer.StepArgumentTypeConverter;
        }
Esempio n. 15
0
 public StepArgumentTypeConverter(ITestTracer testTracer, IBindingRegistry bindingRegistry, IContextManager contextManager, IBindingInvoker bindingInvoker)
 {
     converters = new IStepArgumentTypeConverter[]
     {
         new IndentityConverter(),
         new StepArgumentTransformationConverter(this, testTracer, bindingRegistry, contextManager, bindingInvoker),
         new VerticalTableConverter(this),
         new HorizontalTableConverter(this),
         new SimpleConverter()
     };
 }
Esempio n. 16
0
 public StepArgumentTypeConverter(ITestTracer testTracer, IBindingRegistry bindingRegistry, IContextManager contextManager, IBindingInvoker bindingInvoker)
 {
     converters = new IStepArgumentTypeConverter[]
     {
         new IndentityConverter(),
         new StepArgumentTransformationConverter(this, testTracer, bindingRegistry, contextManager, bindingInvoker),
         new VerticalTableConverter(this),
         new HorizontalTableConverter(this),
         new SimpleConverter()
     };
 }
Esempio n. 17
0
        public object InvokeBinding(IBinding binding, IContextManager contextManager, object[] arguments, ITestTracer testTracer, out TimeSpan duration)
        {
            MethodInfo methodInfo;
            Delegate bindingAction;
            EnsureReflectionInfo(binding, out methodInfo, out bindingAction);

            try
            {
                object result;
                Stopwatch stopwatch = new Stopwatch();
                using (CreateCultureInfoScope(contextManager))
                {
                    stopwatch.Start();
                    object[] invokeArgs = new object[arguments == null ? 1 : arguments.Length + 1];
                    if (arguments != null)
                        Array.Copy(arguments, 0, invokeArgs, 1, arguments.Length);
                    invokeArgs[0] = contextManager;
                    result = bindingAction.DynamicInvoke(invokeArgs);

                    if (result is Task)
                    {
                        ((Task) result).Wait();
                    }

                    stopwatch.Stop();
                }

                if (runtimeConfiguration.TraceTimings && stopwatch.Elapsed >= runtimeConfiguration.MinTracedDuration)
                {
                    testTracer.TraceDuration(stopwatch.Elapsed, binding.Method, arguments);
                }

                duration = stopwatch.Elapsed;
                return result;
            }
            catch (ArgumentException ex)
            {
                throw errorProvider.GetCallError(binding.Method, ex);
            }
            catch (TargetInvocationException invEx)
            {
                var ex = invEx.InnerException;
                ex = ex.PreserveStackTrace(errorProvider.GetMethodText(binding.Method));
                throw ex;
            }
            catch (AggregateException agEx)  //from Task.Wait();
            {
                var ex = agEx.InnerExceptions.First();
                ex = ex.PreserveStackTrace(errorProvider.GetMethodText(binding.Method));
                throw ex;
            }
        }
Esempio n. 18
0
        public override object InvokeBinding(IBinding binding, IContextManager contextManager, object[] arguments,
                                             ITestTracer testTracer, out TimeSpan duration)
        {
            object result = null;

            var stopwatch = new Stopwatch();

            stopwatch.Start();

            try
            {
                result = base.InvokeBinding(binding, contextManager, arguments,
                                            testTracer, out duration);
            }
            catch (Exception ex)
            {
                PreserveStackTrace(ex);

                if (binding is IHookBinding == false)
                {
                    throw;
                }

                var hookBinding = binding as IHookBinding;

                if (hookBinding.HookType == HookType.BeforeScenario ||
                    hookBinding.HookType == HookType.BeforeScenarioBlock ||
                    hookBinding.HookType == HookType.BeforeScenario ||
                    hookBinding.HookType == HookType.BeforeStep ||
                    hookBinding.HookType == HookType.AfterStep ||
                    hookBinding.HookType == HookType.AfterScenario ||
                    hookBinding.HookType == HookType.AfterScenarioBlock)
                {
                    stopwatch.Stop();

                    duration = stopwatch.Elapsed;

                    testTracer.TraceError(ex, duration);
                    SetTestError(contextManager.ScenarioContext, ex);
                }
            }
            finally
            {
                stopwatch.Stop();

                duration = stopwatch.Elapsed;
            }

            return(result);
        }
Esempio n. 19
0
 public TestExecutionEngine(
     IStepFormatter stepFormatter,
     ITestTracer testTracer,
     IErrorProvider errorProvider,
     IStepArgumentTypeConverter stepArgumentTypeConverter,
     SpecFlowConfiguration specFlowConfiguration,
     IBindingRegistry bindingRegistry,
     IUnitTestRuntimeProvider unitTestRuntimeProvider,
     IContextManager contextManager,
     IStepDefinitionMatchService stepDefinitionMatchService,
     IBindingInvoker bindingInvoker,
     IObsoleteStepHandler obsoleteStepHandler,
     ICucumberMessageSender cucumberMessageSender,
     ITestResultFactory testResultFactory,
     ITestPendingMessageFactory testPendingMessageFactory,
     ITestUndefinedMessageFactory testUndefinedMessageFactory,
     ITestRunResultCollector testRunResultCollector,
     IAnalyticsEventProvider analyticsEventProvider,
     IAnalyticsTransmitter analyticsTransmitter,
     ITestRunnerManager testRunnerManager,
     IRuntimePluginTestExecutionLifecycleEventEmitter runtimePluginTestExecutionLifecycleEventEmitter,
     ITestThreadExecutionEventPublisher testThreadExecutionEventPublisher,
     ITestObjectResolver testObjectResolver = null,
     IObjectContainer testThreadContainer   = null) //TODO: find a better way to access the container
 {
     _errorProvider           = errorProvider;
     _bindingInvoker          = bindingInvoker;
     _contextManager          = contextManager;
     _unitTestRuntimeProvider = unitTestRuntimeProvider;
     _bindingRegistry         = bindingRegistry;
     _specFlowConfiguration   = specFlowConfiguration;
     _testTracer                  = testTracer;
     _stepFormatter               = stepFormatter;
     _stepArgumentTypeConverter   = stepArgumentTypeConverter;
     _stepDefinitionMatchService  = stepDefinitionMatchService;
     _testObjectResolver          = testObjectResolver;
     TestThreadContainer          = testThreadContainer;
     _obsoleteStepHandler         = obsoleteStepHandler;
     _cucumberMessageSender       = cucumberMessageSender;
     _testResultFactory           = testResultFactory;
     _testPendingMessageFactory   = testPendingMessageFactory;
     _testUndefinedMessageFactory = testUndefinedMessageFactory;
     _testRunResultCollector      = testRunResultCollector;
     _analyticsEventProvider      = analyticsEventProvider;
     _analyticsTransmitter        = analyticsTransmitter;
     _testRunnerManager           = testRunnerManager;
     _runtimePluginTestExecutionLifecycleEventEmitter = runtimePluginTestExecutionLifecycleEventEmitter;
     _testThreadExecutionEventPublisher = testThreadExecutionEventPublisher;
 }
        public object Transform(IContextManager contextManager, object value, ITestTracer testTracer, IStepArgumentTypeConverter stepArgumentTypeConverter, CultureInfo cultureInfo)
        {
            object[] arguments;
            if (Regex != null && value is string)
            {
                arguments = GetStepTransformationArgumentsFromRegex((string)value, stepArgumentTypeConverter, cultureInfo);
            }
            else
            {
                arguments = new object[] { value }
            };

            return(InvokeAction(contextManager, arguments, testTracer));
        }
    }
Esempio n. 21
0
        public object Transform(object value, ITestTracer testTracer)
        {
            object[] arguments;
            if (Regex != null && value is string)
            {
                arguments = GetStepTransformationArgumentsFromRegex((string)value);
            }
            else
            {
                arguments = new object[] { value }
            };

            return(InvokeAction(arguments, testTracer));
        }
    }
Esempio n. 22
0
        public TestExecutionEngine(IStepFormatter stepFormatter, ITestTracer testTracer, IErrorProvider errorProvider, IStepArgumentTypeConverter stepArgumentTypeConverter, 
            RuntimeConfiguration runtimeConfiguration, IBindingRegistry bindingRegistry, IUnitTestRuntimeProvider unitTestRuntimeProvider, 
            IDictionary<ProgrammingLanguage, IStepDefinitionSkeletonProvider> stepDefinitionSkeletonProviders, IContextManager contextManager)
        {
            this.errorProvider = errorProvider;
            this.contextManager = contextManager;
            this.stepDefinitionSkeletonProviders = stepDefinitionSkeletonProviders;
            this.unitTestRuntimeProvider = unitTestRuntimeProvider;
            this.bindingRegistry = bindingRegistry;
            this.runtimeConfiguration = runtimeConfiguration;
            this.testTracer = testTracer;
            this.stepFormatter = stepFormatter;
            this.stepArgumentTypeConverter = stepArgumentTypeConverter;

            this.currentStepDefinitionSkeletonProvider = stepDefinitionSkeletonProviders[ProgrammingLanguage.CSharp]; // fallback if feature initialization was not proper
        }
Esempio n. 23
0
 public GhprTestExecutionEngine(
     IStepFormatter stepFormatter,
     ITestTracer testTracer,
     IErrorProvider errorProvider,
     IStepArgumentTypeConverter stepArgumentTypeConverter,
     SpecFlowConfiguration specFlowConfiguration,
     IBindingRegistry bindingRegistry,
     IUnitTestRuntimeProvider unitTestRuntimeProvider,
     IContextManager contextManager,
     IStepDefinitionMatchService stepDefinitionMatchService,
     IDictionary <string, IStepErrorHandler> stepErrorHandlers,
     IBindingInvoker bindingInvoker,
     IObsoleteStepHandler obsoleteStepHandler,
     ICucumberMessageSender cucumberMessageSender,
     ITestResultFactory testResultFactory,
     ITestPendingMessageFactory testPendingMessageFactory,
     ITestUndefinedMessageFactory testUndefinedMessageFactory,
     ITestRunResultCollector testRunResultCollector,
     IAnalyticsEventProvider analyticsEventProvider,
     IAnalyticsTransmitter analyticsTransmitter,
     ITestRunnerManager testRunnerManager,
     ITestObjectResolver testObjectResolver = null,
     IObjectContainer testThreadContainer   = null)
 {
     _engine = new TestExecutionEngine(stepFormatter,
                                       testTracer,
                                       errorProvider,
                                       stepArgumentTypeConverter,
                                       specFlowConfiguration,
                                       bindingRegistry,
                                       unitTestRuntimeProvider,
                                       contextManager,
                                       stepDefinitionMatchService,
                                       stepErrorHandlers,
                                       bindingInvoker,
                                       obsoleteStepHandler,
                                       cucumberMessageSender,
                                       testResultFactory,
                                       testPendingMessageFactory,
                                       testUndefinedMessageFactory,
                                       testRunResultCollector,
                                       analyticsEventProvider,
                                       analyticsTransmitter,
                                       testRunnerManager,
                                       testObjectResolver,
                                       testThreadContainer);
 }
Esempio n. 24
0
 public TestExecutionEngine(IStepFormatter stepFormatter, ITestTracer testTracer, IErrorProvider errorProvider, IStepArgumentTypeConverter stepArgumentTypeConverter, 
     RuntimeConfiguration runtimeConfiguration, IBindingRegistry bindingRegistry, IUnitTestRuntimeProvider unitTestRuntimeProvider, 
     IStepDefinitionSkeletonProvider stepDefinitionSkeletonProvider, IContextManager contextManager, IStepDefinitionMatchService stepDefinitionMatchService,
     IDictionary<string, IStepErrorHandler> stepErrorHandlers, IBindingInvoker bindingInvoker)
 {
     this.errorProvider = errorProvider;
     this.bindingInvoker = bindingInvoker;
     this.contextManager = contextManager;
     this.unitTestRuntimeProvider = unitTestRuntimeProvider;
     this.stepDefinitionSkeletonProvider = stepDefinitionSkeletonProvider;
     this.bindingRegistry = bindingRegistry;
     this.runtimeConfiguration = runtimeConfiguration;
     this.testTracer = testTracer;
     this.stepFormatter = stepFormatter;
     this.stepArgumentTypeConverter = stepArgumentTypeConverter;
     this.stepErrorHandlers = stepErrorHandlers == null ? null : stepErrorHandlers.Values.ToArray();
     this.stepDefinitionMatchService = stepDefinitionMatchService;
 }
Esempio n. 25
0
 public TestExecutionEngine(IStepFormatter stepFormatter, ITestTracer testTracer, IErrorProvider errorProvider, IStepArgumentTypeConverter stepArgumentTypeConverter,
                            RuntimeConfiguration runtimeConfiguration, IBindingRegistry bindingRegistry, IUnitTestRuntimeProvider unitTestRuntimeProvider,
                            IStepDefinitionSkeletonProvider stepDefinitionSkeletonProvider, IContextManager contextManager, IStepDefinitionMatchService stepDefinitionMatchService,
                            IDictionary <string, IStepErrorHandler> stepErrorHandlers, IBindingInvoker bindingInvoker)
 {
     this.errorProvider                  = errorProvider;
     this.bindingInvoker                 = bindingInvoker;
     this.contextManager                 = contextManager;
     this.unitTestRuntimeProvider        = unitTestRuntimeProvider;
     this.stepDefinitionSkeletonProvider = stepDefinitionSkeletonProvider;
     this.bindingRegistry                = bindingRegistry;
     this.runtimeConfiguration           = runtimeConfiguration;
     this.testTracer                 = testTracer;
     this.stepFormatter              = stepFormatter;
     this.stepArgumentTypeConverter  = stepArgumentTypeConverter;
     this.stepErrorHandlers          = stepErrorHandlers == null ? null : stepErrorHandlers.Values.ToArray();
     this.stepDefinitionMatchService = stepDefinitionMatchService;
 }
Esempio n. 26
0
        public TestExecutionEngine(IStepFormatter stepFormatter, ITestTracer testTracer, IErrorProvider errorProvider, IStepArgumentTypeConverter stepArgumentTypeConverter,
                                   RuntimeConfiguration runtimeConfiguration, IBindingRegistry bindingRegistry, IUnitTestRuntimeProvider unitTestRuntimeProvider,
                                   IDictionary <ProgrammingLanguage, IStepDefinitionSkeletonProvider> stepDefinitionSkeletonProviders, IContextManager contextManager, IStepDefinitionMatcher stepDefinitionMatcher,
                                   IDictionary <string, IStepErrorHandler> stepErrorHandlers)
        {
            this.errorProvider                   = errorProvider;
            this.stepDefinitionMatcher           = stepDefinitionMatcher;
            this.contextManager                  = contextManager;
            this.stepDefinitionSkeletonProviders = stepDefinitionSkeletonProviders;
            this.unitTestRuntimeProvider         = unitTestRuntimeProvider;
            this.bindingRegistry                 = bindingRegistry;
            this.runtimeConfiguration            = runtimeConfiguration;
            this.testTracer                = testTracer;
            this.stepFormatter             = stepFormatter;
            this.stepArgumentTypeConverter = stepArgumentTypeConverter;
            this.stepErrorHandlers         = stepErrorHandlers == null ? null : stepErrorHandlers.Values.ToArray();

            this.currentStepDefinitionSkeletonProvider = stepDefinitionSkeletonProviders[ProgrammingLanguage.CSharp]; // fallback if feature initialization was not proper
        }
 public TestExecutionEngine(IStepFormatter stepFormatter, ITestTracer testTracer, IErrorProvider errorProvider, IStepArgumentTypeConverter stepArgumentTypeConverter,
                            Configuration.SpecFlowConfiguration specFlowConfiguration, IBindingRegistry bindingRegistry, IUnitTestRuntimeProvider unitTestRuntimeProvider,
                            IStepDefinitionSkeletonProvider stepDefinitionSkeletonProvider, IContextManager contextManager, IStepDefinitionMatchService stepDefinitionMatchService,
                            IDictionary <string, IStepErrorHandler> stepErrorHandlers, IBindingInvoker bindingInvoker, ITestObjectResolver testObjectResolver = null, IObjectContainer testThreadContainer = null) //TODO: find a better way to access the container
 {
     this.errorProvider                  = errorProvider;
     this.bindingInvoker                 = bindingInvoker;
     this.contextManager                 = contextManager;
     this.unitTestRuntimeProvider        = unitTestRuntimeProvider;
     this.stepDefinitionSkeletonProvider = stepDefinitionSkeletonProvider;
     this.bindingRegistry                = bindingRegistry;
     this.specFlowConfiguration          = specFlowConfiguration;
     this.testTracer                 = testTracer;
     this.stepFormatter              = stepFormatter;
     this.stepArgumentTypeConverter  = stepArgumentTypeConverter;
     this.stepErrorHandlers          = stepErrorHandlers == null ? null : stepErrorHandlers.Values.ToArray();
     this.stepDefinitionMatchService = stepDefinitionMatchService;
     this.testObjectResolver         = testObjectResolver;
     this.TestThreadContainer        = testThreadContainer;
 }
Esempio n. 28
0
        public TestExecutionEngine(IStepFormatter stepFormatter, ITestTracer testTracer, IErrorProvider errorProvider, IStepArgumentTypeConverter stepArgumentTypeConverter, 
            RuntimeConfiguration runtimeConfiguration, IBindingRegistry bindingRegistry, IUnitTestRuntimeProvider unitTestRuntimeProvider, 
            IDictionary<ProgrammingLanguage, IStepDefinitionSkeletonProvider> stepDefinitionSkeletonProviders, IContextManager contextManager, IStepDefinitionMatchService stepDefinitionMatchService,
            IDictionary<string, IStepErrorHandler> stepErrorHandlers, IBindingInvoker bindingInvoker, IRuntimeBindingRegistryBuilder bindingRegistryBuilder)
        {
            this.errorProvider = errorProvider;
            //this.stepDefinitionMatcher = stepDefinitionMatcher;
            this.bindingInvoker = bindingInvoker;
            this.bindingRegistryBuilder = bindingRegistryBuilder;
            this.contextManager = contextManager;
            this.stepDefinitionSkeletonProviders = stepDefinitionSkeletonProviders;
            this.unitTestRuntimeProvider = unitTestRuntimeProvider;
            this.bindingRegistry = bindingRegistry;
            this.runtimeConfiguration = runtimeConfiguration;
            this.testTracer = testTracer;
            this.stepFormatter = stepFormatter;
            this.stepArgumentTypeConverter = stepArgumentTypeConverter;
            this.stepErrorHandlers = stepErrorHandlers == null ? null : stepErrorHandlers.Values.ToArray();

            this.currentStepDefinitionSkeletonProvider = stepDefinitionSkeletonProviders[ProgrammingLanguage.CSharp]; // fallback if feature initialization was not proper

            this.stepDefinitionMatchService = stepDefinitionMatchService;
        }
Esempio n. 29
0
        public object InvokeAction(IContextManager contextManager, object[] arguments, ITestTracer testTracer, out TimeSpan duration)
        {
            try
            {
                object result;
                Stopwatch stopwatch = new Stopwatch();
                using (CreateCultureInfoScope(contextManager))
                {
                    stopwatch.Start();
                    object[] invokeArgs = new object[arguments == null ? 1 : arguments.Length + 1];
                    if (arguments != null)
                        Array.Copy(arguments, 0, invokeArgs, 1, arguments.Length);
                    invokeArgs[0] = contextManager;
                    result = BindingAction.DynamicInvoke(invokeArgs);
                    stopwatch.Stop();
                }

                if (runtimeConfiguration.TraceTimings && stopwatch.Elapsed >= runtimeConfiguration.MinTracedDuration)
                {
                    testTracer.TraceDuration(stopwatch.Elapsed, MethodInfo, arguments);
                }

                duration = stopwatch.Elapsed;
                return result;
            }
            catch (ArgumentException ex)
            {
                throw errorProvider.GetCallError(MethodInfo, ex);
            }
            catch (TargetInvocationException invEx)
            {
                var ex = invEx.InnerException;
                ex = ex.PreserveStackTrace(errorProvider.GetMethodText(MethodInfo));
                throw ex;
            }
        }
Esempio n. 30
0
 public static void InvokeHook(this IBindingInvoker invoker, IHookBinding hookBinding, IContextManager contextManager, ITestTracer testTracer)
 {
     TimeSpan duration;
     invoker.InvokeBinding(hookBinding, contextManager, null, testTracer, out duration);
 }
Esempio n. 31
0
 public object InvokeAction(object[] arguments, ITestTracer testTracer)
 {
     TimeSpan duration;
     return InvokeAction(arguments, testTracer, out duration);
 }
        public override object InvokeBinding(IBinding binding, IContextManager contextManager, object[] arguments,
                                             ITestTracer testTracer, out TimeSpan duration)
        {
            var hook = binding as HookBinding;

            // process hook
            if (hook != null)
            {
                var featureContainerId = AllureHelper.GetFeatureContainerId(contextManager.FeatureContext?.FeatureInfo);

                switch (hook.HookType)
                {
                case HookType.BeforeFeature:
                    if (hook.HookOrder == int.MinValue)
                    {
                        // starting point
                        var featureContainer = new TestResultContainer
                        {
                            uuid = AllureHelper.GetFeatureContainerId(contextManager.FeatureContext?.FeatureInfo)
                        };
                        allure.StartTestContainer(featureContainer);

                        contextManager.FeatureContext.Set(new HashSet <TestResultContainer>());
                        contextManager.FeatureContext.Set(new HashSet <TestResult>());

                        return(base.InvokeBinding(binding, contextManager, arguments, testTracer, out duration));
                    }
                    else
                    {
                        try
                        {
                            this.StartFixture(hook, featureContainerId);
                            var result = base.InvokeBinding(binding, contextManager, arguments, testTracer,
                                                            out duration);
                            allure.StopFixture(x => x.status = Status.passed);
                            return(result);
                        }
                        catch (Exception ex)
                        {
                            allure.StopFixture(x => x.status = Status.broken);

                            // if BeforeFeature is failed execution is stopped. We need to create, update, stop and write everything here.

                            // create fake scenario container
                            var scenarioContainer =
                                AllureHelper.StartTestContainer(contextManager.FeatureContext, null);

                            // start fake scenario
                            var scenario = AllureHelper.StartTestCase(scenarioContainer.uuid,
                                                                      contextManager.FeatureContext, null);

                            // update, stop and write
                            allure
                            .StopTestCase(x =>
                            {
                                x.status        = Status.broken;
                                x.statusDetails = AllureHelper.GetStatusDetails(ex);
                            })
                            .WriteTestCase(scenario.uuid)
                            .StopTestContainer(scenarioContainer.uuid)
                            .WriteTestContainer(scenarioContainer.uuid)
                            .StopTestContainer(featureContainerId)
                            .WriteTestContainer(featureContainerId);

                            throw;
                        }
                    }

                case HookType.BeforeStep:
                case HookType.AfterStep:
                {
                    var scenario = AllureHelper.GetCurrentTestCase(contextManager.ScenarioContext);

                    try
                    {
                        return(base.InvokeBinding(binding, contextManager, arguments, testTracer, out duration));
                    }
                    catch (Exception ex)
                    {
                        allure
                        .UpdateTestCase(scenario.uuid,
                                        x =>
                            {
                                x.status        = Status.broken;
                                x.statusDetails = AllureHelper.GetStatusDetails(ex);
                            });
                        throw;
                    }
                }

                case HookType.BeforeScenario:
                case HookType.AfterScenario:
                    if (hook.HookOrder == int.MinValue || hook.HookOrder == int.MaxValue)
                    {
                        return(base.InvokeBinding(binding, contextManager, arguments, testTracer, out duration));
                    }
                    else
                    {
                        var scenarioContainer = AllureHelper.GetCurrentTestConainer(contextManager.ScenarioContext);

                        try
                        {
                            this.StartFixture(hook, scenarioContainer.uuid);
                            var result = base.InvokeBinding(binding, contextManager, arguments, testTracer,
                                                            out duration);
                            allure.StopFixture(x => x.status = Status.passed);
                            return(result);
                        }
                        catch (Exception ex)
                        {
                            allure.StopFixture(x => x.status = Status.broken);

                            // get or add new scenario
                            var scenario = AllureHelper.GetCurrentTestCase(contextManager.ScenarioContext) ??
                                           AllureHelper.StartTestCase(scenarioContainer.uuid,
                                                                      contextManager.FeatureContext, contextManager.ScenarioContext);

                            allure.UpdateTestCase(scenario.uuid,
                                                  x =>
                            {
                                x.status        = Status.broken;
                                x.statusDetails = AllureHelper.GetStatusDetails(ex);
                            });
                            throw;
                        }
                    }

                case HookType.AfterFeature:
                    if (hook.HookOrder == int.MaxValue)
                    // finish point
                    {
                        WriteScenarios(contextManager);
                        allure
                        .StopTestContainer(featureContainerId)
                        .WriteTestContainer(featureContainerId);

                        return(base.InvokeBinding(binding, contextManager, arguments, testTracer, out duration));
                    }
                    else
                    {
                        try
                        {
                            StartFixture(hook, featureContainerId);
                            var result = base.InvokeBinding(binding, contextManager, arguments, testTracer,
                                                            out duration);
                            allure.StopFixture(x => x.status = Status.passed);
                            return(result);
                        }
                        catch (Exception ex)
                        {
                            var scenario = contextManager.FeatureContext.Get <HashSet <TestResult> >().Last();
                            allure
                            .StopFixture(x => x.status = Status.broken)
                            .UpdateTestCase(scenario.uuid,
                                            x =>
                            {
                                x.status        = Status.broken;
                                x.statusDetails = AllureHelper.GetStatusDetails(ex);
                            });

                            WriteScenarios(contextManager);

                            allure
                            .StopTestContainer(featureContainerId)
                            .WriteTestContainer(featureContainerId);

                            throw;
                        }
                    }

                case HookType.BeforeScenarioBlock:
                case HookType.AfterScenarioBlock:
                case HookType.BeforeTestRun:
                case HookType.AfterTestRun:
                default:
                    return(base.InvokeBinding(binding, contextManager, arguments, testTracer, out duration));
                }
            }
            else
            {
                return(base.InvokeBinding(binding, contextManager, arguments, testTracer, out duration));
            }
        }
 /// <summary>
 /// Resolves the context manager and registers the provided test tracer.
 /// </summary>
 /// <param name="testTracer">The test tracer that will be registered.</param>
 /// <returns>An object that implements <see cref="IContextManager"/>.</returns>
 private IContextManager ResolveContextManager(ITestTracer testTracer)
 {
     var container = this.CreateTestThreadObjectContainer(testTracer);
     var contextManager = container.Resolve<IContextManager>();
     return contextManager;
 }
 public StepArgumentTypeConverter()
 {
     testTracer = ObjectContainer.TestTracer;
     StepTransformations = ObjectContainer.BindingRegistry.StepTransformations ?? new List<StepTransformationBinding>();
 }
Esempio n. 35
0
 public StackedInternalContextManager(ITestTracer testTracer)
 {
     this.testTracer = testTracer;
 }
Esempio n. 36
0
 public void Invoke(IContextManager contextManager, ITestTracer testTracer, object[] arguments, out TimeSpan duration)
 {
     InvokeAction(contextManager, arguments, testTracer, out duration);
 }
Esempio n. 37
0
        public virtual object InvokeBinding(IBinding binding, IContextManager contextManager, object[] arguments, ITestTracer testTracer, out TimeSpan duration)
        {
            MethodInfo methodInfo;
            Delegate   bindingAction;

            EnsureReflectionInfo(binding, out methodInfo, out bindingAction);

            try
            {
                object    result;
                Stopwatch stopwatch = new Stopwatch();
                using (CreateCultureInfoScope(contextManager))
                {
                    stopwatch.Start();
                    object[] invokeArgs = new object[arguments == null ? 1 : arguments.Length + 1];
                    if (arguments != null)
                    {
                        Array.Copy(arguments, 0, invokeArgs, 1, arguments.Length);
                    }
                    invokeArgs[0] = contextManager;

                    result = synchronousBindingDelegateInvoker
                             .InvokeDelegateSynchronously(bindingAction, invokeArgs);

                    stopwatch.Stop();
                }

                if (specFlowConfiguration.TraceTimings && stopwatch.Elapsed >= specFlowConfiguration.MinTracedDuration)
                {
                    testTracer.TraceDuration(stopwatch.Elapsed, binding.Method, arguments);
                }

                duration = stopwatch.Elapsed;
                return(result);
            }
            catch (ArgumentException ex)
            {
                throw errorProvider.GetCallError(binding.Method, ex);
            }
            catch (TargetInvocationException invEx)
            {
                var ex = invEx.InnerException;
                ex = ex.PreserveStackTrace(errorProvider.GetMethodText(binding.Method));
                throw ex;
            }
            catch (AggregateException aggregateEx)
            {
                var ex = aggregateEx.InnerExceptions.First();
                ex = ex.PreserveStackTrace(errorProvider.GetMethodText(binding.Method));
                throw ex;
            }
        }
Esempio n. 38
0
 public StepArgumentTypeConverter(ITestTracer testTracer, IBindingRegistry bindingRegistry, IContextManager contextManager)
 {
     this.testTracer     = testTracer;
     this.contextManager = contextManager;
     StepTransformations = bindingRegistry.StepTransformations ?? new List <StepTransformationBinding>();
 }
Esempio n. 39
0
 public object InvokeBinding(IBinding binding, IContextManager contextManager, object[] arguments, ITestTracer testTracer, out TimeSpan duration)
 {
     duration = TimeSpan.Zero;
     return(null);
 }
Esempio n. 40
0
 public object Transform(string value, ITestTracer testTracer)
 {
     var arguments = GetStepTransformationArguments(value);
     return InvokeAction(arguments, testTracer);
 }
Esempio n. 41
0
 public object InvokeAction(IContextManager contextManager, object[] arguments, ITestTracer testTracer)
 {
     TimeSpan duration;
     return InvokeAction(contextManager, arguments, testTracer, out duration);
 }
 public RuntimeBindingSourceProcessor(IBindingFactory bindingFactory, IBindingRegistry bindingRegistry, IErrorProvider errorProvider, ITestTracer testTracer) : base(bindingFactory)
 {
     this.bindingRegistry = bindingRegistry;
     this.errorProvider = errorProvider;
     this.testTracer = testTracer;
 }
Esempio n. 43
0
        public object InvokeAction(IContextManager contextManager, object[] arguments, ITestTracer testTracer, out TimeSpan duration)
        {
            try
            {
                object    result;
                Stopwatch stopwatch = new Stopwatch();
                using (CreateCultureInfoScope(contextManager))
                {
                    stopwatch.Start();
                    object[] invokeArgs = new object[arguments == null ? 1 : arguments.Length + 1];
                    if (arguments != null)
                    {
                        Array.Copy(arguments, 0, invokeArgs, 1, arguments.Length);
                    }
                    invokeArgs[0] = contextManager;
                    result        = BindingAction.DynamicInvoke(invokeArgs);
                    stopwatch.Stop();
                }

                if (runtimeConfiguration.TraceTimings && stopwatch.Elapsed >= runtimeConfiguration.MinTracedDuration)
                {
                    testTracer.TraceDuration(stopwatch.Elapsed, MethodInfo, arguments);
                }

                duration = stopwatch.Elapsed;
                return(result);
            }
            catch (ArgumentException ex)
            {
                throw errorProvider.GetCallError(MethodInfo, ex);
            }
            catch (TargetInvocationException invEx)
            {
                var ex = invEx.InnerException;
                ex = ex.PreserveStackTrace(errorProvider.GetMethodText(MethodInfo));
                throw ex;
            }
        }
 /// <summary>
 /// Creates a test thread object container and registers the provided test tracer.
 /// </summary>
 /// <param name="testTracer">The test tracer that will be registered.</param>
 /// <returns>An object that implements <see cref="IObjectContainer"/>.</returns>
 private IObjectContainer CreateTestThreadObjectContainer(ITestTracer testTracer)
 {
     IObjectContainer container;
     TestObjectFactories.CreateTestRunner(
         out container,
         objectContainer => objectContainer.RegisterInstanceAs<ITestTracer>(testTracer));
     return container;
 }
Esempio n. 45
0
        public object InvokeAction(IContextManager contextManager, object[] arguments, ITestTracer testTracer)
        {
            TimeSpan duration;

            return(InvokeAction(contextManager, arguments, testTracer, out duration));
        }
 public StepArgumentTypeConverter(ITestTracer testTracer, IBindingRegistry bindingRegistry, IContextManager contextManager)
 {
     this.testTracer = testTracer;
     this.contextManager = contextManager;
     StepTransformations = bindingRegistry.StepTransformations ?? new List<StepTransformationBinding>();
 }
Esempio n. 47
0
 public void Invoke(IContextManager contextManager, ITestTracer testTracer)
 {
     InvokeAction(contextManager, null, testTracer);
 }
Esempio n. 48
0
        public object InvokeAction(object[] arguments, ITestTracer testTracer, out TimeSpan duration)
        {
            try
            {
                object result;
                Stopwatch stopwatch = new Stopwatch();
                using (CreateCultureInfoScope())
                {
                    stopwatch.Start();
                    result = BindingAction.DynamicInvoke(arguments);
                    stopwatch.Stop();
                }

                if (RuntimeConfiguration.Current.TraceTimings && stopwatch.Elapsed >= RuntimeConfiguration.Current.MinTracedDuration)
                {
                    testTracer.TraceDuration(stopwatch.Elapsed, MethodInfo, arguments);
                }

                duration = stopwatch.Elapsed;
                return result;
            }
            catch (ArgumentException ex)
            {
                throw errorProvider.GetCallError(MethodInfo, ex);
            }
            catch (TargetInvocationException invEx)
            {
                var ex = invEx.InnerException;
                ex = ex.PreserveStackTrace(errorProvider.GetMethodText(MethodInfo));
                throw ex;
            }
        }
Esempio n. 49
0
        public object InvokeAction(object[] arguments, ITestTracer testTracer)
        {
            TimeSpan duration;

            return(InvokeAction(arguments, testTracer, out duration));
        }