Exemple #1
0
        public void ResolveAllByTypeNotRegisteredThrowsException()
        {
            using (var container = new IocContainer())
            {
                var results = container.ResolveAll<IFoo>();

                // Doesnt throw exception before it is enumerated because it uses yield return - OK ?
                var test = results.Count();
            }
        }
Exemple #2
0
        public void ResolveAllByTypeReturnsInstancesOfExpectedType()
        {
            using (var container = new IocContainer())
            {
                container.Register<IFoo>(c => new Foo1());
                container.Register<IFoo>("Foo1", c => new Foo2());
                container.Register<IFoo>("Foo2", c => new Foo2());
                container.Register<IBar>(c => new Bar1());

                var results = container.ResolveAll<IFoo>();

                Assert.IsTrue(results.Count() == 3);

                var resultsList = results.ToList();

                CollectionAssert.AllItemsAreNotNull(resultsList);
                CollectionAssert.AllItemsAreInstancesOfType(resultsList, typeof(IFoo));
                CollectionAssert.AllItemsAreUnique(resultsList);
            }
        }
        public void RegisteredClassesCanBeResolvedAllByInterface()
        {
            using (var iocContainer = new IocContainer())
            {
                iocContainer.Register<Foo1, Foo1>();
                iocContainer.Register<Foo2, Foo2>();
                iocContainer.Register<Bar1, Bar1>();

                var results = iocContainer.ResolveAll<IFoo>();
                Verify.That(results).IsNotNull()
                                    .IsAnInstanceOfType(typeof(IEnumerable<IFoo>));
                Verify.That(results.Count()).IsEqualTo(2);
            }
        }