forked from structuremap/structuremap
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test OpenGenericWithConstraints added with corresponding bug-fixes
- Loading branch information
Dmitry Kononchuk
committed
May 9, 2011
1 parent
1c3cb8c
commit 746f0fb
Showing
5 changed files
with
75 additions
and
20 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
Source/StructureMap.Testing/Bugs/OpenGenericWithConstraints.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using NUnit.Framework; | ||
using System.Linq; | ||
using NUnit.Framework.SyntaxHelpers; | ||
|
||
namespace StructureMap.Testing.Bugs | ||
{ | ||
public class ClosedGenericForStruct<T>: IAmOpenGeneric<T> | ||
where T: struct {} | ||
|
||
public class ClosedGenericForEnumerable<T>: IAmOpenGeneric<T> | ||
where T: IEnumerable {} | ||
|
||
public struct EnumerableStruct: IEnumerable | ||
{ | ||
#region IEnumerable Members | ||
|
||
public IEnumerator GetEnumerator() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
#endregion | ||
} | ||
|
||
[TestFixture] | ||
public class OpenGenericWithConstraints | ||
{ | ||
[Test] | ||
public void RegisterTwoInheritorsWithDifferentTypeConstraints() | ||
{ | ||
var container = new Container(x => { | ||
x.Scan(y => y.TheCallingAssembly()); | ||
x.For(typeof(IAmOpenGeneric<>)).Add(typeof(ClosedGenericForEnumerable<>)); | ||
x.For(typeof(IAmOpenGeneric<>)).Add(typeof(ClosedGenericForStruct<>)); | ||
}); | ||
container.GetInstance<IAmOpenGeneric<int>>().ShouldBeOfType<ClosedGenericForStruct<int>>(); | ||
container.GetInstance<IAmOpenGeneric<ArrayList>>().ShouldBeOfType<ClosedGenericForEnumerable<ArrayList>>(); | ||
|
||
IList<IAmOpenGeneric<EnumerableStruct>> amOpenGenerics = container.GetAllInstances<IAmOpenGeneric<EnumerableStruct>>(); | ||
amOpenGenerics.Single(x => x.GetType() == typeof(ClosedGenericForStruct<EnumerableStruct>)); | ||
amOpenGenerics.Single(x => x.GetType() == typeof(ClosedGenericForEnumerable<EnumerableStruct>)); | ||
Assert.That(amOpenGenerics.Count, Is.EqualTo(2)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters