public void Throws_if_no_provider_services_have_been_registered_using_implicit_service_provider()
        {
            var selector = new DatabaseProviderSelector(
                Mock.Of<IServiceProvider>(),
                Mock.Of<IDbContextOptions>(),
                null);

            Assert.Equal(CoreStrings.NoProviderConfigured,
                Assert.Throws<InvalidOperationException>(
                    () => selector.SelectServices()).Message);
        }
        public void Selects_single_configured_provider()
        {
            var provider = CreateSource("Database1", configured: true, available: false);
            var serviceProvider = Mock.Of<IServiceProvider>();

            var selector = new DatabaseProviderSelector(
                serviceProvider,
                Mock.Of<IDbContextOptions>(),
                new[] { provider });

            Assert.Same(provider.GetProviderServices(serviceProvider), selector.SelectServices());
        }
        public void Throws_if_multiple_provider_services_are_registered_but_none_are_configured()
        {
            var provider1 = CreateSource("Database1", configured: false, available: true);
            var provider2 = CreateSource("Database2", configured: false, available: false);
            var provider3 = CreateSource("Database3", configured: false, available: false);

            var selector = new DatabaseProviderSelector(
                Mock.Of<IServiceProvider>(),
                Mock.Of<IDbContextOptions>(),
                new[] { provider1, provider2, provider3 });

            Assert.Equal(CoreStrings.MultipleProvidersAvailable("'Database1' 'Database2' 'Database3' "),
                Assert.Throws<InvalidOperationException>(
                    () => selector.SelectServices()).Message);
        }
        public void Throws_if_one_provider_service_is_registered_but_not_configured_and_cannot_be_used_without_configuration()
        {
            var provider = CreateSource("Database1", configured: false, available: false);

            var selector = new DatabaseProviderSelector(
                Mock.Of<IServiceProvider>(),
                Mock.Of<IDbContextOptions>(),
                new[] { provider });

            Assert.Equal(CoreStrings.NoProviderConfigured,
                Assert.Throws<InvalidOperationException>(
                    () => selector.SelectServices()).Message);
        }