public void The_root_resolver_resolves_from_default_resolvers_then_default_provider_then_roots()
            {
                var defaultService1 = new Mock <AttributeProvider>().Object;
                var defaultService2 = new Mock <AttributeProvider>().Object;
                var providerService = new Mock <AttributeProvider>().Object;

                var mockDefaultResolver1 = new Mock <IDbDependencyResolver>();

                mockDefaultResolver1.Setup(m => m.GetService(typeof(AttributeProvider), null)).Returns(defaultService1);
                var mockDefaultResolver2 = new Mock <IDbDependencyResolver>();

                mockDefaultResolver2.Setup(m => m.GetService(typeof(AttributeProvider), null)).Returns(defaultService2);

                var mockProvider = new Mock <DbProviderServices>();

                mockProvider.Setup(m => m.GetService(typeof(AttributeProvider), null)).Returns(providerService);

                var rootResolver = new RootDependencyResolver();

                Assert.IsType <AttributeProvider>(rootResolver.GetService <AttributeProvider>());

                rootResolver.SetDefaultProviderServices(mockProvider.Object, "My.Provider");
                Assert.Same(providerService, rootResolver.GetService <AttributeProvider>());

                rootResolver.AddDefaultResolver(mockDefaultResolver1.Object);
                Assert.Same(defaultService1, rootResolver.GetService <AttributeProvider>());

                rootResolver.AddDefaultResolver(mockDefaultResolver2.Object);
                Assert.Same(defaultService2, rootResolver.GetService <AttributeProvider>());
            }
示例#2
0
            public void The_root_resolver_uses_the_default_provider_services_resolver_and_caches_provider_instances()
            {
                var providerServices = new Mock<DbProviderServices>().Object;
                var mockProviderResolver = new Mock<DefaultProviderServicesResolver>();
                mockProviderResolver
                    .Setup(m => m.GetService(typeof(DbProviderServices), "FooClient"))
                    .Returns(providerServices);

                var resolver = new RootDependencyResolver(
                    mockProviderResolver.Object,
                    new DatabaseInitializerResolver());

                Assert.Same(providerServices, resolver.GetService<DbProviderServices>("FooClient"));
                mockProviderResolver.Verify(m => m.GetService(typeof(DbProviderServices), "FooClient"), Times.Once());
                Assert.Same(providerServices, resolver.GetService<DbProviderServices>("FooClient"));
                mockProviderResolver.Verify(m => m.GetService(typeof(DbProviderServices), "FooClient"), Times.Once());
            }
            public void The_root_resolver_uses_the_default_provider_services_resolver_and_caches_provider_instances()
            {
                var providerServices     = new Mock <DbProviderServices>().Object;
                var mockProviderResolver = new Mock <DefaultProviderServicesResolver>();

                mockProviderResolver
                .Setup(m => m.GetService(typeof(DbProviderServices), "FooClient"))
                .Returns(providerServices);

                var resolver = new RootDependencyResolver(
                    mockProviderResolver.Object,
                    new DatabaseInitializerResolver());

                Assert.Same(providerServices, resolver.GetService <DbProviderServices>("FooClient"));
                mockProviderResolver.Verify(m => m.GetService(typeof(DbProviderServices), "FooClient"), Times.Once());
                Assert.Same(providerServices, resolver.GetService <DbProviderServices>("FooClient"));
                mockProviderResolver.Verify(m => m.GetService(typeof(DbProviderServices), "FooClient"), Times.Once());
            }
            public void The_root_resolver_resolves_from_default_resolvers_before_roots()
            {
                var attributeProvider1 = new Mock <AttributeProvider>().Object;
                var attributeProvider2 = new Mock <AttributeProvider>().Object;

                var mockDefaultResolver1 = new Mock <IDbDependencyResolver>();

                mockDefaultResolver1.Setup(m => m.GetService(typeof(AttributeProvider), null)).Returns(attributeProvider1);
                var mockDefaultResolver2 = new Mock <IDbDependencyResolver>();

                mockDefaultResolver2.Setup(m => m.GetService(typeof(AttributeProvider), null)).Returns(attributeProvider2);

                var rootResolver = new RootDependencyResolver();

                Assert.IsType <AttributeProvider>(rootResolver.GetService <AttributeProvider>());

                rootResolver.AddDefaultResolver(mockDefaultResolver1.Object);
                Assert.Same(attributeProvider1, rootResolver.GetService <AttributeProvider>());

                rootResolver.AddDefaultResolver(mockDefaultResolver2.Object);
                Assert.Same(attributeProvider2, rootResolver.GetService <AttributeProvider>());
            }
            public void GetService_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(() => bag.Add(resolver.GetService <AttributeProvider>()));

                    Assert.Equal(20, bag.Count);
                    Assert.True(bag.All(c => c.GetType() == typeof(AttributeProvider)));
                }
            }
            public void GetService_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(() => bag.Add(resolver.GetService<AttributeProvider>()));

                    Assert.Equal(20, bag.Count);
                    Assert.True(bag.All(c => c.GetType() == typeof(AttributeProvider)));
                }
            }
            public void The_root_resolver_resolves_from_default_resolvers_then_default_provider_then_roots()
            {
                var defaultService1 = new Mock<AttributeProvider>().Object;
                var defaultService2 = new Mock<AttributeProvider>().Object;
                var providerService = new Mock<AttributeProvider>().Object;

                var mockDefaultResolver1 = new Mock<IDbDependencyResolver>();
                mockDefaultResolver1.Setup(m => m.GetService(typeof(AttributeProvider), null)).Returns(defaultService1);
                var mockDefaultResolver2 = new Mock<IDbDependencyResolver>();
                mockDefaultResolver2.Setup(m => m.GetService(typeof(AttributeProvider), null)).Returns(defaultService2);

                var mockProvider = new Mock<DbProviderServices>();
                mockProvider.Setup(m => m.GetService(typeof(AttributeProvider), null)).Returns(providerService);

                var rootResolver = new RootDependencyResolver();

                Assert.IsType<AttributeProvider>(rootResolver.GetService<AttributeProvider>());

                rootResolver.SetDefaultProviderServices(mockProvider.Object, "My.Provider");
                Assert.Same(providerService, rootResolver.GetService<AttributeProvider>());

                rootResolver.AddDefaultResolver(mockDefaultResolver1.Object);
                Assert.Same(defaultService1, rootResolver.GetService<AttributeProvider>());

                rootResolver.AddDefaultResolver(mockDefaultResolver2.Object);
                Assert.Same(defaultService2, rootResolver.GetService<AttributeProvider>());
            }
示例#8
0
            public void The_root_resolver_resolves_from_secondary_resolvers_before_roots()
            {
                var attributeProvider1 = new Mock<AttributeProvider>().Object;
                var attributeProvider2 = new Mock<AttributeProvider>().Object;

                var mockSecondaryResolver1 = new Mock<IDbDependencyResolver>();
                mockSecondaryResolver1.Setup(m => m.GetService(typeof(AttributeProvider), null)).Returns(attributeProvider1);
                var mockSecondaryResolver2 = new Mock<IDbDependencyResolver>();
                mockSecondaryResolver2.Setup(m => m.GetService(typeof(AttributeProvider), null)).Returns(attributeProvider2);

                var rootResolver = new RootDependencyResolver();

                Assert.IsType<AttributeProvider>(rootResolver.GetService<AttributeProvider>());

                rootResolver.AddSecondaryResolver(mockSecondaryResolver1.Object);
                Assert.Same(attributeProvider1, rootResolver.GetService<AttributeProvider>());

                rootResolver.AddSecondaryResolver(mockSecondaryResolver2.Object);
                Assert.Same(attributeProvider2, rootResolver.GetService<AttributeProvider>());
            }