public void LazyResolverSupportsRemove() { Func <IEnumerable <Type> > types = () => new[] { typeof(TransientObject3), typeof(TransientObject2), typeof(TransientObject1) }; var resolver = new LazyResolver(types); resolver.RemoveType(typeof(TransientObject3)); Resolution.Freeze(); var values = resolver.Objects; Assert.IsFalse(values.Select(x => x.GetType()).Contains(typeof(TransientObject3))); Assert.IsTrue(values.Select(x => x.GetType()).ContainsAll(new[] { typeof(TransientObject2), typeof(TransientObject1) })); }
public void Type_List_Delegates_Combination() { Func <IEnumerable <Type> > types = () => new[] { typeof(TransientObject3), typeof(TransientObject2) }; var resolver = new LazyResolver(types); resolver.AddTypeListDelegate(() => new[] { typeof(TransientObject1) }); Resolution.Freeze(); var instances1 = resolver.Objects; Assert.AreEqual(3, instances1.Count()); Assert.IsTrue(instances1.Select(x => x.GetType()).ContainsAll(new[] { typeof(TransientObject1), typeof(TransientObject2), typeof(TransientObject3) })); }
public void LazyResolverThrowsOnDuplicate() { Func <IEnumerable <Type> > types = () => new[] { typeof(TransientObject3), typeof(TransientObject2), typeof(TransientObject1) }; var resolver = new LazyResolver(types); // duplicate, but will not throw here resolver.AddType <TransientObject1>(); Resolution.Freeze(); Assert.Throws <InvalidOperationException>(() => { var values = resolver.Objects; }); }
public void LazyResolverResolvesTypeProducers() { Func <IEnumerable <Type> > types = () => new[] { typeof(TransientObject3), typeof(TransientObject2) }; var resolver = new LazyResolver(types); resolver.AddTypeListDelegate(() => new[] { typeof(TransientObject1) }); Resolution.Freeze(); var values = resolver.Objects; Assert.AreEqual(3, values.Count()); Assert.IsTrue(values.Select(x => x.GetType()) .ContainsAll(new[] { typeof(TransientObject1), typeof(TransientObject2), typeof(TransientObject3) })); }
public void Ensure_Lazy_Type_Resolution() { var resolver = new LazyResolver(new[] { new Lazy <Type>(() => typeof(TransientObject3)) }); resolver.AddType <TransientObject1>(); resolver.AddType(new Lazy <Type>(() => typeof(TransientObject2))); Resolution.Freeze(); Assert.IsFalse(resolver.HasResolvedTypes); var instances1 = resolver.Objects; Assert.IsTrue(resolver.HasResolvedTypes); Assert.AreEqual(3, instances1.Count()); Assert.IsTrue(instances1.Select(x => x.GetType()).ContainsAll(new [] { typeof(TransientObject1), typeof(TransientObject2), typeof(TransientObject3) })); }
public void LazyResolverThrowsOnInvalidType() { Func <IEnumerable <Type> > types = () => new[] { typeof(TransientObject3), typeof(TransientObject2), typeof(TransientObject1) }; var resolver = new LazyResolver( new ActivatorServiceProvider(), Mock.Of <ILogger>(), types); // invalid, but will not throw here resolver.AddType(new Lazy <Type>(() => typeof(TransientObject4))); Resolution.Freeze(); Assert.Throws <InvalidOperationException>(() => { var values = resolver.Objects; }); }
public void LazyResolverResolvesLazyTypes() { var resolver = new LazyResolver(new[] { new Lazy <Type>(() => typeof(TransientObject3)) }); resolver.AddType <TransientObject1>(); resolver.AddType(new Lazy <Type>(() => typeof(TransientObject2))); Resolution.Freeze(); Assert.IsFalse(resolver.HasResolvedTypes); var values = resolver.Objects; Assert.IsTrue(resolver.HasResolvedTypes); Assert.AreEqual(3, values.Count()); Assert.IsTrue(values.Select(x => x.GetType()) .ContainsAll(new [] { typeof(TransientObject1), typeof(TransientObject2), typeof(TransientObject3) })); }
public void LazyResolverResolvesBothWays() { Func <IEnumerable <Type> > types = () => new[] { typeof(TransientObject3) }; var resolver = new LazyResolver( new ActivatorServiceProvider(), Mock.Of <ILogger>(), types); resolver.AddType(new Lazy <Type>(() => typeof(TransientObject2))); resolver.AddType <TransientObject1>(); Resolution.Freeze(); var values = resolver.Objects; Assert.AreEqual(3, values.Count()); Assert.IsTrue(values.Select(x => x.GetType()) .ContainsAll(new[] { typeof(TransientObject1), typeof(TransientObject2), typeof(TransientObject3) })); }
public void TearDown() { LazyResolver.Reset(); }
public void Initialize() { LazyResolver.Reset(); }
public void Initialize() { TestHelper.SetupLog4NetForTests(); LazyResolver.Reset(); }