Skip to content

Commit

Permalink
Enumerables in load context test
Browse files Browse the repository at this point in the history
Add a test to verify that a parent and loaded scope can create a single enumerable that combines components from both scopes.
  • Loading branch information
alistairjevans committed Mar 6, 2023
1 parent 3489ad3 commit 93c02c1
Showing 1 changed file with 32 additions and 0 deletions.
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

0 comments on commit 93c02c1

Please sign in to comment.