Skip to content

Commit

Permalink
Merge pull request #1370 from autofac/test/load-context-combined-enum…
Browse files Browse the repository at this point in the history
…erable-test

Add additional test for enumerables in load context
  • Loading branch information
tillig authored Mar 6, 2023
2 parents 3489ad3 + 93c02c1 commit 2f5418f
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 2f5418f

Please sign in to comment.