Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

How to use TestRunContext for inject configuration #78

Closed
arnaulddumez opened this issue Mar 3, 2022 · 1 comment
Closed

How to use TestRunContext for inject configuration #78

arnaulddumez opened this issue Mar 3, 2022 · 1 comment
Labels
question Further information is requested wontfix This will not be worked on

Comments

@arnaulddumez
Copy link

arnaulddumez commented Mar 3, 2022

There are difference with default SpecFlow Ioc, the method is static and is not possible to inject TestRunContext like the Specflow sample.


    [Binding]
    public class Hooks
    {
        private readonly TestRunContext _testRunContext;
        
        public Hooks(TestRunContext testRunContext)
        {
            _testRunContext = testRunContext;
        }

        [BeforeScenario(Order = 1)]
        public void RegisterDependencies(IObjectContainer objectContainer)
        {
            objectContainer.RegisterInstanceAs(new DatabaseContext());

            IConfiguration config = new ConfigurationBuilder()
                .AddJsonFile(Path.Combine(_testRunContext.TestDirectory, "appsettings.json"), optional: true, reloadOnChange: true)
                .Build();

            objectContainer.RegisterInstanceAs(config);

VS

    public static class ServiceModule
    {
        [ScenarioDependencies]
        public static IServiceCollection CreateServices()
        {
            var services = new ServiceCollection();

There are equivalent please ?

@mbhoek mbhoek added the question Further information is requested label Mar 11, 2022
@mbhoek
Copy link
Member

mbhoek commented Mar 11, 2022

Hello @arnaulddumez, thanks for your question. Your example (injecting a context class using the constructor) should work using this plugin, please refer to this included test for an example: https://github.com/solidtoken/SpecFlow.DependencyInjection/blob/main/SpecFlow.DependencyInjection.Tests/DependencyInjectionPluginSteps.cs (the dependencies are registered here: https://github.com/solidtoken/SpecFlow.DependencyInjection/blob/main/SpecFlow.DependencyInjection.Tests/TestDependencies.cs).

I am not familiar with TestRunContext -- the only reference I could find is in the SpecFlow+ Runner API documentation (https://docs.specflow.org/projects/specflow-runner/en/latest/Usage/SpecFlow-Runner-APIs.html). Recently Tricentis announced the retirement of SpecFlow+ Runner (https://specflow.org/using-specflow/the-retirement-of-specflow-runner/) so I'm not keen on spending time on it.

@mbhoek mbhoek closed this as completed Mar 11, 2022
@mbhoek mbhoek added the wontfix This will not be worked on label Mar 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested wontfix This will not be worked on
Development

No branches or pull requests

2 participants