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:
Louis DeJardin
2010-04-21 00:36:36 -07:00
parent 5a07a5a8c4
commit e750edb514
2 changed files with 40 additions and 0 deletions

View 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>());
}
}
}

View File

@@ -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" />