Beispiel #1
0
 public TestTracer(ITraceListener traceListener, IStepFormatter stepFormatter, IStepDefinitionSkeletonProvider stepDefinitionSkeletonProvider, Configuration.SpecFlowConfiguration specFlowConfiguration)
 {
     this.traceListener = traceListener;
     this.stepFormatter = stepFormatter;
     this.stepDefinitionSkeletonProvider = stepDefinitionSkeletonProvider;
     this.specFlowConfiguration          = specFlowConfiguration;
 }
        private static UnitTestFeatureGeneratorProvider CreateUnitTestFeatureGeneratorProvider()
        {
            Configuration.SpecFlowConfiguration generatorSpecFlowConfiguration = ConfigurationLoader.GetDefault();
            CodeDomHelper            codeDomHelper            = new CodeDomHelper(CodeDomProviderLanguage.CSharp);
            UnitTestFeatureGenerator unitTestFeatureGenerator = new UnitTestFeatureGenerator(
                new NUnit3TestGeneratorProvider(codeDomHelper), codeDomHelper, generatorSpecFlowConfiguration, new DecoratorRegistryStub());

            return(new UnitTestFeatureGeneratorProvider(unitTestFeatureGenerator));
        }
Beispiel #3
0
        protected TestGenerator CreateTestGenerator(ProjectSettings projectSettings)
        {
            Configuration.SpecFlowConfiguration generatorSpecFlowConfiguration = ConfigurationLoader.GetDefault();
            CodeDomHelper            codeDomHelper            = new CodeDomHelper(CodeDomProviderLanguage.CSharp);
            UnitTestFeatureGenerator unitTestFeatureGenerator = new UnitTestFeatureGenerator(new NUnitTestGeneratorProvider(codeDomHelper), codeDomHelper, generatorSpecFlowConfiguration, new DecoratorRegistryStub());

            var generatorRegistryStub = new Mock <IFeatureGeneratorRegistry>();

            generatorRegistryStub.Setup(r => r.CreateGenerator(It.IsAny <SpecFlowDocument>())).Returns(unitTestFeatureGenerator);

            return(new TestGenerator(generatorSpecFlowConfiguration, projectSettings, TestHeaderWriterStub.Object, TestUpToDateCheckerStub.Object, generatorRegistryStub.Object, codeDomHelper));
        }
 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;
 }
Beispiel #5
0
        public static void TransformHtml(XmlSerializer serializer, object report, Type reportType, string outputFilePath, Configuration.SpecFlowConfiguration generatorSpecFlowConfiguration, string xsltFile)
        {
            var xmlOutputWriter = new StringWriter();

            serializer.Serialize(xmlOutputWriter, report);

            XslCompiledTransform xslt = new XslCompiledTransform();
            var         xsltSettings  = new XsltSettings(true, false);
            XmlResolver resourceResolver;

            var reportName = reportType.Name.Replace("Generator", "");

            using (var xsltReader = GetTemplateReader(reportType, reportName, xsltFile))
            {
                resourceResolver = new XmlResourceResolver();
                xslt.Load(xsltReader, xsltSettings, resourceResolver);
            }

            var xmlOutputReader = new XmlTextReader(new StringReader(xmlOutputWriter.ToString()));

            XsltArgumentList argumentList = new XsltArgumentList();

            argumentList.AddParam("feature-language", "", generatorSpecFlowConfiguration.FeatureLanguage.Name);

            using (var xmlTextWriter = new XmlTextWriter(outputFilePath, Encoding.UTF8))
            {
                xslt.Transform(xmlOutputReader, argumentList, xmlTextWriter, resourceResolver);
            }
        }
Beispiel #6
0
 public ErrorProvider(IStepFormatter stepFormatter, Configuration.SpecFlowConfiguration specFlowConfiguration, IUnitTestRuntimeProvider unitTestRuntimeProvider)
 {
     this.stepFormatter           = stepFormatter;
     this.unitTestRuntimeProvider = unitTestRuntimeProvider;
     this.specFlowConfiguration   = specFlowConfiguration;
 }
