mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Found what could be an Autofac bug
Made a test for repro and emailed the autofac group --HG-- branch : dev
This commit is contained in:
39
src/Orchard.Tests/Environment/AutofacUtil/AutofacTests.cs
Normal file
39
src/Orchard.Tests/Environment/AutofacUtil/AutofacTests.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Autofac;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Orchard.Tests.Environment.AutofacUtil {
|
||||
[TestFixture]
|
||||
public class AutofacTests {
|
||||
public interface IFoo { }
|
||||
public class Foo1 : IFoo { }
|
||||
public class Foo2 : IFoo { }
|
||||
public class Foo3 : IFoo { }
|
||||
|
||||
[Test]
|
||||
public void EnumerablesFromDifferentLifetimeScopesShouldReturnDifferentCollections() {
|
||||
var rootBuilder = new ContainerBuilder();
|
||||
rootBuilder.RegisterType<Foo1>().As<IFoo>();
|
||||
var rootContainer = rootBuilder.Build();
|
||||
|
||||
var scopeA = rootContainer.BeginLifetimeScope(
|
||||
scopeBuilder => scopeBuilder.RegisterType<Foo2>().As<IFoo>());
|
||||
var arrayA = scopeA.Resolve<IEnumerable<IFoo>>().ToArray();
|
||||
|
||||
var scopeB = rootContainer.BeginLifetimeScope(
|
||||
scopeBuilder => scopeBuilder.RegisterType<Foo3>().As<IFoo>());
|
||||
var arrayB = scopeB.Resolve<IEnumerable<IFoo>>().ToArray();
|
||||
|
||||
Assert.That(arrayA.Count(), Is.EqualTo(2));
|
||||
Assert.That(arrayA, Has.Some.TypeOf<Foo1>());
|
||||
Assert.That(arrayA, Has.Some.TypeOf<Foo2>());
|
||||
|
||||
Assert.That(arrayB.Count(), Is.EqualTo(2));
|
||||
Assert.That(arrayB, Has.Some.TypeOf<Foo1>());
|
||||
Assert.That(arrayB, Has.Some.TypeOf<Foo3>());
|
||||
}
|
||||
}
|
||||
}
|
@@ -156,6 +156,7 @@
|
||||
<Compile Include="Data\Builders\SessionFactoryBuilderTests.cs" />
|
||||
<Compile Include="Data\RepositoryTests.cs" />
|
||||
<Compile Include="Data\StubLocator.cs" />
|
||||
<Compile Include="Environment\AutofacUtil\AutofacTests.cs" />
|
||||
<Compile Include="Environment\AutofacUtil\DynamicProxy2\DynamicProxyTests.cs" />
|
||||
<Compile Include="Environment\Utility\Build.cs" />
|
||||
<Compile Include="Environment\Configuration\AppDataFolderTests.cs" />
|
||||
|
Reference in New Issue
Block a user