예제 #1
0
        public void Should_be_able_to_register_further_dependencies_based_on_the_configuration()
        {
            StringConfigProvider configurationHolder = GetConfigWithPlugin();

            ContainerBuilder.DefaultDependencyProvider = new TestDefaultDependencyProvider(new PluginWithCustomTestRunnerFactoryWhenStopAtFirstErrorIsTrue());

            // with default unit test provider, the plugin should not change the default factory
            var container         = TestObjectFactories.CreateDefaultGlobalContainer(configurationHolder);
            var testRunnerFactory = container.Resolve <ITestRunnerManager>();

            testRunnerFactory.Should().BeOfType <TestRunnerManager>();

            // with StopAtFirstError == true, we should get a custom factory
            var specialConfiguratuion = new StringConfigProvider(string.Format(@"<?xml version=""1.0"" encoding=""utf-8"" ?>
              <configuration>
                <specFlow>
                  <plugins>
                    <add name=""MyCompany.MyPlugin"" />
                  </plugins>
                  <runtime stopAtFirstError=""true"" />
                </specFlow>
              </configuration>"));

            container = TestObjectFactories.CreateDefaultGlobalContainer(specialConfiguratuion);
            var customTestRunnerFactory = container.Resolve <ITestRunnerFactory>();

            customTestRunnerFactory.Should().BeOfType <CustomTestRunnerFactory>();
        }
예제 #2
0
        public void Should_be_able_to_specify_a_plugin()
        {
            StringConfigProvider configurationHolder = GetConfigWithPlugin();

            ContainerBuilder.DefaultDependencyProvider = new TestDefaultDependencyProvider(new Mock <IRuntimePlugin>().Object);
            TestObjectFactories.CreateDefaultGlobalContainer(configurationHolder);
        }
예제 #3
0
        public void Test_runner_dependencies_from_a_plugin_are_not_in_the_global_container()
        {
            StringConfigProvider configurationHolder = GetConfigWithPlugin();

            ContainerBuilder.DefaultDependencyProvider = new TestDefaultDependencyProvider(new PluginWithCustomTestThreadDependencies(oc => oc.RegisterTypeAs <CustomDependency, ICustomDependency>()));
            var container = TestObjectFactories.CreateDefaultGlobalContainer(configurationHolder);

            Assert.Throws <ObjectContainerException>(() => container.Resolve <ICustomDependency>(), "Interface cannot be resolved");
        }
예제 #4
0
        public void Should_be_able_to_change_default_configuration_from_a_plugin()
        {
            StringConfigProvider configurationHolder = GetConfigWithPlugin();

            ContainerBuilder.DefaultDependencyProvider = new TestDefaultDependencyProvider(new PluginWithCustomConfiguration(conf => conf.StopAtFirstError = true));
            var container            = TestObjectFactories.CreateDefaultGlobalContainer(configurationHolder);
            var runtimeConfiguration = container.Resolve <SpecFlowConfiguration>();

            runtimeConfiguration.StopAtFirstError.Should().BeTrue();
        }
예제 #5
0
        public void Should_be_able_to_register_dependencies_from_a_plugin()
        {
            StringConfigProvider configurationHolder = GetConfigWithPlugin();

            ContainerBuilder.DefaultDependencyProvider = new TestDefaultDependencyProvider(new PluginWithCustomDependency());
            var container        = TestObjectFactories.CreateDefaultGlobalContainer(configurationHolder);
            var customDependency = container.Resolve <ICustomDependency>();

            customDependency.Should().BeOfType(typeof(CustomDependency));
        }
        public void Should_be_able_to_specify_custom_unit_test_provider_in_config_compatible_way()
        {
            var configurationHolder = new StringConfigProvider(string.Format(@"<?xml version=""1.0"" encoding=""utf-8"" ?>
              <configuration>
                <specFlow>
                  <unitTestProvider name=""myprovider"" runtimeProvider=""{0}"" />
                </specFlow>
              </configuration>",
                                                                             typeof(CustomUnitTestProvider).AssemblyQualifiedName));

            var container        = TestObjectFactories.CreateDefaultGlobalContainer(configurationHolder);
            var unitTestProvider = container.Resolve <IUnitTestRuntimeProvider>();

            unitTestProvider.Should().BeOfType(typeof(CustomUnitTestProvider));
        }
예제 #7
0
        public void Should_be_able_to_specify_a_plugin_with_parameters()
        {
            StringConfigProvider configurationHolder = new StringConfigProvider(string.Format(@"<?xml version=""1.0"" encoding=""utf-8"" ?>
              <configuration>
                <specFlow>
                  <plugins>
                    <add name=""MyCompany.MyPlugin"" parameters=""foo, bar"" />
                  </plugins>
                </specFlow>
              </configuration>"));
            var pluginMock = new Mock <IRuntimePlugin>();

            ContainerBuilder.DefaultDependencyProvider = new TestDefaultDependencyProvider(pluginMock.Object);
            TestObjectFactories.CreateDefaultGlobalContainer(configurationHolder);

            pluginMock.Verify(p => p.Initialize(It.IsAny <RuntimePluginEvents>(), It.Is <RuntimePluginParameters>(pp => pp.Parameters == "foo, bar")));
        }
        public void Should_be_able_to_customize_dependencies_from_config()
        {
            var configurationHolder = new StringConfigProvider(string.Format(@"<?xml version=""1.0"" encoding=""utf-8"" ?>
              <configuration>
                <specFlow>
                  <runtime>  
                    <dependencies>
                      <register type=""{0}"" as=""{1}""/>
                    </dependencies>
                  </runtime>
                </specFlow>
              </configuration>",
                                                                             typeof(DummyTestRunnerFactory).AssemblyQualifiedName,
                                                                             typeof(ITestRunnerFactory).AssemblyQualifiedName));

            var container         = TestObjectFactories.CreateDefaultGlobalContainer(configurationHolder);
            var testRunnerFactory = container.Resolve <ITestRunnerFactory>();

            testRunnerFactory.Should().BeOfType(typeof(DummyTestRunnerFactory));
        }
예제 #9
0
        public void Should_be_able_to_customize_dependencies_from_json_config()
        {
            var expectedInterface      = typeof(ITestRunnerFactory).AssemblyQualifiedName;
            var expectedImplementation = typeof(DummyTestRunnerFactory).AssemblyQualifiedName;

            var configurationHolder = new StringConfigProvider(
                $@"{{
                ""runtime"": {{ 
                    ""dependencies"": [
                        {{
                            ""type"": ""{expectedImplementation}"",
                            ""as"": ""{expectedInterface}""
                        }}
                    ]
                }}
            }}");

            var container         = TestObjectFactories.CreateDefaultGlobalContainer(configurationHolder);
            var testRunnerFactory = container.Resolve <ITestRunnerFactory>();

            testRunnerFactory.Should().BeOfType(typeof(DummyTestRunnerFactory));
        }
        public void Should_register_runtime_configuration_with_default_config()
        {
            var container = TestObjectFactories.CreateDefaultGlobalContainer();

            container.Resolve <SpecFlow.Configuration.SpecFlowConfiguration>().Should().NotBeNull();
        }
        public void Should_create_a_container()
        {
            var container = TestObjectFactories.CreateDefaultGlobalContainer();

            container.Should().NotBeNull();
        }