コード例 #1
0
        public void TryResolveAllReturnsExpectedInstances()
        {
            using (var container = new IocContainer())
            {
                // Arrange
                var foo1 = new Foo1();
                var foo2 = new Foo2();
                var foo3 = new Foo2();
                var bar1 = new Bar1();

                container.RegisterInstance<IFoo>(foo1);
                container.RegisterInstance<IFoo>("Foo1", foo2);
                container.RegisterInstance<IFoo>("Foo2", foo3);
                container.RegisterInstance<IBar>(bar1);

                // Act
                var results = container.TryResolveAll<IFoo>();

                var resultList = results.ToList();

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

                CollectionAssert.Contains(resultList, foo1);
                CollectionAssert.Contains(resultList, foo2);
                CollectionAssert.Contains(resultList, foo3);
            }
        }
コード例 #2
0
        public void TryResolveAllByTypeNotRegisteredReturnsEmptyEnumerable()
        {
            using (var container = new IocContainer())
            {
                // Arrange
                var foo1 = new Foo1();
                var foo2 = new Foo2();
                var bar1 = new Bar1();

                container.RegisterInstance<IFoo>(foo1);
                container.RegisterInstance<IFoo>("Foo", foo2);
                container.RegisterInstance<IBar>(bar1);

                // Act
                var results = container.TryResolveAll<IFooBar>();

                // Assert
                Assert.IsTrue(results.Count() == 0);
            }
        }
コード例 #3
0
ファイル: ResolveTest.cs プロジェクト: Kingefosa/Dynamo.IoC
		public void ResolveCanResolveCollection()
		{
			var foo1 = new Foo1();
			var foo2 = new Foo2();
			var foo3 = new Foo1();
			IList<IFoo> list = new List<IFoo>(new IFoo[] { foo1, foo2, foo3 });
			
			// Register Instance
			using (var container = new IocContainer())
			{
				container.RegisterInstance(typeof(IEnumerable<IFoo>), list);
				container.RegisterInstance(typeof(IEnumerable<IFoo>), list, "TheKey");

				AssertResolveCanResolveIEnumerableType(container);
				AssertResolveCanResolveIEnumerableType(container, "TheKey");
			}

			// RegisterInstance - Generic
			using (var container = new IocContainer())
			{
				container.RegisterInstance<IEnumerable<IFoo>>(list);
				container.RegisterInstance<IEnumerable<IFoo>>(list, "TheKey");

				AssertResolveCanResolveIEnumerableType(container);
				AssertResolveCanResolveIEnumerableType(container, "TheKey");
			}

			// Register
			using (var container = new IocContainer())
			{
				container.Register<IEnumerable<IFoo>>(x => list);
				container.Register<IEnumerable<IFoo>>(x => list, "TheKey");

				AssertResolveCanResolveIEnumerableType(container);
				AssertResolveCanResolveIEnumerableType(container, "TheKey");
			}
		}