Exemplo n.º 1
0
        private void FireEvents(BindingEvent bindingEvent)
        {
            var stepContext = contextManager.GetStepContext();

            foreach (IHookBinding eventBinding in bindingRegistry.GetEvents(bindingEvent))
            {
                int scopeMatches;
                if (eventBinding.IsScoped && !eventBinding.BindingScope.Match(stepContext, out scopeMatches))
                {
                    continue;
                }

                eventBinding.Invoke(contextManager, testTracer);
            }
        }
Exemplo n.º 2
0
        private void FireEvents(HookType bindingEvent)
        {
            var stepContext = contextManager.GetStepContext();

            foreach (IHookBinding eventBinding in GetOrderedHooks(bindingEvent))
            {
                int scopeMatches;
                if (eventBinding.IsScoped && !eventBinding.BindingScope.Match(stepContext, out scopeMatches))
                {
                    continue;
                }

                bindingInvoker.InvokeHook(eventBinding, contextManager, testTracer);
            }
        }
Exemplo n.º 3
0
        private void FireEvents(HookType hookType)
        {
            _testThreadExecutionEventPublisher.PublishEvent(new HookStartedEvent(hookType, FeatureContext, ScenarioContext, _contextManager.StepContext));
            var stepContext = _contextManager.GetStepContext();

            var matchingHooks = _bindingRegistry.GetHooks(hookType)
                                .Where(hookBinding => !hookBinding.IsScoped ||
                                       hookBinding.BindingScope.Match(stepContext, out int _));

            //HACK: The InvokeHook requires an IHookBinding that contains the scope as well
            // if multiple scopes match the same method, we take the first one.
            // The InvokeHook uses only the Method anyway...
            // The only problem could be if the same method is decorated with hook attributes using different order,
            // but in this case it is anyway impossible to tell the right ordering.
            var       uniqueMatchingHooks = matchingHooks.GroupBy(hookBinding => hookBinding.Method).Select(g => g.First());
            Exception hookException       = null;

            try
            {
                //Note: if a (user-)hook throws an exception the subsequent hooks of the same type are not executed
                foreach (var hookBinding in uniqueMatchingHooks.OrderBy(x => x.HookOrder))
                {
                    InvokeHook(_bindingInvoker, hookBinding, hookType);
                }
            }
            catch (Exception hookExceptionCaught)
            {
                hookException = hookExceptionCaught;
                SetHookError(hookType, hookException);
            }

            //Note: plugin-hooks are still executed even if a user-hook failed with an exception
            //A plugin-hook should not throw an exception under normal circumstances, exceptions are not handled/caught here
            FireRuntimePluginTestExecutionLifecycleEvents(hookType);

            _testThreadExecutionEventPublisher.PublishEvent(new HookFinishedEvent(hookType, FeatureContext, ScenarioContext, _contextManager.StepContext, hookException));

            //Note: the (user-)hook exception (if any) will be thrown after the plugin hooks executed to fail the test with the right error
            if (hookException != null)
            {
                throw hookException;
            }
        }
Exemplo n.º 4
0
        private void FireEvents(HookType hookType)
        {
            var stepContext = _contextManager.GetStepContext();

            var matchingHooks = _bindingRegistry.GetHooks(hookType)
                                .Where(hookBinding => !hookBinding.IsScoped ||
                                       hookBinding.BindingScope.Match(stepContext, out int _));

            //HACK: The InvokeHook requires an IHookBinding that contains the scope as well
            // if multiple scopes mathching for the same method, we take the first one.
            // The InvokeHook uses only the Method anyway...
            // The only problem could be if the same method is decorated with hook attributes using different order,
            // but in this case it is anyway impossible to tell the right ordering.
            var uniqueMatchingHooks = matchingHooks.GroupBy(hookBinding => hookBinding.Method).Select(g => g.First());

            foreach (var hookBinding in uniqueMatchingHooks.OrderBy(x => x.HookOrder))
            {
                InvokeHook(_bindingInvoker, hookBinding, hookType);
            }
        }