public void Throws_if_no_store_services_have_been_registered_using_implicit_service_provider()
        {
            var selector = new DataStoreSelector(null);

            Assert.Equal(Strings.NoDataStoreConfigured,
                         Assert.Throws <InvalidOperationException>(
                             () => selector.SelectDataStore(DbContextServices.ServiceProviderSource.Implicit)).Message);
        }
示例#2
0
        public void Selects_single_available_store()
        {
            var source = CreateSource("DataStore1", configured: false, available: true, store: Mock.Of <DataStore>());

            var selector = new DataStoreSelector(new[] { source });

            Assert.Same(source, selector.SelectDataStore(new DbContextConfiguration()));
        }
示例#3
0
        public void Selects_single_configured_store()
        {
            var services = Mock.Of <IDataStoreServices>();
            var source   = CreateSource("DataStore1", configured: true, available: false, services: services);

            var selector = new DataStoreSelector(Mock.Of <IServiceProvider>(), Mock.Of <IEntityOptions>(), new[] { source });

            Assert.Same(services, selector.SelectDataStore(ServiceProviderSource.Explicit));
        }
示例#4
0
        public void Throws_if_one_store_service_is_registered_but_not_configured_and_cannot_be_used_without_configuration()
        {
            var source = CreateSource("DataStore1", configured: false, available: false);

            var selector = new DataStoreSelector(new[] { source });

            Assert.Equal(Strings.FormatNoDataStoreConfigured(),
                         Assert.Throws <InvalidOperationException>(() => selector.SelectDataStore(new DbContextConfiguration())).Message);
        }
        public void Selects_single_available_store()
        {
            var services = Mock.Of <DataStoreServices>();
            var source   = CreateSource("DataStore1", configured: false, available: true, services: services);

            var selector = new DataStoreSelector(new[] { source });

            Assert.Same(services, selector.SelectDataStore(DbContextServices.ServiceProviderSource.Explicit));
        }
示例#6
0
        public void Throws_if_no_store_services_have_been_registered_using_external_service_provider()
        {
            var selector = new DataStoreSelector(
                Mock.Of <IServiceProvider>(),
                Mock.Of <IEntityOptions>(),
                null);

            Assert.Equal(Strings.NoDataStoreService,
                         Assert.Throws <InvalidOperationException>(
                             () => selector.SelectDataStore(ServiceProviderSource.Explicit)).Message);
        }
示例#7
0
        public void Throws_if_multiple_store_services_are_registered_but_none_are_configured()
        {
            var source1 = CreateSource("DataStore1", configured: false, available: true);
            var source2 = CreateSource("DataStore2", configured: false, available: false);
            var source3 = CreateSource("DataStore3", configured: false, available: false);

            var selector = new DataStoreSelector(new[] { source1, source2, source3 });

            Assert.Equal(Strings.FormatMultipleDataStoresAvailable("'DataStore1' 'DataStore2' 'DataStore3' "),
                         Assert.Throws <InvalidOperationException>(() => selector.SelectDataStore(new DbContextConfiguration())).Message);
        }
示例#8
0
        public void Throws_if_no_store_services_have_been_registered_using_implicit_service_provider()
        {
            var configurationMock = new Mock <DbContextConfiguration>();

            configurationMock.Setup(m => m.ProviderSource).Returns(DbContextConfiguration.ServiceProviderSource.Implicit);

            var selector = new DataStoreSelector(null);

            Assert.Equal(Strings.FormatNoDataStoreConfigured(),
                         Assert.Throws <InvalidOperationException>(() => selector.SelectDataStore(configurationMock.Object)).Message);
        }
示例#9
0
        public void Throws_if_one_store_service_is_registered_but_not_configured_and_cannot_be_used_without_configuration()
        {
            var source = CreateSource("DataStore1", configured: false, available: false);

            var selector = new DataStoreSelector(
                Mock.Of <IServiceProvider>(),
                Mock.Of <IEntityOptions>(),
                new[] { source });

            Assert.Equal(Strings.NoDataStoreConfigured,
                         Assert.Throws <InvalidOperationException>(
                             () => selector.SelectDataStore(ServiceProviderSource.Explicit)).Message);
        }
        public void Throws_if_multiple_stores_configured()
        {
            var source1 = CreateSource("DataStore1", configured: true, available: false);
            var source2 = CreateSource("DataStore2", configured: true, available: false);
            var source3 = CreateSource("DataStore3", configured: false, available: true);
            var source4 = CreateSource("DataStore4", configured: true, available: false);

            var selector = new DataStoreSelector(new[] { source1, source2, source3, source4 });

            Assert.Equal(Strings.MultipleDataStoresConfigured("'DataStore1' 'DataStore2' 'DataStore4' "),
                         Assert.Throws <InvalidOperationException>(
                             () => selector.SelectDataStore(DbContextServices.ServiceProviderSource.Explicit)).Message);
        }
示例#11
0
        public void Throws_if_multiple_store_services_are_registered_but_none_are_configured()
        {
            var source1 = CreateSource("DataStore1", configured: false, available: true);
            var source2 = CreateSource("DataStore2", configured: false, available: false);
            var source3 = CreateSource("DataStore3", configured: false, available: false);

            var selector = new DataStoreSelector(
                Mock.Of <IServiceProvider>(),
                Mock.Of <IEntityOptions>(),
                new[] { source1, source2, source3 });

            Assert.Equal(Strings.MultipleDataStoresAvailable("'DataStore1' 'DataStore2' 'DataStore3' "),
                         Assert.Throws <InvalidOperationException>(
                             () => selector.SelectDataStore(ServiceProviderSource.Explicit)).Message);
        }