Skip to content

Commit

Permalink
Fix IsConfigured to return true only when a provider is configured
Browse files Browse the repository at this point in the history
As opposed to any extension

Fixes #13228
  • Loading branch information
ajcvickers committed Oct 8, 2018
1 parent efdcf46 commit 188dbf4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/EFCore/DbContextOptionsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public DbContextOptionsBuilder([NotNull] DbContextOptions options)
/// <see cref="DbContext.OnConfiguring(DbContextOptionsBuilder)" />.
/// </para>
/// </summary>
public virtual bool IsConfigured => _options.Extensions.Any();
public virtual bool IsConfigured => _options.Extensions.Any(e => e.ApplyServices(new ServiceCollection()));

/// <summary>
/// Sets the model to be used for the context. If the model is set, then <see cref="DbContext.OnModelCreating(ModelBuilder)" />
Expand Down
16 changes: 14 additions & 2 deletions test/EFCore.Tests/DbContextOptionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void Can_update_an_existing_extension()
}

[Fact]
public void IsConfigured_returns_true_if_any_extensions_have_been_added()
public void IsConfigured_returns_true_if_any_provider_extensions_have_been_added()
{
var optionsBuilder = new DbContextOptionsBuilder();

Expand All @@ -105,6 +105,18 @@ public void IsConfigured_returns_true_if_any_extensions_have_been_added()
Assert.True(optionsBuilder.IsConfigured);
}

[Fact]
public void IsConfigured_returns_false_if_only_non_provider_extensions_have_been_added()
{
var optionsBuilder = new DbContextOptionsBuilder();

Assert.False(optionsBuilder.IsConfigured);

((IDbContextOptionsBuilderInfrastructure)optionsBuilder).AddOrUpdateExtension(new FakeDbContextOptionsExtension1());

Assert.False(optionsBuilder.IsConfigured);
}

private class FakeDbContextOptionsExtension1 : IDbContextOptionsExtension
{
public string Something { get; set; }
Expand All @@ -122,7 +134,7 @@ public virtual void Validate(IDbContextOptions options)

private class FakeDbContextOptionsExtension2 : IDbContextOptionsExtension
{
public virtual bool ApplyServices(IServiceCollection services) => false;
public virtual bool ApplyServices(IServiceCollection services) => true;

public virtual long GetServiceProviderHashCode() => 0;

Expand Down

0 comments on commit 188dbf4

Please sign in to comment.