Created
May 3, 2013 07:00
-
-
Save tjchaplin/5507617 to your computer and use it in GitHub Desktop.
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
public class User { } | |
public class Order { } | |
public interface ILoader<out T> | |
{ | |
IEnumerable<T> Load(); | |
} | |
public class UserLoader : ILoader<User> | |
{ | |
public IEnumerable<User> Load() | |
{ | |
return new List<User>(){new User()}; | |
} | |
} | |
public class OrderLoader : ILoader<Order> | |
{ | |
public IEnumerable<Order> Load() | |
{ | |
return new List<Order>(){new Order()}; | |
} | |
} | |
[TestFixture] | |
public class CovarianceTest | |
{ | |
private ILoader<object>[] covariantArray; | |
[SetUp] | |
public void Context() | |
{ | |
var container = new WindsorContainer(); | |
container.Register(Classes.FromThisAssembly() | |
.BasedOn(typeof (ILoader<>)) | |
.WithService | |
.Select(new []{typeof(ILoader<object>)})); | |
covariantArray = container.ResolveAll<ILoader<object>>(); | |
} | |
[Test] | |
public void When_Accessing_A_Covariant_Array_Should_Be_Able_To_Access_All_Types() | |
{ | |
foreach (var loader in covariantArray) | |
{ | |
var loaded = loader.Load(); | |
Assert.IsTrue(loaded.Any()); | |
Assert.IsTrue(loaded.Any(x=> x.GetType() == typeof(Order) | |
|| x.GetType() == typeof(User))); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment