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(new DbContextConfiguration())); }
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)); }
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); }
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); }
public void Throws_if_no_store_services_have_been_registered_using_implicit_service_provider() { var selector = new DataStoreSelector( Mock.Of<IServiceProvider>(), Mock.Of<IEntityOptions>(), null); Assert.Equal(Strings.NoDataStoreConfigured, Assert.Throws<InvalidOperationException>( () => selector.SelectDataStore(ServiceProviderSource.Implicit)).Message); }
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); }
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( Mock.Of<IServiceProvider>(), Mock.Of<IDbContextOptions>(), new[] { source1, source2, source3, source4 }); Assert.Equal(Strings.MultipleDataStoresConfigured("'DataStore1' 'DataStore2' 'DataStore4' "), Assert.Throws<InvalidOperationException>( () => selector.SelectDataStore(ServiceProviderSource.Explicit)).Message); }
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); }