Beispiel #7
0
 public BindingInvoker(Configuration.SpecFlowConfiguration specFlowConfiguration, IErrorProvider errorProvider, ISynchronousBindingDelegateInvoker synchronousBindingDelegateInvoker)
 {
     this.specFlowConfiguration             = specFlowConfiguration;
     this.errorProvider                     = errorProvider;
     this.synchronousBindingDelegateInvoker = synchronousBindingDelegateInvoker;
 }
 public BindingInvoker(Configuration.SpecFlowConfiguration specFlowConfiguration, IErrorProvider errorProvider)
 {
     this.specFlowConfiguration = specFlowConfiguration;
     this.errorProvider         = errorProvider;
 }
 public void RaiseCustomizeGlobalDependencies(ObjectContainer container, Configuration.SpecFlowConfiguration specFlowConfiguration)
 {
     CustomizeGlobalDependencies?.Invoke(this, new CustomizeGlobalDependenciesEventArgs(container, specFlowConfiguration));
 }
 public void RaiseConfigurationDefaults(Configuration.SpecFlowConfiguration specFlowConfiguration)
 {
     ConfigurationDefaults?.Invoke(this, new ConfigurationDefaultsEventArgs(specFlowConfiguration));
 }
Beispiel #11
0
        public Configuration.SpecFlowConfiguration LoadAppConfig(Configuration.SpecFlowConfiguration specFlowConfiguration, ConfigurationSectionHandler configSection)
        {
            if (configSection == null)
            {
                throw new ArgumentNullException(nameof(configSection));
            }

            ContainerRegistrationCollection runtimeContainerRegistrationCollection   = specFlowConfiguration.CustomDependencies;
            ContainerRegistrationCollection generatorContainerRegistrationCollection = specFlowConfiguration.GeneratorCustomDependencies;
            CultureInfo featureLanguage         = specFlowConfiguration.FeatureLanguage;
            CultureInfo bindingCulture          = specFlowConfiguration.BindingCulture;
            string      runtimeUnitTestProvider = specFlowConfiguration.UnitTestProvider;
            bool        stopAtFirstError        = specFlowConfiguration.StopAtFirstError;
            MissingOrPendingStepsOutcome missingOrPendingStepsOutcome = specFlowConfiguration.MissingOrPendingStepsOutcome;
            bool     traceSuccessfulSteps = specFlowConfiguration.TraceSuccessfulSteps;
            bool     traceTimings         = specFlowConfiguration.TraceTimings;
            TimeSpan minTracedDuration    = specFlowConfiguration.MinTracedDuration;
            StepDefinitionSkeletonStyle stepDefinitionSkeletonStyle = specFlowConfiguration.StepDefinitionSkeletonStyle;
            List <string>           additionalStepAssemblies        = specFlowConfiguration.AdditionalStepAssemblies;
            List <PluginDescriptor> pluginDescriptors = specFlowConfiguration.Plugins;

            bool allowRowTests            = specFlowConfiguration.AllowRowTests;
            bool allowDebugGeneratedFiles = specFlowConfiguration.AllowDebugGeneratedFiles;

            bool markFeaturesParallelizable = specFlowConfiguration.MarkFeaturesParallelizable;

            string[] skipParallelizableMarkerForTags = specFlowConfiguration.SkipParallelizableMarkerForTags;


            if (IsSpecified(configSection.Language))
            {
                featureLanguage = CultureInfo.GetCultureInfo(configSection.Language.Feature);
            }

            if (IsSpecified(configSection.BindingCulture))
            {
                bindingCulture = CultureInfo.GetCultureInfo(configSection.BindingCulture.Name);
            }

            if (IsSpecified(configSection.Runtime))
            {
                stopAtFirstError             = configSection.Runtime.StopAtFirstError;
                missingOrPendingStepsOutcome = configSection.Runtime.MissingOrPendingStepsOutcome;

                if (IsSpecified(configSection.Runtime.Dependencies))
                {
                    runtimeContainerRegistrationCollection = configSection.Runtime.Dependencies;
                }
            }

            if (IsSpecified((configSection.Generator)))
            {
                allowDebugGeneratedFiles   = configSection.Generator.AllowDebugGeneratedFiles;
                allowRowTests              = configSection.Generator.AllowRowTests;
                markFeaturesParallelizable = configSection.Generator.MarkFeaturesParallelizable;

                if (IsSpecified(configSection.Generator.SkipParallelizableMarkerForTags))
                {
                    skipParallelizableMarkerForTags = configSection.Generator.SkipParallelizableMarkerForTags.Select(i => i.Value).ToArray();
                }

                if (IsSpecified(configSection.Generator.Dependencies))
                {
                    generatorContainerRegistrationCollection = configSection.Generator.Dependencies;
                }
            }

            if (IsSpecified(configSection.UnitTestProvider))
            {
                if (!string.IsNullOrEmpty(configSection.UnitTestProvider.RuntimeProvider))
                {
                    //compatibility mode, we simulate a custom dependency
                    runtimeUnitTestProvider = "custom";
                    runtimeContainerRegistrationCollection.Add(configSection.UnitTestProvider.RuntimeProvider, typeof(IUnitTestRuntimeProvider).AssemblyQualifiedName, runtimeUnitTestProvider);
                }
                else
                {
                    runtimeUnitTestProvider = configSection.UnitTestProvider.Name;
                }
            }


            if (IsSpecified(configSection.Trace))
            {
                if (!string.IsNullOrEmpty(configSection.Trace.Listener)) // backwards compatibility
                {
                    runtimeContainerRegistrationCollection.Add(configSection.Trace.Listener, typeof(ITraceListener).AssemblyQualifiedName);
                }

                traceSuccessfulSteps        = configSection.Trace.TraceSuccessfulSteps;
                traceTimings                = configSection.Trace.TraceTimings;
                minTracedDuration           = configSection.Trace.MinTracedDuration;
                stepDefinitionSkeletonStyle = configSection.Trace.StepDefinitionSkeletonStyle;
            }

            foreach (var element in configSection.StepAssemblies)
            {
                var assemblyName = ((StepAssemblyConfigElement)element).Assembly;
                additionalStepAssemblies.Add(assemblyName);
            }

            var pluginNames = pluginDescriptors.Select(m => m.Name).ToList();

            foreach (PluginConfigElement plugin in configSection.Plugins)
            {
                var pluginDescriptor = plugin.ToPluginDescriptor();
                if (pluginNames.Contains(pluginDescriptor.Name))
                {
                    continue;
                }
                pluginDescriptors.Add(pluginDescriptor);
                pluginNames.Add(plugin.Name);
            }

            return(new SpecFlowConfiguration(ConfigSource.AppConfig,
                                             runtimeContainerRegistrationCollection,
                                             generatorContainerRegistrationCollection,
                                             featureLanguage,
                                             bindingCulture,
                                             runtimeUnitTestProvider,
                                             stopAtFirstError,
                                             missingOrPendingStepsOutcome,
                                             traceSuccessfulSteps,
                                             traceTimings,
                                             minTracedDuration,
                                             stepDefinitionSkeletonStyle,
                                             additionalStepAssemblies,
                                             pluginDescriptors,
                                             allowDebugGeneratedFiles,
                                             allowRowTests,
                                             markFeaturesParallelizable,
                                             skipParallelizableMarkerForTags
                                             ));
        }
        public Configuration.SpecFlowConfiguration LoadAppConfig(Configuration.SpecFlowConfiguration specFlowConfiguration, ConfigurationSectionHandler configSection)
        {
            if (configSection == null)
            {
                throw new ArgumentNullException(nameof(configSection));
            }


            ContainerRegistrationCollection runtimeContainerRegistrationCollection   = specFlowConfiguration.CustomDependencies;
            ContainerRegistrationCollection generatorContainerRegistrationCollection = specFlowConfiguration.GeneratorCustomDependencies;
            CultureInfo featureLanguage  = specFlowConfiguration.FeatureLanguage;
            CultureInfo bindingCulture   = specFlowConfiguration.BindingCulture;
            bool        stopAtFirstError = specFlowConfiguration.StopAtFirstError;
            MissingOrPendingStepsOutcome missingOrPendingStepsOutcome = specFlowConfiguration.MissingOrPendingStepsOutcome;
            bool     traceSuccessfulSteps = specFlowConfiguration.TraceSuccessfulSteps;
            bool     traceTimings         = specFlowConfiguration.TraceTimings;
            TimeSpan minTracedDuration    = specFlowConfiguration.MinTracedDuration;
            StepDefinitionSkeletonStyle stepDefinitionSkeletonStyle = specFlowConfiguration.StepDefinitionSkeletonStyle;
            List <string>    additionalStepAssemblies = specFlowConfiguration.AdditionalStepAssemblies;
            ObsoleteBehavior obsoleteBehavior         = specFlowConfiguration.ObsoleteBehavior;

            bool allowRowTests            = specFlowConfiguration.AllowRowTests;
            bool allowDebugGeneratedFiles = specFlowConfiguration.AllowDebugGeneratedFiles;

            bool markFeaturesParallelizable = specFlowConfiguration.MarkFeaturesParallelizable;

            string[] skipParallelizableMarkerForTags = specFlowConfiguration.SkipParallelizableMarkerForTags;
            CucumberMessagesConfiguration cucumberMessagesConfiguration = specFlowConfiguration.CucumberMessagesConfiguration;


            if (IsSpecified(configSection.Language))
            {
                featureLanguage = CultureInfo.GetCultureInfo(configSection.Language.Feature);
            }

            if (IsSpecified(configSection.BindingCulture))
            {
                bindingCulture = CultureInfo.GetCultureInfo(configSection.BindingCulture.Name);
            }

            if (IsSpecified(configSection.Runtime))
            {
                stopAtFirstError             = configSection.Runtime.StopAtFirstError;
                missingOrPendingStepsOutcome = configSection.Runtime.MissingOrPendingStepsOutcome;
                obsoleteBehavior             = configSection.Runtime.ObsoleteBehavior;

                if (IsSpecified(configSection.Runtime.Dependencies))
                {
                    runtimeContainerRegistrationCollection = configSection.Runtime.Dependencies;
                }
            }

            if (IsSpecified((configSection.Generator)))
            {
                allowDebugGeneratedFiles   = configSection.Generator.AllowDebugGeneratedFiles;
                allowRowTests              = configSection.Generator.AllowRowTests;
                markFeaturesParallelizable = configSection.Generator.MarkFeaturesParallelizable;

                if (IsSpecified(configSection.Generator.SkipParallelizableMarkerForTags))
                {
                    skipParallelizableMarkerForTags = configSection.Generator.SkipParallelizableMarkerForTags.Select(i => i.Value).ToArray();
                }

                if (IsSpecified(configSection.Generator.Dependencies))
                {
                    generatorContainerRegistrationCollection = configSection.Generator.Dependencies;
                }
            }

            if (IsSpecified(configSection.Trace))
            {
                if (!string.IsNullOrEmpty(configSection.Trace.Listener)) // backwards compatibility
                {
                    runtimeContainerRegistrationCollection.Add(configSection.Trace.Listener, typeof(ITraceListener).AssemblyQualifiedName);
                }

                traceSuccessfulSteps        = configSection.Trace.TraceSuccessfulSteps;
                traceTimings                = configSection.Trace.TraceTimings;
                minTracedDuration           = configSection.Trace.MinTracedDuration;
                stepDefinitionSkeletonStyle = configSection.Trace.StepDefinitionSkeletonStyle;
            }

            foreach (var element in configSection.StepAssemblies)
            {
                var assemblyName = ((StepAssemblyConfigElement)element).Assembly;
                additionalStepAssemblies.Add(assemblyName);
            }

            if (IsSpecified(configSection.CucumberMessages))
            {
                cucumberMessagesConfiguration.Enabled = configSection.CucumberMessages.Enabled;

                foreach (CucumberMessageSinkElement cucumberMessagesSink in configSection.CucumberMessages.Sinks)
                {
                    cucumberMessagesConfiguration.Sinks.Add(new CucumberMessagesSink(cucumberMessagesSink.Type, cucumberMessagesSink.Path));
                }
            }

            return(new SpecFlowConfiguration(ConfigSource.AppConfig,
                                             runtimeContainerRegistrationCollection,
                                             generatorContainerRegistrationCollection,
                                             featureLanguage,
                                             bindingCulture,
                                             stopAtFirstError,
                                             missingOrPendingStepsOutcome,
                                             traceSuccessfulSteps,
                                             traceTimings,
                                             minTracedDuration,
                                             stepDefinitionSkeletonStyle,
                                             additionalStepAssemblies,
                                             allowDebugGeneratedFiles,
                                             allowRowTests,
                                             markFeaturesParallelizable,
                                             skipParallelizableMarkerForTags,
                                             obsoleteBehavior,
                                             cucumberMessagesConfiguration
                                             ));
        }
 public StepDefinitionRegexCalculator(Configuration.SpecFlowConfiguration specFlowConfiguration)
 {
     this.specFlowConfiguration = specFlowConfiguration;
 }