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

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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>();
}
}
42 changes: 42 additions & 0 deletions 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 @@ -304,4 +306,44 @@ 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 outputHelper = new ReqnrollOutputHelper(
threadExecutionMock.Object,
traceListenerMock.Object,
attachmentHandlerMock.Object);

_testThreadContainer.RegisterInstanceAs<IReqnrollOutputHelper>(outputHelper);
gasparnagy marked this conversation as resolved.
Show resolved Hide resolved

// Assert

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

outputHelper
.Should()
.BeSameAs(outputHelper);
}
}