public void CustomizeDependencies(object sender, CustomizeDependenciesEventArgs eventArgs)
        {
            // Resolve relevant instances to be used for custom IFeatureGenerator implementation
            var objectContainer   = eventArgs.ObjectContainer;
            var language          = objectContainer.Resolve <ProjectSettings>().ProjectPlatformSettings.Language;
            var codeDomHelper     = objectContainer.Resolve <CodeDomHelper>(language);
            var decoratorRegistry = objectContainer.Resolve <DecoratorRegistry>();

            // Resolve specflow configuration to confirm custom variant key, use default if none provided
            var specflowConfiguration = objectContainer.Resolve <SpecFlowConfiguration>();
            var configParam           = specflowConfiguration.Plugins.FirstOrDefault(a => a.Name == GetType().Namespace.Replace(".SpecFlowPlugin", string.Empty))?.Parameters;

            _variantKey = !string.IsNullOrEmpty(configParam) ? configParam : _variantKey;

            // Create custom unit test provider based on user defined config value
            var generatorProvider = GetGeneratorProviderFromConfig(codeDomHelper, specflowConfiguration.UnitTestProvider);

            // Create generator instance to be registered and replace original
            var customFeatureGenerator         = new FeatureGeneratorExtended(generatorProvider, codeDomHelper, specflowConfiguration, decoratorRegistry, _variantKey);
            var customFeatureGeneratorProvider = new FeatureGeneratorProviderExtended(customFeatureGenerator);

            // Register dependencies
            objectContainer.RegisterInstanceAs(generatorProvider);
            objectContainer.RegisterInstanceAs(customFeatureGenerator);
            objectContainer.RegisterInstanceAs <IFeatureGeneratorProvider>(customFeatureGeneratorProvider, "default");
        }
Beispiel #2
0
        public void CustomizeDependencies(object sender, CustomizeDependenciesEventArgs eventArgs)
        {
            // Resolve relevant instances to be used for custom IFeatureGenerator implementation
            var objectContainer   = eventArgs.ObjectContainer;
            var language          = objectContainer.Resolve <ProjectSettings>().ProjectPlatformSettings.Language;
            var codeDomHelper     = objectContainer.Resolve <CodeDomHelper>(language);
            var decoratorRegistry = objectContainer.Resolve <DecoratorRegistry>();

            // Get variant key from config
            var projSettings = eventArgs.ObjectContainer.Resolve <ProjectSettings>();

            if (projSettings.ConfigurationHolder.HasConfiguration && projSettings.ConfigurationHolder.ConfigSource == ConfigSource.Json)
            {
                // TODO: use this once dependency is resolved ->  _config = JsonConvert.DeserializeObject<Configuration>(projSettings.ConfigurationHolder.Content);
                var vk = GetJsonValueByRegex(projSettings.ConfigurationHolder.Content, "variantkey");
                _variantKey = !string.IsNullOrEmpty(vk) ? vk : _variantKey;
            }
            else if (projSettings.ConfigurationHolder.HasConfiguration && projSettings.ConfigurationHolder.ConfigSource == ConfigSource.AppConfig)
            {
                var appconfig = projSettings.ConfigurationHolder.Content;
                var vk        = GetGeneratorPath(appconfig);
                _variantKey = !string.IsNullOrEmpty(vk) ? vk : _variantKey;
            }

            // Create custom unit test provider based on user defined config value
            //TODO: use this once dependency is resolved -> var generatorProvider = GetGeneratorProviderFromConfig(codeDomHelper, utp ?? _config?.PluginParameters?.UnitTestProvider ?? "");
            // https://github.com/dotnet/sdk/issues/9594

            if (string.IsNullOrEmpty(utp))
            {
                var c = objectContainer.Resolve <UnitTestProviderConfiguration>();
                utp = c.UnitTestProvider;

                if (string.IsNullOrEmpty(utp))
                {
                    throw new Exception("Unit test provider not detected, please install as a nuget package described here: https://github.com/SpecFlowOSS/SpecFlow/wiki/SpecFlow-and-.NET-Core");
                }
            }

            //TODO: remove after proving => var generatorProvider = GetGeneratorProviderFromConfig(codeDomHelper, utp ?? GetJsonValueByRegex(projSettings.ConfigurationHolder.Content, "unittestprovider"));
            var generatorProvider     = GetGeneratorProviderFromConfig(codeDomHelper, utp);
            var specflowConfiguration = eventArgs.SpecFlowProjectConfiguration.SpecFlowConfiguration;

            // Create generator instance to be registered and replace original
            var customFeatureGenerator         = new FeatureGeneratorExtended(generatorProvider, codeDomHelper, specflowConfiguration, decoratorRegistry, _variantKey);
            var customFeatureGeneratorProvider = new FeatureGeneratorProviderExtended(customFeatureGenerator);

            // Register dependencies
            objectContainer.RegisterInstanceAs(generatorProvider);
            objectContainer.RegisterInstanceAs(customFeatureGenerator);
            objectContainer.RegisterInstanceAs <IFeatureGeneratorProvider>(customFeatureGeneratorProvider, "default");
        }