diff --git a/Reqnroll/Bindings/Discovery/IRuntimeBindingRegistryBuilder.cs b/Reqnroll/Bindings/Discovery/IRuntimeBindingRegistryBuilder.cs index 0c79c1c2d..79287701e 100644 --- a/Reqnroll/Bindings/Discovery/IRuntimeBindingRegistryBuilder.cs +++ b/Reqnroll/Bindings/Discovery/IRuntimeBindingRegistryBuilder.cs @@ -4,6 +4,7 @@ namespace Reqnroll.Bindings.Discovery { public interface IRuntimeBindingRegistryBuilder { + Assembly[] GetBindingAssemblies(Assembly testAssembly); void BuildBindingsFromAssembly(Assembly assembly); void BuildingCompleted(); } diff --git a/Reqnroll/Bindings/Discovery/RuntimeBindingRegistryBuilder.cs b/Reqnroll/Bindings/Discovery/RuntimeBindingRegistryBuilder.cs index 543e55cb2..38d5bbda7 100644 --- a/Reqnroll/Bindings/Discovery/RuntimeBindingRegistryBuilder.cs +++ b/Reqnroll/Bindings/Discovery/RuntimeBindingRegistryBuilder.cs @@ -2,8 +2,11 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; +using BoDi; using Reqnroll.Bindings.Reflection; using Reqnroll.Compatibility; +using Reqnroll.Configuration; +using Reqnroll.Infrastructure; namespace Reqnroll.Bindings.Discovery { @@ -11,11 +14,24 @@ public class RuntimeBindingRegistryBuilder : IRuntimeBindingRegistryBuilder { private readonly IRuntimeBindingSourceProcessor _bindingSourceProcessor; private readonly IReqnrollAttributesFilter _reqnrollAttributesFilter; + private readonly IBindingAssemblyLoader _bindingAssemblyLoader; + private readonly ReqnrollConfiguration _reqnrollConfiguration; - public RuntimeBindingRegistryBuilder(IRuntimeBindingSourceProcessor bindingSourceProcessor, IReqnrollAttributesFilter reqnrollAttributesFilter) + public RuntimeBindingRegistryBuilder(IRuntimeBindingSourceProcessor bindingSourceProcessor, IReqnrollAttributesFilter reqnrollAttributesFilter, IBindingAssemblyLoader bindingAssemblyLoader, ReqnrollConfiguration reqnrollConfiguration) { _bindingSourceProcessor = bindingSourceProcessor; _reqnrollAttributesFilter = reqnrollAttributesFilter; + _bindingAssemblyLoader = bindingAssemblyLoader; + _reqnrollConfiguration = reqnrollConfiguration; + } + + public Assembly[] GetBindingAssemblies(Assembly testAssembly) + { + var bindingAssemblies = new List { testAssembly }; + + bindingAssemblies.AddRange( + _reqnrollConfiguration.AdditionalStepAssemblies.Select(_bindingAssemblyLoader.Load)); + return bindingAssemblies.ToArray(); } public void BuildBindingsFromAssembly(Assembly assembly) diff --git a/Reqnroll/Bindings/DryRunBindingInvoker.cs b/Reqnroll/Bindings/DryRunBindingInvoker.cs new file mode 100644 index 000000000..e2ce796d1 --- /dev/null +++ b/Reqnroll/Bindings/DryRunBindingInvoker.cs @@ -0,0 +1,23 @@ +using System; +using System.Threading.Tasks; +using Reqnroll.Infrastructure; +using Reqnroll.Tracing; + +namespace Reqnroll.Bindings; + +#pragma warning disable CS0618 // Type or member is obsolete +public class DryRunBindingInvoker : IAsyncBindingInvoker, IBindingInvoker +#pragma warning restore CS0618 // Type or member is obsolete +{ + public object InvokeBinding(IBinding binding, IContextManager contextManager, object[] arguments, ITestTracer testTracer, out TimeSpan duration) + { + duration = TimeSpan.Zero; + return null; + } + + public Task InvokeBindingAsync(IBinding binding, IContextManager contextManager, object[] arguments, ITestTracer testTracer, DurationHolder durationHolder) + { + durationHolder.Duration = TimeSpan.Zero; + return Task.FromResult((object)null); + } +} diff --git a/Reqnroll/Bindings/Provider/BindingProviderService.cs b/Reqnroll/Bindings/Provider/BindingProviderService.cs new file mode 100644 index 000000000..9b97e222e --- /dev/null +++ b/Reqnroll/Bindings/Provider/BindingProviderService.cs @@ -0,0 +1,150 @@ +using System; +using System.Linq; +using System.Reflection; +using BoDi; +using Reqnroll.Bindings.Discovery; +using Reqnroll.Bindings.Provider.Data; +using Reqnroll.Bindings.Reflection; +using Reqnroll.Configuration; +using Reqnroll.Infrastructure; +using SpecFlow.Internal.Json; + +namespace Reqnroll.Bindings.Provider; +public class BindingProviderService +{ + public static string DiscoverBindings(Assembly testAssembly, string jsonConfiguration) + { + if (string.IsNullOrWhiteSpace(jsonConfiguration)) jsonConfiguration = "{}"; + var globalContainer = CreateGlobalContainer(testAssembly, jsonConfiguration); + var bindingRegistryBuilder = globalContainer.Resolve(); + BuildBindingRegistry(testAssembly, bindingRegistryBuilder); + var bindingRegistry = globalContainer.Resolve(); + var resultData = ParseDiscoveryResult(bindingRegistry, testAssembly); + var jsonString = resultData.ToJson(); + return jsonString; + } + + private static BindingData ParseDiscoveryResult(IBindingRegistry bindingRegistry, Assembly testAssembly) + { + var resultData = new BindingData(); + + StepDefinitionData CreateStepDefinition(IStepDefinitionBinding stepDefinitionBinding) + { + var stepDefinition = new StepDefinitionData + { + Source = GetSource(stepDefinitionBinding.Method), + Type = stepDefinitionBinding.StepDefinitionType.ToString(), + Regex = stepDefinitionBinding.Regex?.ToString(), + ParamTypes = GetParamTypes(stepDefinitionBinding.Method), + Scope = GetScope(stepDefinitionBinding), + Expression = stepDefinitionBinding.SourceExpression, + Error = stepDefinitionBinding.ErrorMessage + }; + + return stepDefinition; + } + + HookData CreateHook(IHookBinding hookBinding) + { + var hook = new HookData + { + Source = GetSource(hookBinding.Method), + Type = hookBinding.HookType.ToString(), + HookOrder = hookBinding.HookOrder, + Scope = GetScope(hookBinding), + }; + + return hook; + } + + StepArgumentTransformationData CreateStepArgumentTransformation(IStepArgumentTransformationBinding stepArgumentTransformationBinding) + { + var stepArgumentTransformation = new StepArgumentTransformationData + { + Source = GetSource(stepArgumentTransformationBinding.Method), + Name = stepArgumentTransformationBinding.Name, + Regex = stepArgumentTransformationBinding.Regex?.ToString(), + ParamTypes = GetParamTypes(stepArgumentTransformationBinding.Method), + }; + + return stepArgumentTransformation; + } + + string[] GetParamTypes(IBindingMethod bindingMethod) + { + return bindingMethod.Parameters.Select(p => p.Type.FullName).ToArray(); + } + + BindingScopeData GetScope(IScopedBinding scopedBinding) + { + if (!scopedBinding.IsScoped) + return null; + + return new BindingScopeData + { + Tag = scopedBinding.BindingScope.Tag == null + ? null + : "@" + scopedBinding.BindingScope.Tag, + FeatureTitle = scopedBinding.BindingScope.FeatureTitle, + ScenarioTitle = scopedBinding.BindingScope.ScenarioTitle + }; + } + + BindingSourceData GetSource(IBindingMethod bindingMethod) + { + if (bindingMethod is not RuntimeBindingMethod runtimeBindingMethod || + runtimeBindingMethod.MethodInfo.DeclaringType == null) return null; + + var methodInfo = runtimeBindingMethod.MethodInfo; + return new BindingSourceData + { + Method = new BindingSourceMethodData + { + Type = methodInfo.DeclaringType!.FullName, + Assembly = methodInfo.DeclaringType.Assembly == testAssembly ? null : methodInfo.DeclaringType.Assembly.FullName, + MetadataToken = methodInfo.MetadataToken, + FullName = methodInfo.ToString() + } + }; + } + + resultData.StepDefinitions = bindingRegistry.GetStepDefinitions().Select(CreateStepDefinition).ToArray(); + resultData.Hooks = bindingRegistry.GetHooks().Select(CreateHook).ToArray(); + resultData.StepArgumentTransformations = bindingRegistry.GetStepTransformations().Select(CreateStepArgumentTransformation).ToArray(); + resultData.Errors = bindingRegistry.GetErrorMessages().Select(e => $"{e.Type}: {e.Message}").ToArray(); + return resultData; + } + + private static void BuildBindingRegistry(Assembly testAssembly, IRuntimeBindingRegistryBuilder bindingRegistryBuilder) + { + var bindingAssemblies = bindingRegistryBuilder.GetBindingAssemblies(testAssembly); + foreach (Assembly assembly in bindingAssemblies) + { + bindingRegistryBuilder.BuildBindingsFromAssembly(assembly); + } + bindingRegistryBuilder.BuildingCompleted(); + } + + class BindingDiscoveryDependencyProvider : DefaultDependencyProvider + { + public override void RegisterGlobalContainerDefaults(ObjectContainer container) + { + base.RegisterGlobalContainerDefaults(container); + container.RegisterTypeAs(); +#pragma warning disable CS0618 + container.RegisterTypeAs(); +#pragma warning restore CS0618 + } + } + + private static IObjectContainer CreateGlobalContainer(Assembly testAssembly, string jsonConfiguration) + { + var containerBuilder = new ContainerBuilder(new BindingDiscoveryDependencyProvider()) + { + SkipLoadingProvider = true + }; + var configurationProvider = new JsonStringRuntimeConfigurationProvider(jsonConfiguration); + return containerBuilder.CreateGlobalContainer(testAssembly, configurationProvider); + } + +} diff --git a/Reqnroll/Bindings/Provider/Data/BindingData.cs b/Reqnroll/Bindings/Provider/Data/BindingData.cs new file mode 100644 index 000000000..013c763a4 --- /dev/null +++ b/Reqnroll/Bindings/Provider/Data/BindingData.cs @@ -0,0 +1,11 @@ +#nullable disable +namespace Reqnroll.Bindings.Provider.Data; + +public class BindingData +{ + public string[] Errors { get; set; } + public string[] Warnings { get; set; } + public StepDefinitionData[] StepDefinitions { get; set; } + public HookData[] Hooks { get; set; } + public StepArgumentTransformationData[] StepArgumentTransformations { get; set; } +} diff --git a/Reqnroll/Bindings/Provider/Data/BindingScopeData.cs b/Reqnroll/Bindings/Provider/Data/BindingScopeData.cs new file mode 100644 index 000000000..b8ec8cbd1 --- /dev/null +++ b/Reqnroll/Bindings/Provider/Data/BindingScopeData.cs @@ -0,0 +1,9 @@ +#nullable disable +namespace Reqnroll.Bindings.Provider.Data; + +public class BindingScopeData +{ + public string Tag { get; set; } + public string FeatureTitle { get; set; } + public string ScenarioTitle { get; set; } +} diff --git a/Reqnroll/Bindings/Provider/Data/BindingSourceData.cs b/Reqnroll/Bindings/Provider/Data/BindingSourceData.cs new file mode 100644 index 000000000..8563c0631 --- /dev/null +++ b/Reqnroll/Bindings/Provider/Data/BindingSourceData.cs @@ -0,0 +1,8 @@ +#nullable disable +namespace Reqnroll.Bindings.Provider.Data; + +public class BindingSourceData +{ + public BindingSourceMethodData Method { get; set; } + public string SourceLocation { get; set; } +} diff --git a/Reqnroll/Bindings/Provider/Data/BindingSourceMethodData.cs b/Reqnroll/Bindings/Provider/Data/BindingSourceMethodData.cs new file mode 100644 index 000000000..034f53bf7 --- /dev/null +++ b/Reqnroll/Bindings/Provider/Data/BindingSourceMethodData.cs @@ -0,0 +1,10 @@ +#nullable disable +namespace Reqnroll.Bindings.Provider.Data; + +public class BindingSourceMethodData +{ + public string Type { get; set; } // full type name (with namespace) + public string Assembly { get; set; } // assembly name, null if the assembly is the main test assembly + public string FullName { get; set; } // method name with signature: (,) + public int? MetadataToken { get; set; } // MethodInfo.MetadataToken +} diff --git a/Reqnroll/Bindings/Provider/Data/HookData.cs b/Reqnroll/Bindings/Provider/Data/HookData.cs new file mode 100644 index 000000000..f2b121890 --- /dev/null +++ b/Reqnroll/Bindings/Provider/Data/HookData.cs @@ -0,0 +1,9 @@ +#nullable disable +namespace Reqnroll.Bindings.Provider.Data; +public class HookData +{ + public BindingSourceData Source { get; set; } + public BindingScopeData Scope { get; set; } + public string Type { get; set; } + public int HookOrder { get; set; } +} diff --git a/Reqnroll/Bindings/Provider/Data/StepArgumentTransformationData.cs b/Reqnroll/Bindings/Provider/Data/StepArgumentTransformationData.cs new file mode 100644 index 000000000..75f09a5c9 --- /dev/null +++ b/Reqnroll/Bindings/Provider/Data/StepArgumentTransformationData.cs @@ -0,0 +1,12 @@ +#nullable disable +namespace Reqnroll.Bindings.Provider.Data; +public class StepArgumentTransformationData +{ + public BindingSourceData Source { get; set; } + + public string Name { get; set; } + + public string Regex { get; set; } + + public string[] ParamTypes { get; set; } +} diff --git a/Reqnroll/Bindings/Provider/Data/StepDefinitionData.cs b/Reqnroll/Bindings/Provider/Data/StepDefinitionData.cs new file mode 100644 index 000000000..c7a2f7d35 --- /dev/null +++ b/Reqnroll/Bindings/Provider/Data/StepDefinitionData.cs @@ -0,0 +1,14 @@ +#nullable disable +namespace Reqnroll.Bindings.Provider.Data; + +public class StepDefinitionData +{ + public BindingSourceData Source { get; set; } + public string Type { get; set; } + public string Expression { get; set; } + public string Regex { get; set; } + public string[] ParamTypes { get; set; } + public BindingScopeData Scope { get; set; } + + public string Error { get; set; } +} diff --git a/Reqnroll/Configuration/JsonStringRuntimeConfigurationProvider.cs b/Reqnroll/Configuration/JsonStringRuntimeConfigurationProvider.cs new file mode 100644 index 000000000..b8410bd95 --- /dev/null +++ b/Reqnroll/Configuration/JsonStringRuntimeConfigurationProvider.cs @@ -0,0 +1,20 @@ +using System; +using Reqnroll.Configuration.JsonConfig; + +namespace Reqnroll.Configuration; +public class JsonStringRuntimeConfigurationProvider(string jsonConfigFileContent) : IRuntimeConfigurationProvider +{ + public ReqnrollConfiguration LoadConfiguration(ReqnrollConfiguration reqnrollConfiguration) + { + if (reqnrollConfiguration == null) + throw new ArgumentNullException(nameof(reqnrollConfiguration)); + + if (jsonConfigFileContent == null) return reqnrollConfiguration; + + if (!jsonConfigFileContent.Trim().StartsWith("{")) + throw new NotSupportedException($"Only JSON config value can be provided! Provided value: {jsonConfigFileContent}"); + + var jsonConfigurationLoader = new JsonConfigurationLoader(); + return jsonConfigurationLoader.LoadJson(reqnrollConfiguration, jsonConfigFileContent); + } +} diff --git a/Reqnroll/Infrastructure/ContainerBuilder.cs b/Reqnroll/Infrastructure/ContainerBuilder.cs index ee025cef6..a57b1b30e 100644 --- a/Reqnroll/Infrastructure/ContainerBuilder.cs +++ b/Reqnroll/Infrastructure/ContainerBuilder.cs @@ -23,6 +23,8 @@ public class ContainerBuilder : IContainerBuilder private readonly IDefaultDependencyProvider _defaultDependencyProvider; + public bool SkipLoadingProvider { get; set; } = false; + public ContainerBuilder(IDefaultDependencyProvider defaultDependencyProvider = null) { _defaultDependencyProvider = defaultDependencyProvider ?? DefaultDependencyProvider; @@ -54,9 +56,9 @@ public virtual IObjectContainer CreateGlobalContainer(Assembly testAssembly, IRu container.RegisterFromConfiguration(reqnrollConfiguration.CustomDependencies); } - var unitTestProviderConfigration = container.Resolve(); + var unitTestProviderConfiguration = container.Resolve(); - LoadPlugins(configurationProvider, container, runtimePluginEvents, reqnrollConfiguration, unitTestProviderConfigration, testAssembly); + LoadPlugins(configurationProvider, container, runtimePluginEvents, reqnrollConfiguration, unitTestProviderConfiguration, testAssembly); runtimePluginEvents.RaiseConfigurationDefaults(reqnrollConfiguration); @@ -64,8 +66,8 @@ public virtual IObjectContainer CreateGlobalContainer(Assembly testAssembly, IRu container.RegisterInstanceAs(reqnrollConfiguration); - if (unitTestProviderConfigration != null) - container.RegisterInstanceAs(container.Resolve(unitTestProviderConfigration.UnitTestProvider ?? ConfigDefaults.UnitTestProviderName)); + if (!SkipLoadingProvider) + container.RegisterInstanceAs(container.Resolve(unitTestProviderConfiguration.UnitTestProvider ?? ConfigDefaults.UnitTestProviderName)); runtimePluginEvents.RaiseCustomizeGlobalDependencies(container, reqnrollConfiguration); diff --git a/Reqnroll/Reqnroll.csproj b/Reqnroll/Reqnroll.csproj index 9592af1a8..7eea6d63f 100644 --- a/Reqnroll/Reqnroll.csproj +++ b/Reqnroll/Reqnroll.csproj @@ -69,7 +69,7 @@ - + diff --git a/Reqnroll/TestRunnerManager.cs b/Reqnroll/TestRunnerManager.cs index c75a7320a..fc08890e4 100644 --- a/Reqnroll/TestRunnerManager.cs +++ b/Reqnroll/TestRunnerManager.cs @@ -74,7 +74,7 @@ public virtual ITestRunner CreateTestRunner(string testWorkerId = "default-worke protected virtual void InitializeBindingRegistry(ITestRunner testRunner) { - BindingAssemblies = GetBindingAssemblies(); + BindingAssemblies = _bindingRegistryBuilder.GetBindingAssemblies(TestAssembly); BuildBindingRegistry(BindingAssemblies); void DomainUnload(object sender, EventArgs e) @@ -86,16 +86,6 @@ void DomainUnload(object sender, EventArgs e) AppDomain.CurrentDomain.ProcessExit += DomainUnload; } - protected virtual Assembly[] GetBindingAssemblies() - { - var bindingAssemblies = new List { TestAssembly }; - - var assemblyLoader = _globalContainer.Resolve(); - bindingAssemblies.AddRange( - _reqnrollConfiguration.AdditionalStepAssemblies.Select(assemblyLoader.Load)); - return bindingAssemblies.ToArray(); - } - protected virtual void BuildBindingRegistry(IEnumerable bindingAssemblies) { foreach (Assembly assembly in bindingAssemblies) diff --git a/Tests/Reqnroll.RuntimeTests/Bindings/Provider/BindingProviderServiceTests.cs b/Tests/Reqnroll.RuntimeTests/Bindings/Provider/BindingProviderServiceTests.cs new file mode 100644 index 000000000..d4110ce56 --- /dev/null +++ b/Tests/Reqnroll.RuntimeTests/Bindings/Provider/BindingProviderServiceTests.cs @@ -0,0 +1,18 @@ +using Reqnroll.Bindings.Provider; +using System.Reflection; +using FluentAssertions; +using Xunit; +using Xunit.Abstractions; + +namespace Reqnroll.RuntimeTests.Bindings.Provider; +public class BindingProviderServiceTests(ITestOutputHelper testOutputHelper) +{ + [Fact] + public void Should_provide_step_definitions() + { + var result = BindingProviderService.DiscoverBindings(Assembly.GetExecutingAssembly(), null); + testOutputHelper.WriteLine(result); + result.Should().NotBeNull(); + result.Should().Contain("\"StepDefinitions\":"); + } +} diff --git a/Tests/Reqnroll.RuntimeTests/Infrastructure/PluginTests.cs b/Tests/Reqnroll.RuntimeTests/Infrastructure/PluginTests.cs index 8591ad3ce..60d098b5a 100644 --- a/Tests/Reqnroll.RuntimeTests/Infrastructure/PluginTests.cs +++ b/Tests/Reqnroll.RuntimeTests/Infrastructure/PluginTests.cs @@ -147,9 +147,9 @@ public void WriteToolOutput(string message) - private StringConfigProvider GetConfigWithPlugin() + private JsonStringRuntimeConfigurationProvider GetConfigWithPlugin() { - return new StringConfigProvider("{}"); + return new JsonStringRuntimeConfigurationProvider("{}"); } //[Fact] @@ -277,7 +277,7 @@ public void Should_be_able_to_register_scenario_dependencies_from_a_plugin() [Fact] public void Should_be_able_to_register_feature_dependencies_from_a_plugin() { - StringConfigProvider configurationHolder = GetConfigWithPlugin(); + var configurationHolder = GetConfigWithPlugin(); var testDefaultDependencyProvider = new TestDefaultDependencyProvider(new PluginWithCustomFeatureDependencies(oc => oc.RegisterTypeAs())); var container = TestObjectFactories.CreateDefaultFeatureContainer(configurationHolder, testDefaultDependencyProvider); var customDependency = container.Resolve(); diff --git a/Tests/Reqnroll.RuntimeTests/Infrastructure/StringConfigProvider.cs b/Tests/Reqnroll.RuntimeTests/Infrastructure/StringConfigProvider.cs deleted file mode 100644 index 3f7eac886..000000000 --- a/Tests/Reqnroll.RuntimeTests/Infrastructure/StringConfigProvider.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using Reqnroll.Configuration; -using Reqnroll.Configuration.JsonConfig; - -namespace Reqnroll.RuntimeTests.Infrastructure -{ - internal class StringConfigProvider : IRuntimeConfigurationProvider - { - private readonly string configFileContent; - - private bool IsJsonConfig => configFileContent != null && configFileContent.StartsWith("{"); - - public StringConfigProvider(string configContent) - { - configFileContent = configContent; - } - - public ReqnrollConfiguration LoadConfiguration(ReqnrollConfiguration reqnrollConfiguration) - { - if (IsJsonConfig) - { - var jsonConfigurationLoader = new JsonConfigurationLoader(); - - return jsonConfigurationLoader.LoadJson(reqnrollConfiguration, configFileContent); - } - - throw new NotSupportedException("app.config tests are not supported"); - } - } -} \ No newline at end of file diff --git a/Tests/Reqnroll.RuntimeTests/Infrastructure/TestRunContainerBuilderTests.cs b/Tests/Reqnroll.RuntimeTests/Infrastructure/TestRunContainerBuilderTests.cs index 4d7387a1b..8a5b9fc97 100644 --- a/Tests/Reqnroll.RuntimeTests/Infrastructure/TestRunContainerBuilderTests.cs +++ b/Tests/Reqnroll.RuntimeTests/Infrastructure/TestRunContainerBuilderTests.cs @@ -53,7 +53,7 @@ private Assembly CurrentDomainOnAssemblyResolve(object sender, ResolveEventArgs [Fact] public void Should_be_able_to_customize_dependencies_from_config() { - var configurationHolder = new StringConfigProvider( + var configurationHolder = new JsonStringRuntimeConfigurationProvider( $$""" { "runtime": { @@ -78,7 +78,7 @@ 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( + var configurationHolder = new JsonStringRuntimeConfigurationProvider( $@"{{ ""runtime"": {{ ""dependencies"": [ diff --git a/Tests/Reqnroll.RuntimeTests/RuntimeBindingRegistryBuilderTests.cs b/Tests/Reqnroll.RuntimeTests/RuntimeBindingRegistryBuilderTests.cs index 1c475bafe..699cfd7f5 100644 --- a/Tests/Reqnroll.RuntimeTests/RuntimeBindingRegistryBuilderTests.cs +++ b/Tests/Reqnroll.RuntimeTests/RuntimeBindingRegistryBuilderTests.cs @@ -1,9 +1,12 @@ using System; using System.Linq; using System.Reflection; +using Moq; using Xunit; using Reqnroll.Bindings; using Reqnroll.Bindings.Discovery; +using Reqnroll.Configuration; +using Reqnroll.Infrastructure; namespace Reqnroll.RuntimeTests { @@ -209,10 +212,15 @@ public void GivenAndWhen() } } + private RuntimeBindingRegistryBuilder CreateSut() + { + return new RuntimeBindingRegistryBuilder(bindingSourceProcessorStub, new ReqnrollAttributesFilter(), new Mock().Object, ConfigurationLoader.GetDefault()); + } + [Fact] public void ShouldFindBinding_WithDefaultOrder() { - var builder = new RuntimeBindingRegistryBuilder(bindingSourceProcessorStub, new ReqnrollAttributesFilter()); + var builder = CreateSut(); BuildCompleteBindingFromType(builder, typeof (ScopedHookExample)); @@ -222,7 +230,7 @@ public void ShouldFindBinding_WithDefaultOrder() [Fact] public void ShouldFindBinding_WithSpecifiedPriorities() { - var builder = new RuntimeBindingRegistryBuilder(bindingSourceProcessorStub, new ReqnrollAttributesFilter()); + var builder = CreateSut(); BuildCompleteBindingFromType(builder, typeof (PrioritizedHookExample)); @@ -292,7 +300,7 @@ public void ShouldFindBinding_WithSpecifiedPriorities() [Fact] public void ShouldFindExampleConverter() { - var builder = new RuntimeBindingRegistryBuilder(bindingSourceProcessorStub, new ReqnrollAttributesFilter()); + var builder = CreateSut(); BuildCompleteBindingFromAssembly(builder); Assert.Equal(1, @@ -317,7 +325,7 @@ private static void BuildCompleteBindingFromType(RuntimeBindingRegistryBuilder b [Fact] public void ShouldFindScopedExampleConverter() { - var builder = new RuntimeBindingRegistryBuilder(bindingSourceProcessorStub, new ReqnrollAttributesFilter()); + var builder = CreateSut(); BuildCompleteBindingFromAssembly(builder); @@ -336,7 +344,7 @@ public void ShouldFindScopedExampleConverter() [Fact] public void ShouldFindScopedHook_WithCtorArg() { - var builder = new RuntimeBindingRegistryBuilder(bindingSourceProcessorStub, new ReqnrollAttributesFilter()); + var builder = CreateSut(); BuildCompleteBindingFromAssembly(builder); @@ -347,7 +355,7 @@ public void ShouldFindScopedHook_WithCtorArg() [Fact] public void ShouldFindScopedHook_WithMultipleCtorArg() { - var builder = new RuntimeBindingRegistryBuilder(bindingSourceProcessorStub, new ReqnrollAttributesFilter()); + var builder = CreateSut(); BuildCompleteBindingFromAssembly(builder); @@ -358,7 +366,7 @@ public void ShouldFindScopedHook_WithMultipleCtorArg() [Fact] public void ShouldFindScopedHook_WithScopeAttribute() { - var builder = new RuntimeBindingRegistryBuilder(bindingSourceProcessorStub, new ReqnrollAttributesFilter()); + var builder = CreateSut(); BuildCompleteBindingFromAssembly(builder); @@ -369,7 +377,7 @@ public void ShouldFindScopedHook_WithScopeAttribute() [Fact] public void ShouldFindStepDefinitionsWithStepDefinitionAttributes() { - var builder = new RuntimeBindingRegistryBuilder(bindingSourceProcessorStub, new ReqnrollAttributesFilter()); + var builder = CreateSut(); BuildCompleteBindingFromType(builder, typeof(BindingClassWithStepDefinitionAttributes)); @@ -382,7 +390,7 @@ public void ShouldFindStepDefinitionsWithStepDefinitionAttributes() [Fact] public void ShouldFindStepDefinitionsWithTranslatedAttributes() { - var builder = new RuntimeBindingRegistryBuilder(bindingSourceProcessorStub, new ReqnrollAttributesFilter()); + var builder = CreateSut(); BuildCompleteBindingFromType(builder, typeof(BindingClassWithTranslatedStepDefinitionAttributes)); @@ -395,7 +403,7 @@ public void ShouldFindStepDefinitionsWithTranslatedAttributes() [Fact] public void ShouldFindStepDefinitionsWithCustomAttribute() { - var builder = new RuntimeBindingRegistryBuilder(bindingSourceProcessorStub, new ReqnrollAttributesFilter()); + var builder = CreateSut(); BuildCompleteBindingFromType(builder, typeof(BindingClassWithCustomStepDefinitionAttribute)); diff --git a/Tests/Reqnroll.RuntimeTests/TestObjectFactories.cs b/Tests/Reqnroll.RuntimeTests/TestObjectFactories.cs index dd34bad9c..04b5f7769 100644 --- a/Tests/Reqnroll.RuntimeTests/TestObjectFactories.cs +++ b/Tests/Reqnroll.RuntimeTests/TestObjectFactories.cs @@ -30,7 +30,7 @@ internal static IObjectContainer CreateDefaultTestThreadContainer(IRuntimeConfig return CreateDefaultTestThreadContainer(configurationProvider, registerGlobalMocks, registerTestThreadMocks, new RuntimeTestsContainerBuilder()); } - internal static IObjectContainer CreateDefaultFeatureContainer(StringConfigProvider configurationHolder, IDefaultDependencyProvider defaultDependencyProvider = null) + internal static IObjectContainer CreateDefaultFeatureContainer(IRuntimeConfigurationProvider configurationHolder, IDefaultDependencyProvider defaultDependencyProvider = null) { var instance = new RuntimeTestsContainerBuilder(defaultDependencyProvider); var testThreadContainer = CreateDefaultTestThreadContainer(configurationHolder, null, null, instance);