public void LoadShouldThrowExceptionWhenIgnoreNotSet() { //Arrange bool shoulOnLoadExceptionCalled = false; DbConnection connection = new SqlConnection(_fixture.TestSettings.MssqlConnectionString.Replace("P@ssw0rd123", "wrongpassword")); EFCoreConfigurationSource <PersonDbContext> configurationSource = new EFCoreConfigurationSource <PersonDbContext>(options => options.UseSqlServer(connection), onLoadException: exceptionContext => { exceptionContext.Ignore = false; shoulOnLoadExceptionCalled = true; }); EFCoreConfigurationProvider <PersonDbContext> configurationProvider = new EFCoreConfigurationProvider <PersonDbContext>(configurationSource); //Act Exception ex = Record.Exception(() => configurationProvider.Load()); //Assert Assert.NotNull(ex); Assert.True(shoulOnLoadExceptionCalled); }
public async Task LoadAndWatchDbShouldThrowExceptionWhenIgnoreNotSet() { //Arrange int onLoadExceptionCalledCount = 0; DbConnection connection = new SqlConnection(_fixture.TestSettings.MssqlConnectionString.Replace("P@ssw0rd123", "wrongpassword")); EFCoreConfigurationSource <PersonDbContext> configurationSource = new EFCoreConfigurationSource <PersonDbContext>(options => options.UseSqlServer(connection), reloadOnChange: true, pollingInterval: 2000, onLoadException: exceptionContext => { exceptionContext.Ignore = false; onLoadExceptionCalledCount++; }); EFCoreConfigurationProvider <PersonDbContext> configurationProvider = new EFCoreConfigurationProvider <PersonDbContext>(configurationSource); //Act Exception ex = Record.Exception(() => configurationProvider.Load()); await Task.Delay(3000); //Assert Assert.NotNull(ex); Assert.Equal(1, onLoadExceptionCalledCount); }