public static IObjectContainer CreateContainer(SpecFlowConfigurationHolder configurationHolder, ProjectSettings projectSettings)
        {
            var container = new ObjectContainer();

            RegisterDefaults(container);

            var specFlowConfiguration = container.Resolve<ISpecFlowProjectConfigurationLoader>()
                .LoadConfiguration(configurationHolder);

            if (specFlowConfiguration.GeneratorConfiguration.CustomDependencies != null)
                container.RegisterFromConfiguration(specFlowConfiguration.GeneratorConfiguration.CustomDependencies);

            container.RegisterInstanceAs(specFlowConfiguration);
            container.RegisterInstanceAs(specFlowConfiguration.GeneratorConfiguration);
            container.RegisterInstanceAs(specFlowConfiguration.RuntimeConfiguration);

            var generatorInfo = container.Resolve<IGeneratorInfoProvider>().GetGeneratorInfo();
            container.RegisterInstanceAs(generatorInfo);

            container.RegisterInstanceAs(projectSettings);

            container.RegisterInstanceAs(container.Resolve<CodeDomHelper>(projectSettings.ProjectPlatformSettings.Language));

            if (specFlowConfiguration.GeneratorConfiguration.GeneratorUnitTestProvider != null)
                container.RegisterInstanceAs(container.Resolve<IUnitTestGeneratorProvider>(specFlowConfiguration.GeneratorConfiguration.GeneratorUnitTestProvider));

            return container;
        }
예제 #2
0
        private static IGeneratorPlugin[] LoadPlugins(ObjectContainer container, IGeneratorConfigurationProvider configurationProvider, SpecFlowConfigurationHolder configurationHolder)
        {
            var plugins = container.Resolve<IDictionary<string, IGeneratorPlugin>>().Values.AsEnumerable();

            var pluginLoader = container.Resolve<IGeneratorPluginLoader>();
            plugins = plugins.Concat(configurationProvider.GetPlugins(configurationHolder).Where(pd => (pd.Type & PluginType.Generator) != 0).Select(pd => LoadPlugin(pluginLoader, pd)));

            return plugins.ToArray();
        }
        private static void LoadPlugins(ObjectContainer container, IGeneratorConfigurationProvider configurationProvider, SpecFlowConfigurationHolder configurationHolder, GeneratorPluginEvents generatorPluginEvents)
        {
            // initialize plugins that were registered from code
            foreach (var generatorPlugin in container.Resolve<IDictionary<string, IGeneratorPlugin>>().Values)
            {
                // these plugins cannot have parameters
                generatorPlugin.Initialize(generatorPluginEvents, new GeneratorPluginParameters());
            }

            var pluginLoader = container.Resolve<IGeneratorPluginLoader>();
            foreach (var pluginDescriptor in configurationProvider.GetPlugins(configurationHolder).Where(pd => (pd.Type & PluginType.Generator) != 0))
            {
                LoadPlugin(pluginDescriptor, pluginLoader, generatorPluginEvents);
            }
        }
        public virtual SpecFlowProjectConfiguration LoadConfiguration(SpecFlowConfigurationHolder configurationHolder, IProjectReference projectReference)
        {
            SpecFlowProjectConfiguration configuration = new SpecFlowProjectConfiguration();

            if (configurationHolder != null && configurationHolder.HasConfiguration)
            {
                ConfigurationSectionHandler specFlowConfigSection = ConfigurationSectionHandler.CreateFromXml(configurationHolder.XmlString);
                if (specFlowConfigSection != null)
                {
                    configuration.GeneratorConfiguration.UpdateFromConfigFile(specFlowConfigSection);
                    configuration.RuntimeConfiguration.UpdateFromConfigFile(specFlowConfigSection);
                }
            }
            configuration.GeneratorConfiguration.GeneratorVersion = GetGeneratorVersion(projectReference);
            return configuration;
        }
