コード例 #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));
        }
コード例 #2
0
 public StepArgumentTypeConverter(ITestTracer testTracer, IBindingRegistry bindingRegistry, IContextManager contextManager, IBindingInvoker bindingInvoker)
 {
     this.testTracer      = testTracer;
     this.bindingRegistry = bindingRegistry;
     this.contextManager  = contextManager;
     this.bindingInvoker  = bindingInvoker;
 }
コード例 #3
0
ファイル: TestExecutionEngine.cs プロジェクト: vfert/SpecFlow
 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;
 }
コード例 #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);
        }
コード例 #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);
 }
コード例 #6
0
 public StepArgumentTypeConverter(ITestTracer testTracer, IBindingRegistry bindingRegistry, IContextManager contextManager, IBindingInvoker bindingInvoker)
 {
     this.testTracer = testTracer;
     this.bindingRegistry = bindingRegistry;
     this.contextManager = contextManager;
     this.bindingInvoker = bindingInvoker;
 }
コード例 #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);
 }
コード例 #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;
            }
        }
コード例 #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;
 }
コード例 #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;
 }
コード例 #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);
        }
コード例 #12
0
ファイル: TestRunnerManager.cs プロジェクト: sphinxy/SpecFlow
 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;
 }
コード例 #13
0
ファイル: TestRunner.cs プロジェクト: timjstewart/SpecFlow
        public TestRunner()
        {
            errorProvider = ObjectContainer.ErrorProvider;
            testTracer = ObjectContainer.TestTracer;
            unitTestRuntimeProvider = ObjectContainer.UnitTestRuntimeProvider;
            stepFormatter = ObjectContainer.StepFormatter;
 
            bindingRegistry = ObjectContainer.BindingRegistry;
            stepArgumentTypeConverter = ObjectContainer.StepArgumentTypeConverter;
        }
コード例 #14
0
ファイル: TestRunner.cs プロジェクト: robmaher/SpecFlow
        public TestRunner()
        {
            errorProvider           = ObjectContainer.ErrorProvider;
            testTracer              = ObjectContainer.TestTracer;
            unitTestRuntimeProvider = ObjectContainer.UnitTestRuntimeProvider;
            stepFormatter           = ObjectContainer.StepFormatter;

            bindingRegistry           = ObjectContainer.BindingRegistry;
            stepArgumentTypeConverter = ObjectContainer.StepArgumentTypeConverter;
        }
コード例 #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()
     };
 }
コード例 #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()
     };
 }
コード例 #17
0
ファイル: BindingInvoker.cs プロジェクト: lmaywy/SpecFlow
        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;
            }
        }
コード例 #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);
        }
コード例 #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;
 }
コード例 #20
0
        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));
        }
    }
コード例 #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));
        }
    }
コード例 #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
        }
コード例 #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);
 }
コード例 #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;
 }
コード例 #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;
 }
コード例 #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
        }
コード例 #27
0
 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;
 }
コード例 #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;
        }
コード例 #29
0
ファイル: MethodBinding.cs プロジェクト: JonKruger/SpecFlow
        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;
            }
        }
コード例 #30
0
ファイル: IBindingInvoker.cs プロジェクト: kenlefeb/SpecFlow
 public static void InvokeHook(this IBindingInvoker invoker, IHookBinding hookBinding, IContextManager contextManager, ITestTracer testTracer)
 {
     TimeSpan duration;
     invoker.InvokeBinding(hookBinding, contextManager, null, testTracer, out duration);
 }
コード例 #31
0
 public object InvokeAction(object[] arguments, ITestTracer testTracer)
 {
     TimeSpan duration;
     return InvokeAction(arguments, testTracer, out duration);
 }
コード例 #32
0
        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));
            }
        }
コード例 #33
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;
 }
コード例 #34
0
 public StepArgumentTypeConverter()
 {
     testTracer = ObjectContainer.TestTracer;
     StepTransformations = ObjectContainer.BindingRegistry.StepTransformations ?? new List<StepTransformationBinding>();
 }
コード例 #35
0
 public StackedInternalContextManager(ITestTracer testTracer)
 {
     this.testTracer = testTracer;
 }
コード例 #36
0
 public void Invoke(IContextManager contextManager, ITestTracer testTracer, object[] arguments, out TimeSpan duration)
 {
     InvokeAction(contextManager, arguments, testTracer, out duration);
 }
コード例 #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;
            }
        }
コード例 #38
0
 public StepArgumentTypeConverter(ITestTracer testTracer, IBindingRegistry bindingRegistry, IContextManager contextManager)
 {
     this.testTracer     = testTracer;
     this.contextManager = contextManager;
     StepTransformations = bindingRegistry.StepTransformations ?? new List <StepTransformationBinding>();
 }
コード例 #39
0
 public object InvokeBinding(IBinding binding, IContextManager contextManager, object[] arguments, ITestTracer testTracer, out TimeSpan duration)
 {
     duration = TimeSpan.Zero;
     return(null);
 }
コード例 #40
0
 public object Transform(string value, ITestTracer testTracer)
 {
     var arguments = GetStepTransformationArguments(value);
     return InvokeAction(arguments, testTracer);
 }
コード例 #41
0
ファイル: MethodBinding.cs プロジェクト: JonKruger/SpecFlow
 public object InvokeAction(IContextManager contextManager, object[] arguments, ITestTracer testTracer)
 {
     TimeSpan duration;
     return InvokeAction(contextManager, arguments, testTracer, out duration);
 }
コード例 #42
0
 public RuntimeBindingSourceProcessor(IBindingFactory bindingFactory, IBindingRegistry bindingRegistry, IErrorProvider errorProvider, ITestTracer testTracer) : base(bindingFactory)
 {
     this.bindingRegistry = bindingRegistry;
     this.errorProvider = errorProvider;
     this.testTracer = testTracer;
 }
コード例 #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;
            }
        }
コード例 #44
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;
 }
コード例 #45
0
        public object InvokeAction(IContextManager contextManager, object[] arguments, ITestTracer testTracer)
        {
            TimeSpan duration;

            return(InvokeAction(contextManager, arguments, testTracer, out duration));
        }
コード例 #46
0
 public StepArgumentTypeConverter(ITestTracer testTracer, IBindingRegistry bindingRegistry, IContextManager contextManager)
 {
     this.testTracer = testTracer;
     this.contextManager = contextManager;
     StepTransformations = bindingRegistry.StepTransformations ?? new List<StepTransformationBinding>();
 }
コード例 #47
0
ファイル: HookBinding.cs プロジェクト: richieallen/SpecFlow
 public void Invoke(IContextManager contextManager, ITestTracer testTracer)
 {
     InvokeAction(contextManager, null, testTracer);
 }
コード例 #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;
            }
        }
コード例 #49
0
        public object InvokeAction(object[] arguments, ITestTracer testTracer)
        {
            TimeSpan duration;

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