Skip to content

Commit

Permalink
demo of bug 313
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown authored and unknown committed Dec 12, 2014
1 parent 9884775 commit bc6bff2
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
63 changes: 63 additions & 0 deletions src/StructureMap.Testing/Bugs/Bug_313.cs
@@ -0,0 +1,63 @@
using System.Linq;
using NUnit.Framework;
using StructureMap.Graph;

namespace StructureMap.Testing.Bugs
{
[TestFixture]
public class Bug_313
{
[Test]
public void exclude_type_does_indeed_work()
{
var container = new Container(_ =>
{
_.Scan(x =>
{
x.TheCallingAssembly();
x.AddAllTypesOf<IFoo>();
x.ExcludeType<Foo2>();
});
});

container.GetAllInstances<IFoo>()
.Select(x => x.GetType())
.ShouldHaveTheSameElementsAs(typeof(Foo1), typeof(Foo3));
}

[Test, Explicit("This test is invalid and will fail, included to demonstrate a usage problem")]
public void demo_of_problem()
{
var container = new Container(_ =>
{
_.Scan(x =>
{
x.TheCallingAssembly();
x.AddAllTypesOf<IFoo>();
x.ExcludeType<Foo2>();
});
_.Scan(x =>
{
x.TheCallingAssembly();
x.AddAllTypesOf<IFoo>();
x.ExcludeType<Foo1>();
});
});

// This will fail!
container.GetAllInstances<IFoo>()
.Select(x => x.GetType())
.ShouldHaveTheSameElementsAs(typeof(Foo3));
}

public interface IFoo
{

}

public class Foo1 : IFoo { }
public class Foo2 : IFoo { }
public class Foo3 : IFoo { }
}
}
1 change: 1 addition & 0 deletions src/StructureMap.Testing/StructureMap.Testing.csproj
Expand Up @@ -205,6 +205,7 @@
<Compile Include="Bugs\Bug_251_do_not_add_null_values_to_plugin_family_instance_cache.cs" />
<Compile Include="Bugs\Bug_255_InstanceAttribute_Implementation.cs" />
<Compile Include="Bugs\Bug_295_named_registrations_to_nested_container.cs" />
<Compile Include="Bugs\Bug_313.cs" />
<Compile Include="Bugs\BuildUpBug.cs" />
<Compile Include="Bugs\closed_type_generic_is_in_get_all.cs" />
<Compile Include="Bugs\CloseOpenGenericsWithSomeSpecifics.cs" />
Expand Down

0 comments on commit bc6bff2

Please sign in to comment.