예제 #5
0
        public void Should_create_custom_generator_when_configured_so()
        {
            var configurationHolder = new SpecFlowConfigurationHolder(string.Format(@"
                <specFlow>
                  <generator>  
                  <dependencies>
                    <register type=""{0}"" as=""{1}""/>
                  </dependencies>
                  </generator>
                </specFlow>",
                typeof(DummyGenerator).AssemblyQualifiedName,
                typeof(ITestGenerator).AssemblyQualifiedName));

            var projectSettings = net35CSProjectSettings;
            projectSettings.ConfigurationHolder = configurationHolder;
            var generator = factory.CreateGenerator(projectSettings);
            generator.Should().BeOfType<DummyGenerator>();
        }
        public IEnumerable<PluginDescriptor> GetPlugins(SpecFlowConfigurationHolder configurationHolder)
        {
            try
            {
                if (configurationHolder != null && configurationHolder.HasConfiguration)
                {
                    ConfigurationSectionHandler section = ConfigurationSectionHandler.CreateFromXml(configurationHolder.XmlString);
                    if (section != null && section.Plugins != null)
                    {
                        return section.Plugins.Select(pce => pce.ToPluginDescriptor());
                    }
                }

                return Enumerable.Empty<PluginDescriptor>();
            }
            catch(Exception ex)
            {
                throw new ConfigurationErrorsException("SpecFlow configuration error", ex);
            }
        }
 public virtual void LoadConfiguration(SpecFlowConfigurationHolder configurationHolder, SpecFlowProjectConfiguration configuration)
 {
     try
     {
         if (configurationHolder != null && configurationHolder.HasConfiguration)
         {
             ConfigurationSectionHandler specFlowConfigSection =
                 ConfigurationSectionHandler.CreateFromXml(configurationHolder.XmlString);
             if (specFlowConfigSection != null)
             {
                 UpdateGeneratorConfiguration(configuration, specFlowConfigSection);
                 UpdateRuntimeConfiguration(configuration, specFlowConfigSection);
             }
         }
     }
     catch(Exception ex)
     {
         throw new ConfigurationErrorsException("SpecFlow configuration error", ex);
     }
 }
        public static IObjectContainer CreateContainer(SpecFlowConfigurationHolder configurationHolder)
        {
            var container = new ObjectContainer();

            RegisterDefaults(container);

            var specFlowConfiguration = container.Resolve<ISpecFlowProjectConfigurationLoader>()
                .LoadConfiguration(configurationHolder);

            if (specFlowConfiguration.GeneratorConfiguration.CustomDependencies != null)
                container.RegisterFromConfiguration(specFlowConfiguration.GeneratorConfiguration.CustomDependencies);

            container.RegisterInstanceAs(specFlowConfiguration);
            container.RegisterInstanceAs(specFlowConfiguration.GeneratorConfiguration);
            container.RegisterInstanceAs(specFlowConfiguration.RuntimeConfiguration);

            var generatorInfo = container.Resolve<IGeneratorInfoProvider>().GetGeneratorInfo();
            container.RegisterInstanceAs(generatorInfo);

            return container;
        }
예제 #9
0
        public void Should_be_able_to_register_further_dependencies_based_on_the_configuration()
        {
            var configurationHolder = GetConfigWithPlugin();

            GeneratorContainerBuilder.DefaultDependencyProvider = new TestDefaultDependencyProvider(new PluginWithCustomization());

            // with default settings, the plugin should not change the header writer
            var container = CreateDefaultContainer(configurationHolder);
            var testHeaderWriter = container.Resolve<ITestHeaderWriter>();
            testHeaderWriter.Should().BeOfType<TestHeaderWriter>();

            // with StopAtFirstError == true, we should get a custom factory
            var specialConfiguratuion = new SpecFlowConfigurationHolder(string.Format(@"<specFlow>
                  <plugins>
                    <add name=""MyCompany.MyPlugin"" />
                  </plugins>
                  <runtime stopAtFirstError=""true"" />
                </specFlow>"));
            container = CreateDefaultContainer(specialConfiguratuion);
            var customHeaderWriter = container.Resolve<ITestHeaderWriter>();
            customHeaderWriter.Should().BeOfType<CustomHeaderWriter>();
        }
        public void Should_create_custom_generator_when_configured_so()
        {
            var configurationHolder = new SpecFlowConfigurationHolder(string.Format(@"
                <specFlow>
                  <generator>
                  <dependencies>
                    <register type=""{0}"" as=""{1}""/>
                  </dependencies>
                  </generator>
                </specFlow>",
                typeof(DummyGenerator).AssemblyQualifiedName,
                typeof(ITestGenerator).AssemblyQualifiedName));

            var projectSettings = new ProjectSettings();
            projectSettings.ConfigurationHolder = configurationHolder;

            using (var remoteFactory = CreateRemoteAppDomainTestGeneratorFactory())
            {
                var generator = remoteFactory.CreateGenerator(projectSettings);
                generator.ToString().ShouldEqual("DummyGenerator"); // since the type is wrapped, we can only check it this way
            }
        }
예제 #11
0
 public ProjectSettings()
 {
     ProjectPlatformSettings = new ProjectPlatformSettings();
     ConfigurationHolder     = new SpecFlowConfigurationHolder();
 }
예제 #12
0
        public void Should_be_able_to_specify_a_plugin_with_parameters()
        {
            var configurationHolder = new SpecFlowConfigurationHolder(string.Format(@"<specFlow>
                  <plugins>
                    <add name=""MyCompany.MyPlugin"" parameters=""foo, bar"" />
                  </plugins>
                </specFlow>"));
            var pluginMock = new Mock<IGeneratorPlugin>();
            GeneratorContainerBuilder.DefaultDependencyProvider = new TestDefaultDependencyProvider(pluginMock.Object);
            CreateDefaultContainer(configurationHolder);

            pluginMock.Verify(p => p.Initialize(It.IsAny<GeneratorPluginEvents>(), It.Is<GeneratorPluginParameters>(pp => pp.Parameters == "foo, bar")));
        }
예제 #13
0
 private IObjectContainer CreateDefaultContainer(SpecFlowConfigurationHolder configurationHolder)
 {
     return GeneratorContainerBuilder.CreateContainer(configurationHolder, new ProjectSettings());
 }
예제 #14
0
 public ProjectSettings()
 {
     ProjectPlatformSettings = new ProjectPlatformSettings();
     ConfigurationHolder = new SpecFlowConfigurationHolder();
 }
 public static SpecFlowProjectConfiguration LoadConfiguration(this IGeneratorConfigurationProvider configurationProvider, SpecFlowConfigurationHolder configurationHolder)
 {
     SpecFlowProjectConfiguration configuration = new SpecFlowProjectConfiguration();
     configurationProvider.LoadConfiguration(configurationHolder, configuration);
     return configuration;
 }