Ejemplo n.º 1
0
        public void Should_be_able_to_specify_a_plugin()
        {
            StringConfigProvider configurationHolder = GetConfigWithPlugin();

            TestRunContainerBuilder.DefaultDependencyProvider = new TestDefaultDependencyProvider(new Mock <IRuntimePlugin>().Object);
            TestRunContainerBuilder.CreateContainer(configurationHolder);
        }
Ejemplo n.º 2
0
        public void Should_be_able_to_register_further_dependencies_based_on_the_configuration()
        {
            StringConfigProvider configurationHolder = GetConfigWithPlugin();

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

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

            testRunnerFactory.ShouldBeType <TestRunnerFactory>();

            // 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 = TestRunContainerBuilder.CreateContainer(specialConfiguratuion);
            var customTestRunnerFactory = container.Resolve <ITestRunnerFactory>();

            customTestRunnerFactory.ShouldBeType <CustomTestRunnerFactory>();
        }
Ejemplo n.º 3
0
        public static TInterface CreateInstance <TInterface>(Type type)
        {
            //HACK: to provide backwards compatibility, until DI is fully introduced
            if (type.GetConstructor(new Type[0]) == null)
            {
                var container = TestRunContainerBuilder.CreateContainer();
                return(container.Resolve <TInterface>());
            }

            // do not use ErrorProvider for thowing exceptions here, because of the potential
            // infinite loop
            try
            {
                return((TInterface)Activator.CreateInstance(type));
            }
            catch (InvalidCastException)
            {
                throw new ConfigurationErrorsException(
                          String.Format("The specified type '{0}' does not implement interface '{1}'",
                                        type.FullName, typeof(TInterface).FullName));
            }
            catch (Exception ex)
            {
                throw new ConfigurationErrorsException(
                          String.Format("Unable to create instance of type '{0}': {1}",
                                        type.FullName, ex.Message), ex);
            }
        }
Ejemplo n.º 4
0
        public void Should_be_able_to_register_dependencies_from_a_plugin()
        {
            StringConfigProvider configurationHolder = GetConfigWithPlugin();

            TestRunContainerBuilder.DefaultDependencyProvider = new TestDefaultDependencyProvider(new PluginWithCustomDependency());
            var container        = TestRunContainerBuilder.CreateContainer(configurationHolder);
            var customDependency = container.Resolve <ICustomDependency>();

            customDependency.ShouldBeType(typeof(CustomDependency));
        }
Ejemplo n.º 5
0
        public void Should_be_able_to_change_default_configuration_from_a_plugin()
        {
            StringConfigProvider configurationHolder = GetConfigWithPlugin();

            TestRunContainerBuilder.DefaultDependencyProvider = new TestDefaultDependencyProvider(new PluginWithCustomConfiguration(
                                                                                                      conf => conf.StopAtFirstError = true));
            var container            = TestRunContainerBuilder.CreateContainer(configurationHolder);
            var runtimeConfiguration = container.Resolve <RuntimeConfiguration>();

            runtimeConfiguration.StopAtFirstError.ShouldBeTrue();
        }
Ejemplo n.º 6
0
        static internal TestRunner CreateTestRunner(out IObjectContainer container, Action <IObjectContainer> registerMocks = null)
        {
            container = TestRunContainerBuilder.CreateContainer();

            if (registerMocks != null)
            {
                registerMocks(container);
            }

            return((TestRunner)container.Resolve <ITestRunner>());
        }
Ejemplo n.º 7
0
        private ITestRunner CreateTestRunner(TestRunnerKey key)
        {
            var container = TestRunContainerBuilder.CreateContainer();

            if (key.Async)
            {
                //TODO: better support this in the DI container
                container.RegisterTypeAs <AsyncTestRunner, ITestRunner>();
            }
            var factory = container.Resolve <ITestRunnerFactory>();

            return(factory.Create(key.TestAssembly));
        }
Ejemplo n.º 8
0
        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        = TestRunContainerBuilder.CreateContainer(configurationHolder);
            var unitTestProvider = container.Resolve <IUnitTestRuntimeProvider>();

            unitTestProvider.ShouldBeType(typeof(CustomUnitTestProvider));
        }
Ejemplo n.º 9
0
        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         = TestRunContainerBuilder.CreateContainer(configurationHolder);
            var testRunnerFactory = container.Resolve <ITestRunnerFactory>();

            testRunnerFactory.ShouldBeType(typeof(DummyTestRunnerFactory));
        }
Ejemplo n.º 10
0
        public void Should_be_able_to_specify_a_plugin()
        {
            StringConfigProvider configurationHolder = GetConfigWithPlugin();

            TestRunContainerBuilder.CreateContainer(configurationHolder);
        }
Ejemplo n.º 11
0
        internal static IObjectContainer CreateDefaultGlobalContainer(IRuntimeConfigurationProvider configurationProvider = null)
        {
            var instance = new TestRunContainerBuilder();

            return(instance.CreateContainer(configurationProvider));
        }
Ejemplo n.º 12
0
        public void Should_register_runtime_configuration_with_default_config()
        {
            var container = TestRunContainerBuilder.CreateContainer();

            container.Resolve <RuntimeConfiguration>().ShouldNotBeNull();
        }
Ejemplo n.º 13
0
        public void Should_create_a_container()
        {
            var container = TestRunContainerBuilder.CreateContainer();

            container.ShouldNotBeNull();
        }