Exemple #1
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 SpecFlowConfiguration LoadJson(SpecFlowConfiguration specFlowConfiguration, string jsonContent)
        {
            if (String.IsNullOrWhiteSpace(jsonContent))
            {
                throw new ArgumentNullException(nameof(jsonContent));
            }

            var jsonConfig = JsonSerializer.Deserialize <JsonConfig>(jsonContent);

            ContainerRegistrationCollection containerRegistrationCollection          = 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;
            bool          allowRowTests              = specFlowConfiguration.AllowRowTests;
            bool          allowDebugGeneratedFiles   = specFlowConfiguration.AllowDebugGeneratedFiles;
            bool          markFeaturesParallelizable = specFlowConfiguration.MarkFeaturesParallelizable;

            string[]         skipParallelizableMarkerForTags = specFlowConfiguration.SkipParallelizableMarkerForTags;
            ObsoleteBehavior obsoleteBehavior = specFlowConfiguration.ObsoleteBehavior;

            if (jsonConfig.Language != null)
            {
                if (jsonConfig.Language.Feature.IsNotNullOrWhiteSpace())
                {
                    featureLanguage = CultureInfo.GetCultureInfo(jsonConfig.Language.Feature);
                }
            }

            if (jsonConfig.BindingCulture != null)
            {
                if (jsonConfig.BindingCulture.Name.IsNotNullOrWhiteSpace())
                {
                    bindingCulture = CultureInfo.GetCultureInfo(jsonConfig.BindingCulture.Name);
                }
            }

            if (jsonConfig.Runtime != null)
            {
                missingOrPendingStepsOutcome = jsonConfig.Runtime.MissingOrPendingStepsOutcome;
                stopAtFirstError             = jsonConfig.Runtime.StopAtFirstError;
                obsoleteBehavior             = jsonConfig.Runtime.ObsoleteBehavior;

                if (jsonConfig.Runtime.Dependencies != null)
                {
                    foreach (var runtimeDependency in jsonConfig.Runtime.Dependencies)
                    {
                        containerRegistrationCollection.Add(runtimeDependency.ImplementationType, runtimeDependency.InterfaceType);
                    }
                }
            }

            if (jsonConfig.Generator != null)
            {
                allowDebugGeneratedFiles        = jsonConfig.Generator.AllowDebugGeneratedFiles;
                allowRowTests                   = jsonConfig.Generator.AllowRowTests;
                markFeaturesParallelizable      = jsonConfig.Generator.MarkFeaturesParallelizable;
                skipParallelizableMarkerForTags = jsonConfig.Generator.SkipParallelizableMarkerForTags?.ToArray();
            }

            if (jsonConfig.Trace != null)
            {
                traceSuccessfulSteps        = jsonConfig.Trace.TraceSuccessfulSteps;
                traceTimings                = jsonConfig.Trace.TraceTimings;
                minTracedDuration           = jsonConfig.Trace.MinTracedDuration;
                stepDefinitionSkeletonStyle = jsonConfig.Trace.StepDefinitionSkeletonStyle;
            }

            if (jsonConfig.StepAssemblies != null)
            {
                foreach (var stepAssemblyEntry in jsonConfig.StepAssemblies)
                {
                    additionalStepAssemblies.Add(stepAssemblyEntry.Assembly);
                }
            }

            return(new SpecFlowConfiguration(ConfigSource.Json,
                                             containerRegistrationCollection,
                                             generatorContainerRegistrationCollection,
                                             featureLanguage,
                                             bindingCulture,
                                             stopAtFirstError,
                                             missingOrPendingStepsOutcome,
                                             traceSuccessfulSteps,
                                             traceTimings,
                                             minTracedDuration,
                                             stepDefinitionSkeletonStyle,
                                             additionalStepAssemblies,
                                             allowDebugGeneratedFiles,
                                             allowRowTests,
                                             markFeaturesParallelizable,
                                             skipParallelizableMarkerForTags,
                                             obsoleteBehavior));
        }
        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
                                             ));
        }