From c9f60658b2c19ba5366e66862cb45746ab471949 Mon Sep 17 00:00:00 2001 From: Safia Abdalla Date: Tue, 11 Mar 2025 13:06:17 -0700 Subject: [PATCH 1/2] Fix named configuration handling in DbContext-based clients --- .../AzureCosmosDBResource.cs | 2 + .../AspireAzureEFCoreCosmosExtensions.cs | 2 + ...spireSqlServerEFCoreSqlClientExtensions.cs | 4 +- .../AspireEFPostgreSqlExtensions.cs | 2 + .../AspireOracleEFCoreExtensions.cs | 4 +- .../AspireEFMySqlExtensions.cs | 2 + src/Components/Common/EntityFrameworkUtils.cs | 10 +++- ...spireAzureEfCoreCosmosDBExtensionsTests.cs | 54 ++++++++++++++++++ ...SqlServerEFCoreSqlClientExtensionsTests.cs | 52 +++++++++++++++++ .../AspireEFPostgreSqlExtensionsTests.cs | 56 +++++++++++++++++++ ...pireOracleEFCoreDatabaseExtensionsTests.cs | 52 +++++++++++++++++ .../AspireEFMySqlExtensionsTests.cs | 54 ++++++++++++++++++ 12 files changed, 291 insertions(+), 3 deletions(-) diff --git a/src/Aspire.Hosting.Azure.CosmosDB/AzureCosmosDBResource.cs b/src/Aspire.Hosting.Azure.CosmosDB/AzureCosmosDBResource.cs index dcc6190a428..07915c633a6 100644 --- a/src/Aspire.Hosting.Azure.CosmosDB/AzureCosmosDBResource.cs +++ b/src/Aspire.Hosting.Azure.CosmosDB/AzureCosmosDBResource.cs @@ -73,6 +73,7 @@ void IResourceWithAzureFunctionsConfig.ApplyAzureFunctionsConfiguration(IDiction target[connectionName] = ConnectionStringExpression; // Injected to support Aspire client integration for CosmosDB in Azure Functions projects. target[$"Aspire__Microsoft__Azure__Cosmos__{connectionName}__ConnectionString"] = ConnectionStringExpression; + target[$"Aspire__Microsoft__EntityFrameworkCore__Cosmos__{connectionName}__ConnectionString"] = ConnectionStringExpression; } else { @@ -80,6 +81,7 @@ void IResourceWithAzureFunctionsConfig.ApplyAzureFunctionsConfiguration(IDiction target[$"{connectionName}__accountEndpoint"] = ConnectionStringExpression; // Injected to support Aspire client integration for CosmosDB in Azure Functions projects. target[$"Aspire__Microsoft__Azure__Cosmos__{connectionName}__AccountEndpoint"] = ConnectionStringExpression; + target[$"Aspire__Microsoft__EntityFrameworkCore__Cosmos__{connectionName}__AccountEndpoint"] = ConnectionStringExpression; } } } diff --git a/src/Components/Aspire.Microsoft.EntityFrameworkCore.Cosmos/AspireAzureEFCoreCosmosExtensions.cs b/src/Components/Aspire.Microsoft.EntityFrameworkCore.Cosmos/AspireAzureEFCoreCosmosExtensions.cs index 699e1920b96..8f47741e751 100644 --- a/src/Components/Aspire.Microsoft.EntityFrameworkCore.Cosmos/AspireAzureEFCoreCosmosExtensions.cs +++ b/src/Components/Aspire.Microsoft.EntityFrameworkCore.Cosmos/AspireAzureEFCoreCosmosExtensions.cs @@ -50,6 +50,7 @@ public static class AspireAzureEFCoreCosmosExtensions var settings = builder.GetDbContextSettings( DefaultConfigSectionName, + connectionName, (settings, section) => section.Bind(settings) ); @@ -131,6 +132,7 @@ void UseCosmosBody(CosmosDbContextOptionsBuilder builder) var settings = builder.GetDbContextSettings( DefaultConfigSectionName, + null, (settings, section) => section.Bind(settings) ); diff --git a/src/Components/Aspire.Microsoft.EntityFrameworkCore.SqlServer/AspireSqlServerEFCoreSqlClientExtensions.cs b/src/Components/Aspire.Microsoft.EntityFrameworkCore.SqlServer/AspireSqlServerEFCoreSqlClientExtensions.cs index 2e2b1d0cfc5..f44cc93db44 100644 --- a/src/Components/Aspire.Microsoft.EntityFrameworkCore.SqlServer/AspireSqlServerEFCoreSqlClientExtensions.cs +++ b/src/Components/Aspire.Microsoft.EntityFrameworkCore.SqlServer/AspireSqlServerEFCoreSqlClientExtensions.cs @@ -15,7 +15,7 @@ namespace Microsoft.Extensions.Hosting; /// -/// Extension methods for configuring EntityFrameworkCore DbContext to Azure SQL, MS SQL server +/// Extension methods for configuring EntityFrameworkCore DbContext to Azure SQL, MS SQL server /// public static class AspireSqlServerEFCoreSqlClientExtensions { @@ -47,6 +47,7 @@ public static class AspireSqlServerEFCoreSqlClientExtensions var settings = builder.GetDbContextSettings( DefaultConfigSectionName, + connectionName, (settings, section) => section.Bind(settings) ); @@ -100,6 +101,7 @@ void ConfigureDbContext(DbContextOptionsBuilder dbContextOptionsBuilder) var settings = builder.GetDbContextSettings( DefaultConfigSectionName, + null, (settings, section) => section.Bind(settings) ); diff --git a/src/Components/Aspire.Npgsql.EntityFrameworkCore.PostgreSQL/AspireEFPostgreSqlExtensions.cs b/src/Components/Aspire.Npgsql.EntityFrameworkCore.PostgreSQL/AspireEFPostgreSqlExtensions.cs index 2e5dc7cfd34..97235041fde 100644 --- a/src/Components/Aspire.Npgsql.EntityFrameworkCore.PostgreSQL/AspireEFPostgreSqlExtensions.cs +++ b/src/Components/Aspire.Npgsql.EntityFrameworkCore.PostgreSQL/AspireEFPostgreSqlExtensions.cs @@ -55,6 +55,7 @@ public static partial class AspireEFPostgreSqlExtensions var settings = builder.GetDbContextSettings( DefaultConfigSectionName, + connectionName, (settings, section) => section.Bind(settings) ); @@ -112,6 +113,7 @@ void ConfigureDbContext(DbContextOptionsBuilder dbContextOptionsBuilder) var settings = builder.GetDbContextSettings( DefaultConfigSectionName, + null, (settings, section) => section.Bind(settings) ); diff --git a/src/Components/Aspire.Oracle.EntityFrameworkCore/AspireOracleEFCoreExtensions.cs b/src/Components/Aspire.Oracle.EntityFrameworkCore/AspireOracleEFCoreExtensions.cs index 7a0b4c2d91d..f77c9b713b7 100644 --- a/src/Components/Aspire.Oracle.EntityFrameworkCore/AspireOracleEFCoreExtensions.cs +++ b/src/Components/Aspire.Oracle.EntityFrameworkCore/AspireOracleEFCoreExtensions.cs @@ -16,7 +16,7 @@ namespace Microsoft.Extensions.Hosting; /// -/// Extension methods for configuring EntityFrameworkCore DbContext to Oracle database +/// Extension methods for configuring EntityFrameworkCore DbContext to Oracle database /// public static class AspireOracleEFCoreExtensions { @@ -48,6 +48,7 @@ public static class AspireOracleEFCoreExtensions var settings = builder.GetDbContextSettings( DefaultConfigSectionName, + connectionName, (settings, section) => section.Bind(settings) ); @@ -99,6 +100,7 @@ void ConfigureDbContext(DbContextOptionsBuilder dbContextOptionsBuilder) var settings = builder.GetDbContextSettings( DefaultConfigSectionName, + null, (settings, section) => section.Bind(settings) ); diff --git a/src/Components/Aspire.Pomelo.EntityFrameworkCore.MySql/AspireEFMySqlExtensions.cs b/src/Components/Aspire.Pomelo.EntityFrameworkCore.MySql/AspireEFMySqlExtensions.cs index e9a6b22245f..5faf4ffd5a5 100644 --- a/src/Components/Aspire.Pomelo.EntityFrameworkCore.MySql/AspireEFMySqlExtensions.cs +++ b/src/Components/Aspire.Pomelo.EntityFrameworkCore.MySql/AspireEFMySqlExtensions.cs @@ -60,6 +60,7 @@ public static partial class AspireEFMySqlExtensions var settings = builder.GetDbContextSettings( DefaultConfigSectionName, + connectionName, (settings, section) => section.Bind(settings) ); @@ -149,6 +150,7 @@ void ConfigureDbContext(IServiceProvider serviceProvider, DbContextOptionsBuilde var settings = builder.GetDbContextSettings( DefaultConfigSectionName, + null, (settings, section) => section.Bind(settings) ); diff --git a/src/Components/Common/EntityFrameworkUtils.cs b/src/Components/Common/EntityFrameworkUtils.cs index fcbafc9825a..19b4546b103 100644 --- a/src/Components/Common/EntityFrameworkUtils.cs +++ b/src/Components/Common/EntityFrameworkUtils.cs @@ -14,12 +14,20 @@ internal static class EntityFrameworkUtils /// /// Binds the DbContext specific configuration section to settings when available. /// - public static TSettings GetDbContextSettings(this IHostApplicationBuilder builder, string defaultConfigSectionName, Action bindSettings) + public static TSettings GetDbContextSettings(this IHostApplicationBuilder builder, string defaultConfigSectionName, string? connectionName, Action bindSettings) where TSettings : new() { TSettings settings = new(); var configurationSection = builder.Configuration.GetSection(defaultConfigSectionName); bindSettings(settings, configurationSection); + // If the connectionName is not provided, we've been called in the context + // of an Enrich invocation and don't need to bind the connectionName specific settings. + // Instead, we'll just bind to the TContext-specific settings. + if (connectionName is not null) + { + var connectionSpecificConfigurationSection = configurationSection.GetSection(connectionName); + bindSettings(settings, connectionSpecificConfigurationSection); + } var typeSpecificConfigurationSection = configurationSection.GetSection(typeof(TContext).Name); if (typeSpecificConfigurationSection.Exists()) // https://github.com/dotnet/runtime/issues/91380 { diff --git a/tests/Aspire.Microsoft.EntityFrameworkCore.Cosmos.Tests/AspireAzureEfCoreCosmosDBExtensionsTests.cs b/tests/Aspire.Microsoft.EntityFrameworkCore.Cosmos.Tests/AspireAzureEfCoreCosmosDBExtensionsTests.cs index e0255f0676b..5eb1626d8eb 100644 --- a/tests/Aspire.Microsoft.EntityFrameworkCore.Cosmos.Tests/AspireAzureEfCoreCosmosDBExtensionsTests.cs +++ b/tests/Aspire.Microsoft.EntityFrameworkCore.Cosmos.Tests/AspireAzureEfCoreCosmosDBExtensionsTests.cs @@ -246,6 +246,60 @@ public void AddAzureCosmosClient_FailsWithError() Assert.Contains("AccountEndpoint", e.Message); } + [Fact] + public void AddCosmosDbContext_WithConnectionNameAndSettings_AppliesConnectionSpecificSettings() + { + var builder = Host.CreateEmptyApplicationBuilder(null); + + var connectionName = "testdb"; + var databaseName = "testdbname"; + + builder.Configuration.AddInMemoryCollection(new Dictionary + { + [$"ConnectionStrings:{connectionName}"] = ConnectionString, + [$"Aspire:Microsoft:EntityFrameworkCore:Cosmos:{connectionName}:RequestTimeout"] = "60", + [$"Aspire:Microsoft:EntityFrameworkCore:Cosmos:{connectionName}:DisableTracing"] = "true" + }); + + EntityFrameworkCoreCosmosSettings? capturedSettings = null; + builder.AddCosmosDbContext(connectionName, databaseName, settings => + { + capturedSettings = settings; + }); + + Assert.NotNull(capturedSettings); + Assert.Equal(TimeSpan.Parse("60"), capturedSettings.RequestTimeout); + Assert.True(capturedSettings.DisableTracing); + } + + [Fact] + public void AddCosmosDbContext_WithConnectionSpecificAndContextSpecificSettings_PrefersContextSpecific() + { + // Arrange + var builder = Host.CreateEmptyApplicationBuilder(null); + + var connectionName = "testdb"; + var databaseName = "testdbname"; + + builder.Configuration.AddInMemoryCollection(new Dictionary + { + [$"ConnectionStrings:{connectionName}"] = ConnectionString, + // Connection-specific settings + [$"Aspire:Microsoft:EntityFrameworkCore:Cosmos:{connectionName}:RequestTimeout"] = "60", + // Context-specific settings wins + [$"Aspire:Microsoft:EntityFrameworkCore:Cosmos:TestDbContext:RequestTimeout"] = "120" + }); + + EntityFrameworkCoreCosmosSettings? capturedSettings = null; + builder.AddCosmosDbContext(connectionName, databaseName, settings => + { + capturedSettings = settings; + }); + + Assert.NotNull(capturedSettings); + Assert.Equal(TimeSpan.Parse("120"), capturedSettings.RequestTimeout); + } + private static void PopulateConfiguration(ConfigurationManager configuration, string connectionString) => configuration.AddInMemoryCollection([ new KeyValuePair("ConnectionStrings:cosmos", connectionString) diff --git a/tests/Aspire.Microsoft.EntityFrameworkCore.SqlServer.Tests/AspireSqlServerEFCoreSqlClientExtensionsTests.cs b/tests/Aspire.Microsoft.EntityFrameworkCore.SqlServer.Tests/AspireSqlServerEFCoreSqlClientExtensionsTests.cs index 55deb2fe5ee..da506cd516b 100644 --- a/tests/Aspire.Microsoft.EntityFrameworkCore.SqlServer.Tests/AspireSqlServerEFCoreSqlClientExtensionsTests.cs +++ b/tests/Aspire.Microsoft.EntityFrameworkCore.SqlServer.Tests/AspireSqlServerEFCoreSqlClientExtensionsTests.cs @@ -299,6 +299,58 @@ public void DoesntThrowWhenDbContextIsRegisteredBeforeAspireComponentProduction( Assert.Null(exception); } + [Fact] + public void AddSqlServerDbContext_WithConnectionNameAndSettings_AppliesConnectionSpecificSettings() + { + var builder = Host.CreateEmptyApplicationBuilder(null); + + var connectionName = "testdb"; + + builder.Configuration.AddInMemoryCollection(new Dictionary + { + [$"ConnectionStrings:{connectionName}"] = ConnectionString, + [$"Aspire:Microsoft:EntityFrameworkCore:SqlServer:{connectionName}:CommandTimeout"] = "60", + [$"Aspire:Microsoft:EntityFrameworkCore:SqlServer:{connectionName}:DisableTracing"] = "true" + }); + + MicrosoftEntityFrameworkCoreSqlServerSettings? capturedSettings = null; + builder.AddSqlServerDbContext(connectionName, settings => + { + capturedSettings = settings; + }); + + Assert.NotNull(capturedSettings); + Assert.Equal(60, capturedSettings.CommandTimeout); + Assert.True(capturedSettings.DisableTracing); + } + + [Fact] + public void AddSqlServerDbContext_WithConnectionSpecificAndContextSpecificSettings_PrefersContextSpecific() + { + // Arrange + var builder = Host.CreateEmptyApplicationBuilder(null); + + var connectionName = "testdb"; + + builder.Configuration.AddInMemoryCollection(new Dictionary + { + [$"ConnectionStrings:{connectionName}"] = ConnectionString, + // Connection-specific settings + [$"Aspire:Microsoft:EntityFrameworkCore:SqlServer:{connectionName}:CommandTimeout"] = "60", + // Context-specific settings wins + [$"Aspire:Microsoft:EntityFrameworkCore:SqlServer:TestDbContext:CommandTimeout"] = "120" + }); + + MicrosoftEntityFrameworkCoreSqlServerSettings? capturedSettings = null; + builder.AddSqlServerDbContext(connectionName, settings => + { + capturedSettings = settings; + }); + + Assert.NotNull(capturedSettings); + Assert.Equal(120, capturedSettings.CommandTimeout); + } + public class TestDbContext2 : DbContext { public TestDbContext2(DbContextOptions options) : base(options) diff --git a/tests/Aspire.Npgsql.EntityFrameworkCore.PostgreSQL.Tests/AspireEFPostgreSqlExtensionsTests.cs b/tests/Aspire.Npgsql.EntityFrameworkCore.PostgreSQL.Tests/AspireEFPostgreSqlExtensionsTests.cs index cdd5bc5ade7..e71e30ca33e 100644 --- a/tests/Aspire.Npgsql.EntityFrameworkCore.PostgreSQL.Tests/AspireEFPostgreSqlExtensionsTests.cs +++ b/tests/Aspire.Npgsql.EntityFrameworkCore.PostgreSQL.Tests/AspireEFPostgreSqlExtensionsTests.cs @@ -306,6 +306,62 @@ public void DoesntThrowWhenDbContextIsRegisteredBeforeAspireComponentProduction( Assert.Null(exception); } + [Fact] + public void AddNpgsqlDbContext_WithConnectionNameAndSettings_AppliesConnectionSpecificSettings() + { + var builder = Host.CreateEmptyApplicationBuilder(null); + + var connectionName = "testdb"; + + builder.Configuration.AddInMemoryCollection(new Dictionary + { + [$"ConnectionStrings:{connectionName}"] = ConnectionString, + [$"Aspire:Npgsql:EntityFrameworkCore:PostgreSQL:{connectionName}:CommandTimeout"] = "60", + [$"Aspire:Npgsql:EntityFrameworkCore:PostgreSQL:{connectionName}:DisableRetry"] = "true", + [$"Aspire:Npgsql:EntityFrameworkCore:PostgreSQL:{connectionName}:DisableHealthChecks"] = "true" + }); + + builder.AddNpgsqlDbContext(connectionName); + + NpgsqlEntityFrameworkCorePostgreSQLSettings? capturedSettings = null; + builder.AddNpgsqlDbContext(connectionName, settings => + { + capturedSettings = settings; + }); + + Assert.NotNull(capturedSettings); + Assert.Equal(60, capturedSettings.CommandTimeout); + Assert.True(capturedSettings.DisableRetry); + Assert.True(capturedSettings.DisableHealthChecks); + } + + [Fact] + public void AddNpgsqlDbContext_WithConnectionSpecificAndContextSpecificSettings_PrefersContextSpecific() + { + // Arrange + var builder = Host.CreateEmptyApplicationBuilder(null); + + var connectionName = "testdb"; + + builder.Configuration.AddInMemoryCollection(new Dictionary + { + [$"ConnectionStrings:{connectionName}"] = ConnectionString, + // Connection-specific settings + [$"Aspire:Npgsql:EntityFrameworkCore:PostgreSQL:{connectionName}:CommandTimeout"] = "60", + // Context-specific settings wins + [$"Aspire:Npgsql:EntityFrameworkCore:PostgreSQL:TestDbContext:CommandTimeout"] = "120" + }); + + NpgsqlEntityFrameworkCorePostgreSQLSettings? capturedSettings = null; + builder.AddNpgsqlDbContext(connectionName, settings => + { + capturedSettings = settings; + }); + + Assert.NotNull(capturedSettings); + Assert.Equal(120, capturedSettings.CommandTimeout); + } + public class TestDbContext2 : DbContext { public TestDbContext2(DbContextOptions options) : base(options) diff --git a/tests/Aspire.Oracle.EntityFrameworkCore.Tests/AspireOracleEFCoreDatabaseExtensionsTests.cs b/tests/Aspire.Oracle.EntityFrameworkCore.Tests/AspireOracleEFCoreDatabaseExtensionsTests.cs index 24a59ce31a0..cd07d412bd9 100644 --- a/tests/Aspire.Oracle.EntityFrameworkCore.Tests/AspireOracleEFCoreDatabaseExtensionsTests.cs +++ b/tests/Aspire.Oracle.EntityFrameworkCore.Tests/AspireOracleEFCoreDatabaseExtensionsTests.cs @@ -332,6 +332,58 @@ public void CanPassSettingsToDbContext() Assert.NotNull(context); } + [Fact] + public void AddOracleDatabaseDbContext_WithConnectionNameAndSettings_AppliesConnectionSpecificSettings() + { + var builder = Host.CreateEmptyApplicationBuilder(null); + + var connectionName = "testdb"; + + builder.Configuration.AddInMemoryCollection(new Dictionary + { + [$"ConnectionStrings:{connectionName}"] = ConnectionString, + [$"Aspire:Oracle:EntityFrameworkCore:{connectionName}:CommandTimeout"] = "60", + [$"Aspire:Oracle:EntityFrameworkCore:{connectionName}:DisableTracing"] = "true" + }); + + OracleEntityFrameworkCoreSettings? capturedSettings = null; + builder.AddOracleDatabaseDbContext(connectionName, settings => + { + capturedSettings = settings; + }); + + Assert.NotNull(capturedSettings); + Assert.Equal(60, capturedSettings.CommandTimeout); + Assert.True(capturedSettings.DisableTracing); + } + + [Fact] + public void AddOracleDatabaseDbContext_WithConnectionSpecificAndContextSpecificSettings_PrefersContextSpecific() + { + // Arrange + var builder = Host.CreateEmptyApplicationBuilder(null); + + var connectionName = "testdb"; + + builder.Configuration.AddInMemoryCollection(new Dictionary + { + [$"ConnectionStrings:{connectionName}"] = ConnectionString, + // Connection-specific settings + [$"Aspire:Oracle:EntityFrameworkCore:{connectionName}:CommandTimeout"] = "60", + // Context-specific settings wins + [$"Aspire:Oracle:EntityFrameworkCore:TestDbContext:CommandTimeout"] = "120" + }); + + OracleEntityFrameworkCoreSettings? capturedSettings = null; + builder.AddOracleDatabaseDbContext(connectionName, settings => + { + capturedSettings = settings; + }); + + Assert.NotNull(capturedSettings); + Assert.Equal(120, capturedSettings.CommandTimeout); + } + public class TestDbContext2 : DbContext { public TestDbContext2(DbContextOptions options) : base(options) diff --git a/tests/Aspire.Pomelo.EntityFrameworkCore.MySql.Tests/AspireEFMySqlExtensionsTests.cs b/tests/Aspire.Pomelo.EntityFrameworkCore.MySql.Tests/AspireEFMySqlExtensionsTests.cs index 3adc8859f35..94c7009503a 100644 --- a/tests/Aspire.Pomelo.EntityFrameworkCore.MySql.Tests/AspireEFMySqlExtensionsTests.cs +++ b/tests/Aspire.Pomelo.EntityFrameworkCore.MySql.Tests/AspireEFMySqlExtensionsTests.cs @@ -293,4 +293,58 @@ public void DoesntThrowWhenDbContextIsRegisteredBeforeAspireComponentProduction( Assert.Null(exception); } + + [Fact] + public void AddMySqlDbContext_WithConnectionNameAndSettings_AppliesConnectionSpecificSettings() + { + var builder = Host.CreateEmptyApplicationBuilder(null); + + var connectionName = "testdb"; + + builder.Configuration.AddInMemoryCollection(new Dictionary + { + [$"ConnectionStrings:{connectionName}"] = ConnectionString, + [$"Aspire:Pomelo:EntityFrameworkCore:MySql:{connectionName}:CommandTimeout"] = "60", + [$"Aspire:Pomelo:EntityFrameworkCore:MySql:{connectionName}:DisableRetry"] = "true", + [$"Aspire:Pomelo:EntityFrameworkCore:MySql:{connectionName}:DisableHealthChecks"] = "true" + }); + + PomeloEntityFrameworkCoreMySqlSettings? capturedSettings = null; + builder.AddMySqlDbContext(connectionName, settings => + { + capturedSettings = settings; + }); + + Assert.NotNull(capturedSettings); + Assert.Equal(60, capturedSettings.CommandTimeout); + Assert.True(capturedSettings.DisableRetry); + Assert.True(capturedSettings.DisableHealthChecks); + } + + [Fact] + public void AddMySqlDbContext_WithConnectionSpecificAndContextSpecificSettings_PrefersContextSpecific() + { + // Arrange + var builder = Host.CreateEmptyApplicationBuilder(null); + + var connectionName = "testdb"; + + builder.Configuration.AddInMemoryCollection(new Dictionary + { + [$"ConnectionStrings:{connectionName}"] = ConnectionString, + // Connection-specific settings + [$"Aspire:Pomelo:EntityFrameworkCore:MySql:{connectionName}:CommandTimeout"] = "60", + // Context-specific settings wins + [$"Aspire:Pomelo:EntityFrameworkCore:MySql:TestDbContext:CommandTimeout"] = "120" + }); + + PomeloEntityFrameworkCoreMySqlSettings? capturedSettings = null; + builder.AddMySqlDbContext(connectionName, settings => + { + capturedSettings = settings; + }); + + Assert.NotNull(capturedSettings); + Assert.Equal(120, capturedSettings.CommandTimeout); + } } From 691a249513986a0b604279556a11f6cdac37942a Mon Sep 17 00:00:00 2001 From: Safia Abdalla Date: Tue, 11 Mar 2025 13:20:25 -0700 Subject: [PATCH 2/2] Update ApplyAzureFunctionsConfig tests for Cosmos --- .../Aspire.Hosting.Azure.Tests/AzureCosmosDBExtensionsTests.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/Aspire.Hosting.Azure.Tests/AzureCosmosDBExtensionsTests.cs b/tests/Aspire.Hosting.Azure.Tests/AzureCosmosDBExtensionsTests.cs index da3c8615017..172110dc55d 100644 --- a/tests/Aspire.Hosting.Azure.Tests/AzureCosmosDBExtensionsTests.cs +++ b/tests/Aspire.Hosting.Azure.Tests/AzureCosmosDBExtensionsTests.cs @@ -117,18 +117,21 @@ public void AzureCosmosDBAppliesAzureFunctionsConfiguration() ((IResourceWithAzureFunctionsConfig)cosmos.Resource).ApplyAzureFunctionsConfiguration(target, "cosmos"); Assert.Collection(target.Keys.OrderBy(k => k), k => Assert.Equal("Aspire__Microsoft__Azure__Cosmos__cosmos__AccountEndpoint", k), + k => Assert.Equal("Aspire__Microsoft__EntityFrameworkCore__Cosmos__cosmos__AccountEndpoint", k), k => Assert.Equal("cosmos__accountEndpoint", k)); target.Clear(); ((IResourceWithAzureFunctionsConfig)db1.Resource).ApplyAzureFunctionsConfiguration(target, "db1"); Assert.Collection(target.Keys.OrderBy(k => k), k => Assert.Equal("Aspire__Microsoft__Azure__Cosmos__db1__AccountEndpoint", k), + k => Assert.Equal("Aspire__Microsoft__EntityFrameworkCore__Cosmos__db1__AccountEndpoint", k), k => Assert.Equal("db1__accountEndpoint", k)); target.Clear(); ((IResourceWithAzureFunctionsConfig)container1.Resource).ApplyAzureFunctionsConfiguration(target, "container1"); Assert.Collection(target.Keys.OrderBy(k => k), k => Assert.Equal("Aspire__Microsoft__Azure__Cosmos__container1__AccountEndpoint", k), + k => Assert.Equal("Aspire__Microsoft__EntityFrameworkCore__Cosmos__container1__AccountEndpoint", k), k => Assert.Equal("container1__accountEndpoint", k)); } }