Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autofac: To add default registration for IReqnrollOutputHelper #362

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
* Enhance BoDi error handling to provide the name of the interface being registered when that interface has already been resolved (#324)
* Improve code-behind feature file compilation speed (#336)
* Improve parameter type naming for generic types (#343)
* Add default registration for IReqnrollOutputHelper using Autofac (#357)

## Bug fixes:

*Contributors of this release (in alphabetical order):* @clrudolphi, @obligaron, @olegKoshmeliuk
*Contributors of this release (in alphabetical order):* @Antwane, @clrudolphi, @obligaron, @olegKoshmeliuk

# v2.2.1 - 2024-11-08

Expand Down
7 changes: 7 additions & 0 deletions Plugins/Reqnroll.Autofac.ReqnrollPlugin/AutofacPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,5 +179,12 @@ private void RegisterReqnrollDependencies(
var scenarioContext = reqnrollContainer.Resolve<TestThreadContext>();
return scenarioContext;
}).As<TestThreadContext>();
containerBuilder.Register(
ctx =>
{
var reqnrollContainer = ctx.Resolve<TestThreadContext>();
var scenarioContext = reqnrollContainer.TestThreadContainer.Resolve<IReqnrollOutputHelper>();
return scenarioContext;
}).As<IReqnrollOutputHelper>();
}
}
49 changes: 48 additions & 1 deletion Tests/Reqnroll.PluginTests/Autofac/AutofacPluginTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
using Reqnroll.Autofac.ReqnrollPlugin;
using Reqnroll.BoDi;
using Reqnroll.Configuration;
using Reqnroll.Events;
using Reqnroll.Infrastructure;
using Reqnroll.Plugins;
using Reqnroll.Tracing;
using Reqnroll.UnitTestProvider;
using Xunit;

Expand Down Expand Up @@ -106,7 +108,7 @@ public static void SetupScenarioContainer(global::Autofac.ContainerBuilder conta
}
}

private readonly RuntimePluginEvents _runtimePluginEvents;
private readonly RuntimePluginEvents _runtimePluginEvents;
private readonly ObjectContainer _testRunContainer;
private readonly ObjectContainer _testThreadContainer;
private readonly ObjectContainer _featureContainer;
Expand Down Expand Up @@ -304,4 +306,49 @@ public void Should_allow_using_existing_global_scope()
var globalDep1 = resolver.ResolveBindingInstance(typeof(IGlobalDependency1), scenarioContainer);
globalDep1.Should().NotBeNull();
}

[Fact]
public void Should_register_IReqnrollOutputHelper()
{
// Arrange
var sut = new TestableAutofacPlugin(typeof(ContainerSetup1),
nameof(ContainerSetup1.SetupGlobalContainer),
nameof(ContainerSetup1.SetupScenarioContainer));

// Act
var scenarioContainer = InitializeToScenarioContainer(sut);

var resolver = _testRunContainer.Resolve<ITestObjectResolver>();

var testThreadContext =
new TestThreadContext(_testThreadContainer);

_testThreadContainer.RegisterInstanceAs(testThreadContext);

var traceListenerMock =
new Mock<ITraceListener>();
var attachmentHandlerMock =
new Mock<IReqnrollAttachmentHandler>();
var threadExecutionMock =
new Mock<ITestThreadExecutionEventPublisher>();

var defaultDenpendencyProvider = new DefaultDependencyProvider();
defaultDenpendencyProvider
.RegisterTestThreadContainerDefaults(_testThreadContainer);

_testThreadContainer
.RegisterInstanceAs<ITraceListener>(traceListenerMock.Object);
_testThreadContainer
.RegisterInstanceAs<IReqnrollAttachmentHandler>(attachmentHandlerMock.Object);
_testThreadContainer
.RegisterInstanceAs<ITestThreadExecutionEventPublisher>(threadExecutionMock.Object);

// Assert
var resolvedOutputHelper = resolver
.ResolveBindingInstance(typeof(IReqnrollOutputHelper), scenarioContainer);

resolvedOutputHelper
.Should()
.NotBeNull();
}
}
Loading