Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/EFCore.Design/Design/Internal/DbContextOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,9 @@ private KeyValuePair<Type, Func<DbContext>> FindContextType(string? name)
string name,
bool throwOnEmpty)
{
if (name == "*")
return types;

var candidates = FilterTypes(types, name, StringComparison.OrdinalIgnoreCase);
if (candidates.Count == 0)
{
Expand Down Expand Up @@ -749,10 +752,12 @@ private KeyValuePair<Type, Func<DbContext>> FindContextType(string? name)
}

private static Dictionary<Type, Func<DbContext>?> FilterTypes(
Dictionary<Type, Func<DbContext>?> types,
string name,
StringComparison comparisonType)
=> types
Dictionary<Type, Func<DbContext>?> types,
string name,
StringComparison comparisonType)
=> name == "*"
? types
: types
.Where(t => string.Equals(t.Key.Name, name, comparisonType)
|| string.Equals(t.Key.FullName, name, comparisonType)
|| string.Equals(t.Key.AssemblyQualifiedName, name, comparisonType))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,35 @@ public void CreateAllContexts_creates_all_contexts()
Assert.DoesNotContain(reporter.Messages, m => m.Level == LogLevel.Warning);
}

[ConditionalFact]
public void CreateContext_with_wildcard_returns_all_contexts()
{
var assembly = MockAssembly.Create(typeof(BaseContext), typeof(DerivedContext), typeof(HierarchyContextFactory));
var reporter = new TestOperationReporter();
var operations = new TestDbContextOperations(
reporter,
assembly,
assembly,
project: "",
projectDir: "",
rootNamespace: null,
language: "C#",
nullable: false,
args: [],
new TestAppServiceProviderFactory(assembly, reporter, throwOnCreate: true));

var contexts = operations.CreateAllContexts().ToList();

Assert.Collection(
contexts,
c => Assert.IsType<BaseContext>(c),
c => Assert.IsType<DerivedContext>(c));

Assert.DoesNotContain(reporter.Messages, m => m.Level == LogLevel.Critical);
Assert.DoesNotContain(reporter.Messages, m => m.Level == LogLevel.Error);
Assert.DoesNotContain(reporter.Messages, m => m.Level == LogLevel.Warning);
}
Comment on lines +223 to +250

[ConditionalFact]
public void Optimize_throws_when_no_contexts()
{
Expand Down