public void The_root_resolver_resolves_from_default_resolvers_and_roots()
            {
                var attributeProvider1 = new Mock <AttributeProvider>().Object;
                var attributeProvider2 = new Mock <AttributeProvider>().Object;

                var mockDefaultResolver1 = new Mock <IDbDependencyResolver>();

                mockDefaultResolver1.Setup(m => m.GetServices(typeof(AttributeProvider), null)).Returns(new object[] { attributeProvider1 });
                var mockDefaultResolver2 = new Mock <IDbDependencyResolver>();

                mockDefaultResolver2.Setup(m => m.GetServices(typeof(AttributeProvider), null)).Returns(new object[] { attributeProvider2 });

                var rootResolver = new RootDependencyResolver();

                var defaultProvider = rootResolver.GetServices <AttributeProvider>().Single();

                Assert.IsType <AttributeProvider>(defaultProvider);

                rootResolver.AddDefaultResolver(mockDefaultResolver1.Object);
                rootResolver.AddDefaultResolver(mockDefaultResolver2.Object);

                var attributeProviders = rootResolver.GetServices <AttributeProvider>().ToList();

                Assert.Equal(3, attributeProviders.Count);
                Assert.Same(attributeProvider2, attributeProviders[0]);
                Assert.Same(attributeProvider1, attributeProviders[1]);
                Assert.Same(defaultProvider, attributeProviders[2]);
            }
            public void GetServices_can_be_accessed_from_multiple_threads_concurrently()
            {
                for (var i = 0; i < 30; i++)
                {
                    var bag = new ConcurrentBag <AttributeProvider>();

                    var resolver = new RootDependencyResolver();
                    resolver.AddDefaultResolver(new SingletonDependencyResolver <AttributeProvider>(new AttributeProvider()));
                    resolver.AddDefaultResolver(new SingletonDependencyResolver <AttributeProvider>(new AttributeProvider()));

                    ExecuteInParallel(() => resolver.GetServices <AttributeProvider>().Each(bag.Add));

                    Assert.Equal(60, bag.Count);
                    Assert.True(bag.All(c => c.GetType() == typeof(AttributeProvider)));
                }
            }
            public void The_root_resolver_resolves_from_default_resolvers_and_roots()
            {
                var attributeProvider1 = new Mock<AttributeProvider>().Object;
                var attributeProvider2 = new Mock<AttributeProvider>().Object;

                var mockDefaultResolver1 = new Mock<IDbDependencyResolver>();
                mockDefaultResolver1.Setup(m => m.GetServices(typeof(AttributeProvider), null)).Returns(new object[] { attributeProvider1 });
                var mockDefaultResolver2 = new Mock<IDbDependencyResolver>();
                mockDefaultResolver2.Setup(m => m.GetServices(typeof(AttributeProvider), null)).Returns(new object[] { attributeProvider2 });

                var rootResolver = new RootDependencyResolver();

                var defaultProvider = rootResolver.GetServices<AttributeProvider>().Single();
                Assert.IsType<AttributeProvider>(defaultProvider);

                rootResolver.AddDefaultResolver(mockDefaultResolver1.Object);
                rootResolver.AddDefaultResolver(mockDefaultResolver2.Object);

                var attributeProviders = rootResolver.GetServices<AttributeProvider>().ToList();

                Assert.Equal(3, attributeProviders.Count);
                Assert.Same(attributeProvider2, attributeProviders[0]);
                Assert.Same(attributeProvider1, attributeProviders[1]);
                Assert.Same(defaultProvider, attributeProviders[2]);
            }
            public void GetServices_can_be_accessed_from_multiple_threads_concurrently()
            {
                for (var i = 0; i < 30; i++)
                {
                    var bag = new ConcurrentBag<AttributeProvider>();

                    var resolver = new RootDependencyResolver();
                    resolver.AddDefaultResolver(new SingletonDependencyResolver<AttributeProvider>(new AttributeProvider()));
                    resolver.AddDefaultResolver(new SingletonDependencyResolver<AttributeProvider>(new AttributeProvider()));

                    ExecuteInParallel(() => resolver.GetServices<AttributeProvider>().Each(bag.Add));

                    Assert.Equal(60, bag.Count);
                    Assert.True(bag.All(c => c.GetType() == typeof(AttributeProvider)));
                }
            }