Skip to content

Instantly share code, notes, and snippets.

@gasparnagy
Created June 4, 2024 14:40
Show Gist options
  • Save gasparnagy/2023be4a19f7366feedf9b454a28c2d1 to your computer and use it in GitHub Desktop.
Save gasparnagy/2023be4a19f7366feedf9b454a28c2d1 to your computer and use it in GitHub Desktop.
Reqnroll debug step-in tester
using Moq;
using Reqnroll;
using Reqnroll.Bindings;
using Reqnroll.Bindings.Reflection;
using Reqnroll.BoDi;
using Reqnroll.Configuration;
using Reqnroll.Infrastructure;
using Reqnroll.Tracing;
// get a sample STATIC method from the package
var methodInfo = Type.GetType("ConsoleApp1.SampleClass, ConsoleApp1").GetMethod("SampleMethod");
var bindingInvoker = new BindingInvoker(ConfigurationLoader.GetDefault(), null, new BindingDelegateInvoker());
var binding = new HookBinding(new RuntimeBindingMethod(methodInfo), HookType.BeforeScenario, null, 0);
var contextManagerMock = new Mock<IContextManager>();
var scenarioContainer = new ObjectContainer();
scenarioContainer.RegisterInstanceAs(new ScenarioInfo("", null, null, null));
scenarioContainer.RegisterInstanceAs(new Mock<ITestObjectResolver>().Object);
contextManagerMock.SetupGet(cm => cm.ScenarioContext)
.Returns(scenarioContainer.Resolve<ScenarioContext>());
await bindingInvoker.InvokeBindingAsync(binding, contextManagerMock.Object, Array.Empty<object>(), new Mock<ITestTracer>().Object, new DurationHolder());
Console.WriteLine("Done.");
@gasparnagy
Copy link
Author

The ConsoleApp1.SampleClass, ConsoleApp1 and the SampleMethod has to be customized.

Line 21 makes the invoke. With a local method debugger steps in correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment