public void SimpleLookup() { // <example1> var targets = new TargetContainer(); targets.RegisterObject("hello world"); var target = targets.Fetch(typeof(string)); Assert.IsType <ObjectTarget>(target); // </example1> }
public void Covariant_ShouldRegister_TypeWhichReferencesItselfInImplementedCovariant_NoEnumerable() { // Tests an bug with covariance when a type inherits an interface in which it passes itself // as the argument to a covariant type parameter. This results in a stack overflow unless // explicitly handled. // This simplified, less real-world, scenario takes enumerables out of the equation. // Arrange var config = TargetContainer.DefaultConfig.Clone(); config.Remove(Configuration.InjectEnumerables.Instance); var targets = new TargetContainer(); targets.RegisterObject <ISelfReferencingCovariant>(null, serviceType: typeof(ICovariant <ISelfReferencingCovariant>)); // Act var fetched = targets.Fetch(typeof(ICovariant <ISelfReferencingCovariantBaseInterface>)); // Assert Assert.NotNull(fetched); Assert.False(fetched.UseFallback); }
public void MixedVariance_ShouldMixContravarianceWithCovariance() { // Arrange TargetContainer targets = new TargetContainer(); targets.RegisterObject <Func <BaseClass, BaseClassChild> >(bc => new BaseClassChild()); // Act var result = new TargetTypeSelector(typeof(Func <BaseClassChild, BaseClass>), targets).ToArray(); LogActual(result); // Assert Assert.Equal(new[] { typeof(Func <BaseClassChild, BaseClass>), typeof(Func <BaseClass, BaseClass>), typeof(Func <BaseClass, BaseClassChild>), typeof(Func <object, BaseClass>), typeof(Func <,>) }, result); }