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

Add additional test for enumerables in load context #1370

Merged
merged 1 commit into from
Mar 6, 2023
Merged
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
32 changes: 32 additions & 0 deletions test/Autofac.Specification.Test/LoadContextScopeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,38 @@ public void CanLoadInstanceOfScanAssemblyAndUnloadItAfterEnumerable()
WaitForUnload(loadContextRef);
}

[Fact]
public void EnumerableCanContainItemsFromParentAndLoadedScope()
{
var builder = new ContainerBuilder();

builder.RegisterInstance("string").As<object>();

using var rootContainer = builder.Build();

LoadAssemblyAndTest(
rootContainer,
out var loadContextRef,
(builder, assembly) => builder.RegisterType(assembly.GetType("A.Service1")).As<object>(),
(scope, loadContext, assembly) =>
{
var resolved = scope.Resolve<IEnumerable<object>>();

Assert.Collection(
resolved,
firstItem =>
{
Assert.Equal("string", firstItem);
},
secondItem =>
{
Assert.IsType(assembly.GetType("A.Service1"), secondItem);
});
});

WaitForUnload(loadContextRef);
}

[Fact]
public void CannotUseDefaultLoadContextForNewLifetimeScope()
{
Expand Down