diff --git a/src/EFCore.Design/Design/Internal/DbContextOperations.cs b/src/EFCore.Design/Design/Internal/DbContextOperations.cs index 78a3bcb808d..43c373f6988 100644 --- a/src/EFCore.Design/Design/Internal/DbContextOperations.cs +++ b/src/EFCore.Design/Design/Internal/DbContextOperations.cs @@ -711,6 +711,9 @@ private KeyValuePair> FindContextType(string? name) string name, bool throwOnEmpty) { + if (name == "*") + return types; + var candidates = FilterTypes(types, name, StringComparison.OrdinalIgnoreCase); if (candidates.Count == 0) { @@ -749,10 +752,12 @@ private KeyValuePair> FindContextType(string? name) } private static Dictionary?> FilterTypes( - Dictionary?> types, - string name, - StringComparison comparisonType) - => types + Dictionary?> 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)) diff --git a/test/EFCore.Design.Tests/Design/Internal/DbContextOperationsTest.cs b/test/EFCore.Design.Tests/Design/Internal/DbContextOperationsTest.cs index 2481eaf8367..ace7cd0084d 100644 --- a/test/EFCore.Design.Tests/Design/Internal/DbContextOperationsTest.cs +++ b/test/EFCore.Design.Tests/Design/Internal/DbContextOperationsTest.cs @@ -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(c), + c => Assert.IsType(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); + } + [ConditionalFact] public void Optimize_throws_when_no_contexts() {