diff --git a/samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthAppHost/Program.cs b/samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthAppHost/Program.cs index 79bc6ba1e3..820d0d304a 100644 --- a/samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthAppHost/Program.cs +++ b/samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthAppHost/Program.cs @@ -8,7 +8,9 @@ var coreApp = builder.AddProject("core") .WithHttpHealthCheck() - .WaitFor(frameworkApp) - .WithIncrementalMigrationFallback(frameworkApp, options => options.RemoteAuthentication = RemoteAuthentication.DefaultScheme); + .WaitFor(frameworkApp); + +var incremental = builder.AddIncrementalMigrationFallback(coreApp, frameworkApp) + .WithAuthentication(RemoteAuthentication.DefaultScheme); builder.Build().Run(); diff --git a/samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthFramework/AuthRemoteFormsAuthFramework.csproj b/samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthFramework/AuthRemoteFormsAuthFramework.csproj index 6867d46660..563587af90 100644 --- a/samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthFramework/AuthRemoteFormsAuthFramework.csproj +++ b/samples/AuthRemoteFormsAuth/AuthRemoteFormsAuthFramework/AuthRemoteFormsAuthFramework.csproj @@ -1,6 +1,6 @@ - net481 + net48 diff --git a/samples/AuthRemoteIdentity/AuthRemoteIdentityAppHost/Program.cs b/samples/AuthRemoteIdentity/AuthRemoteIdentityAppHost/Program.cs index c98ab62930..2d3ebe9571 100644 --- a/samples/AuthRemoteIdentity/AuthRemoteIdentityAppHost/Program.cs +++ b/samples/AuthRemoteIdentity/AuthRemoteIdentityAppHost/Program.cs @@ -17,7 +17,9 @@ var coreApp = builder.AddProject("core") .WithHttpHealthCheck() - .WaitFor(frameworkApp) - .WithIncrementalMigrationFallback(frameworkApp, options => options.RemoteAuthentication = RemoteAuthentication.DefaultScheme); + .WaitFor(frameworkApp); + +var incremental = builder.AddIncrementalMigrationFallback(coreApp, frameworkApp) + .WithAuthentication(RemoteAuthentication.DefaultScheme); builder.Build().Run(); diff --git a/samples/ServiceDefaults/Samples.ServiceDefaults.csproj b/samples/ServiceDefaults/Samples.ServiceDefaults.csproj index b420eaf219..17e44547b9 100644 --- a/samples/ServiceDefaults/Samples.ServiceDefaults.csproj +++ b/samples/ServiceDefaults/Samples.ServiceDefaults.csproj @@ -1,7 +1,7 @@  - net481;net9.0 + net48;net9.0 enable enable true @@ -25,7 +25,7 @@ - + diff --git a/samples/SessionRemote/SessionRemoteAppHost/Program.cs b/samples/SessionRemote/SessionRemoteAppHost/Program.cs index b11ddb4cf0..365ef5c300 100644 --- a/samples/SessionRemote/SessionRemoteAppHost/Program.cs +++ b/samples/SessionRemote/SessionRemoteAppHost/Program.cs @@ -8,7 +8,9 @@ var coreApp = builder.AddProject("core") .WithHttpHealthCheck() - .WaitFor(frameworkApp) - .WithIncrementalMigrationFallback(frameworkApp, options => options.RemoteSession = RemoteSession.Enabled); + .WaitFor(frameworkApp); + +var incremental = builder.AddIncrementalMigrationFallback(coreApp, frameworkApp) + .WithSession(); builder.Build().Run(); diff --git a/samples/WebFormsToBlazor/WebFormsToBlazorAppHost/Program.cs b/samples/WebFormsToBlazor/WebFormsToBlazorAppHost/Program.cs index 02c0b12fff..f875e72f4e 100644 --- a/samples/WebFormsToBlazor/WebFormsToBlazorAppHost/Program.cs +++ b/samples/WebFormsToBlazor/WebFormsToBlazorAppHost/Program.cs @@ -8,7 +8,9 @@ var coreApp = builder.AddProject("core") .WithHttpHealthCheck() - .WaitFor(frameworkApp) - .WithIncrementalMigrationFallback(frameworkApp, options => options.RemoteSession = RemoteSession.Enabled); + .WaitFor(frameworkApp); + +var incremental = builder.AddIncrementalMigrationFallback(coreApp, frameworkApp) + .WithSession(); builder.Build().Run(); diff --git a/samples/WebFormsToBlazor/WebFormsToBlazorAppHost/WebFormsToBlazorAppHost.csproj b/samples/WebFormsToBlazor/WebFormsToBlazorAppHost/WebFormsToBlazorAppHost.csproj index 6161c000d4..2be3cbdaad 100644 --- a/samples/WebFormsToBlazor/WebFormsToBlazorAppHost/WebFormsToBlazorAppHost.csproj +++ b/samples/WebFormsToBlazor/WebFormsToBlazorAppHost/WebFormsToBlazorAppHost.csproj @@ -4,7 +4,7 @@ Exe - net9.0-windows + net10.0-windows enable enable true diff --git a/src/Aspire.Hosting.IncrementalMigration/AspireConstants.Shared.cs b/src/Aspire.Hosting.IncrementalMigration/AspireConstants.Shared.cs index 3d29469887..15b3513aa6 100644 --- a/src/Aspire.Hosting.IncrementalMigration/AspireConstants.Shared.cs +++ b/src/Aspire.Hosting.IncrementalMigration/AspireConstants.Shared.cs @@ -8,14 +8,19 @@ namespace Microsoft.AspNetCore.SystemWebAdapters; internal static partial class AspireConstants { - public const string RootKey = "SystemWebAdapters"; - public const string ProxyKey = RootKey + Separator + "Proxy"; + public const string DefaultIncrementalServiceName = "Default"; + + public const string ProxyKey = "Proxy"; public const string ProxyKeyIsEnabled = ProxyKey + Separator + "UseForwardedHeaders"; - public const string RemoteKey = RootKey + Separator + "Remote"; + public const string RemoteKey = "Remote"; public const string RemoteApiKey = RemoteKey + Separator + "ApiKey"; public const string RemoteUrl = RemoteKey + Separator + "RemoteAppUrl"; public const string RemoteSessionKey = RemoteKey + Separator + "Session"; public const string RemoteAuthKey = RemoteKey + Separator + "Authentication"; public const string RemoteAuthIsDefaultScheme = RemoteAuthKey + Separator + "IsDefaultScheme"; public const string IsEnabled = Separator + "IsEnabled"; + + public static string GetConfigSection(string name) => $"IncrementalMigration{Separator}{name}"; + + public static string GetKey(string name, string key) => $"{GetConfigSection(name)}{Separator}{key}"; } diff --git a/src/Aspire.Hosting.IncrementalMigration/IncrementalMigration.cs b/src/Aspire.Hosting.IncrementalMigration/IncrementalMigration.cs new file mode 100644 index 0000000000..000046b6ae --- /dev/null +++ b/src/Aspire.Hosting.IncrementalMigration/IncrementalMigration.cs @@ -0,0 +1,12 @@ +using Aspire.Hosting.ApplicationModel; + +namespace Aspire.Hosting; + +public class IncrementalMigration(string name) : Resource(name) +{ + internal RemoteAuthentication RemoteAuthentication { get; set; } = RemoteAuthentication.Disabled; + + internal RemoteSession RemoteSession { get; set; } = RemoteSession.Disabled; + + internal string RemoteAppEndpointName { get; set; } = "https"; +} diff --git a/src/Aspire.Hosting.IncrementalMigration/IncrementalMigrationOptions.cs b/src/Aspire.Hosting.IncrementalMigration/IncrementalMigrationOptions.cs deleted file mode 100644 index f43f4e7c13..0000000000 --- a/src/Aspire.Hosting.IncrementalMigration/IncrementalMigrationOptions.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Aspire.Hosting; - -public class IncrementalMigrationOptions -{ - public RemoteAuthentication RemoteAuthentication { get; set; } = RemoteAuthentication.Disabled; - - public RemoteSession RemoteSession { get; set; } = RemoteSession.Disabled; - - public string RemoteAppEndpointName { get; set; } = "https"; -} diff --git a/src/Aspire.Hosting.IncrementalMigration/IncrementalMigrationResourceExtensions.cs b/src/Aspire.Hosting.IncrementalMigration/IncrementalMigrationResourceExtensions.cs index 7155b4d935..aaf24f2084 100644 --- a/src/Aspire.Hosting.IncrementalMigration/IncrementalMigrationResourceExtensions.cs +++ b/src/Aspire.Hosting.IncrementalMigration/IncrementalMigrationResourceExtensions.cs @@ -8,63 +8,106 @@ namespace Aspire.Hosting; public static class IncrementalMigrationResourceExtensions { - public static IResourceBuilder WithIncrementalMigrationFallback( - this IResourceBuilder coreApp, + public static IResourceBuilder AddIncrementalMigrationFallback( + this IDistributedApplicationBuilder builder, + IResourceBuilder coreApp, + IResourceBuilder frameworkApp, + IResourceBuilder? apiKey = null + ) + where TCore : IResourceWithEnvironment + where TFramework : IResourceWithEnvironment, IResourceWithEndpoints + => builder.AddIncrementalMigrationFallback(DefaultIncrementalServiceName, coreApp, frameworkApp, apiKey); + + public static IResourceBuilder AddIncrementalMigrationFallback( + this IDistributedApplicationBuilder builder, + string name, + IResourceBuilder coreApp, IResourceBuilder frameworkApp, - Action? configureOptions = null, IResourceBuilder? apiKey = null ) where TCore : IResourceWithEnvironment where TFramework : IResourceWithEnvironment, IResourceWithEndpoints { + ArgumentNullException.ThrowIfNull(builder); + ArgumentException.ThrowIfNullOrWhiteSpace(name); ArgumentNullException.ThrowIfNull(coreApp); ArgumentNullException.ThrowIfNull(frameworkApp); - apiKey ??= coreApp.ApplicationBuilder.AddParameter($"{coreApp.Resource.Name}-{frameworkApp.Resource.Name}-remoteapp-apiKey", () => Guid.NewGuid().ToString(), secret: true); + var incrementalMigration = new IncrementalMigration(name); - var options = new IncrementalMigrationOptions(); - configureOptions?.Invoke(options); + apiKey ??= coreApp.ApplicationBuilder.AddParameter($"{name}-IncrementalMigration-ApiKey", () => Guid.NewGuid().ToString(), secret: true); coreApp.WithReferenceRelationship(frameworkApp.Resource); coreApp.WithEnvironment(ctx => { - ctx.EnvironmentVariables[RemoteUrl] = frameworkApp.Resource.GetEndpoint(options.RemoteAppEndpointName); - ctx.EnvironmentVariables[RemoteApiKey] = apiKey; + ctx.EnvironmentVariables[GetKey(name, RemoteUrl)] = frameworkApp.Resource.GetEndpoint(incrementalMigration.RemoteAppEndpointName); + ctx.EnvironmentVariables[GetKey(name, RemoteApiKey)] = apiKey; - if (options.RemoteSession == RemoteSession.Enabled) + if (incrementalMigration.RemoteSession == RemoteSession.Enabled) { - ctx.EnvironmentVariables[RemoteSessionKey + IsEnabled] = true; + ctx.EnvironmentVariables[GetKey(name, RemoteSessionKey + IsEnabled)] = true; } - if (options.RemoteAuthentication != RemoteAuthentication.Disabled) + if (incrementalMigration.RemoteAuthentication != RemoteAuthentication.Disabled) { - ctx.EnvironmentVariables[RemoteAuthKey + IsEnabled] = true; + ctx.EnvironmentVariables[GetKey(name, RemoteAuthKey + IsEnabled)] = true; - if (options.RemoteAuthentication == RemoteAuthentication.DefaultScheme) + if (incrementalMigration.RemoteAuthentication == RemoteAuthentication.DefaultScheme) { - ctx.EnvironmentVariables[RemoteAuthIsDefaultScheme] = true; + ctx.EnvironmentVariables[GetKey(name, RemoteAuthIsDefaultScheme)] = true; } } }); frameworkApp.WithEnvironment(ctx => { - ctx.EnvironmentVariables[RemoteApiKey] = apiKey; + ctx.EnvironmentVariables[GetKey(name, RemoteApiKey)] = apiKey; - ctx.EnvironmentVariables[ProxyKeyIsEnabled] = true; + ctx.EnvironmentVariables[GetKey(name, ProxyKeyIsEnabled)] = true; - if (options.RemoteSession == RemoteSession.Enabled) + if (incrementalMigration.RemoteSession == RemoteSession.Enabled) { - ctx.EnvironmentVariables[RemoteSessionKey + IsEnabled] = true; + ctx.EnvironmentVariables[GetKey(name, RemoteSessionKey + IsEnabled)] = true; } - if (options.RemoteAuthentication != RemoteAuthentication.Disabled) + if (incrementalMigration.RemoteAuthentication != RemoteAuthentication.Disabled) { - ctx.EnvironmentVariables[RemoteAuthKey + IsEnabled] = true; + ctx.EnvironmentVariables[GetKey(name, RemoteAuthKey + IsEnabled)] = true; } }); - return coreApp; + return builder.AddResource(incrementalMigration) + .WithInitialState(new() + { + Properties = [], + ResourceType = "IncrementalMigration", + IsHidden = true, + }); + } + + public static IResourceBuilder WithSession(this IResourceBuilder incrementalMigration, RemoteSession mode = RemoteSession.Enabled) + { + ArgumentNullException.ThrowIfNull(incrementalMigration); + incrementalMigration.Resource.RemoteSession = mode; + return incrementalMigration; + } + + public static IResourceBuilder WithAuthentication( + this IResourceBuilder incrementalMigration, + RemoteAuthentication mode = RemoteAuthentication.Enabled) + { + ArgumentNullException.ThrowIfNull(incrementalMigration); + incrementalMigration.Resource.RemoteAuthentication = mode; + return incrementalMigration; + } + + public static IResourceBuilder WithEndpointName( + this IResourceBuilder incrementalMigration, + string endpointName) + { + ArgumentNullException.ThrowIfNull(incrementalMigration); + incrementalMigration.Resource.RemoteAppEndpointName = endpointName; + return incrementalMigration; } } diff --git a/src/Aspire.Microsoft.AspNetCore.SystemWebAdapters/AspireSystemWebAdapterExtensions.cs b/src/Aspire.Microsoft.AspNetCore.SystemWebAdapters/AspireSystemWebAdapterExtensions.cs index 531217be9a..ed48bf4f44 100644 --- a/src/Aspire.Microsoft.AspNetCore.SystemWebAdapters/AspireSystemWebAdapterExtensions.cs +++ b/src/Aspire.Microsoft.AspNetCore.SystemWebAdapters/AspireSystemWebAdapterExtensions.cs @@ -19,7 +19,7 @@ namespace Microsoft.Extensions.Hosting; public static class AspireSystemWebAdaptersExtensions { - public static ISystemWebAdapterBuilder AddSystemWebAdapters(this IHostApplicationBuilder builder) + public static ISystemWebAdapterBuilder AddSystemWebAdapters(this IHostApplicationBuilder builder, string? serviceName = null) { #if NET ArgumentNullException.ThrowIfNull(builder); @@ -30,7 +30,8 @@ public static ISystemWebAdapterBuilder AddSystemWebAdapters(this IHostApplicatio } #endif - var config = builder.Configuration; + serviceName ??= DefaultIncrementalServiceName; + var config = builder.Configuration.GetSection(GetConfigSection(serviceName)); var adapters = builder.Services.AddSystemWebAdapters(); #if NET @@ -61,6 +62,7 @@ public static ISystemWebAdapterBuilder AddSystemWebAdapters(this IHostApplicatio if (config.GetValue(RemoteSessionKey + IsEnabled)) { + adapters.AddSessionSerializer(); remoteConfig.AddSessionServer(config.GetSection(RemoteSessionKey).Bind); } diff --git a/test/Microsoft.AspNetCore.SystemWebAdapters.E2E.Tests/AspireFixtureExtensions.cs b/test/Microsoft.AspNetCore.SystemWebAdapters.E2E.Tests/AspireFixtureExtensions.cs new file mode 100644 index 0000000000..70418d7829 --- /dev/null +++ b/test/Microsoft.AspNetCore.SystemWebAdapters.E2E.Tests/AspireFixtureExtensions.cs @@ -0,0 +1,54 @@ +using Aspire.Hosting; +using Aspire.Hosting.ApplicationModel; +using Azure; +using Microsoft.Extensions.Hosting; +using Xunit; +using Xunit.Abstractions; + +namespace Microsoft.AspNetCore.SystemWebAdapters.E2E.Tests; + +internal static class AspireFixtureExtensions +{ + public static IResource GetResource(this DistributedApplication app, string resourceName) + { + ThrowIfNotStarted(app); + + var applicationModel = app.Services.GetRequiredService(); + + var resources = applicationModel.Resources; + var resource = resources.SingleOrDefault(r => string.Equals(r.Name, resourceName, StringComparison.OrdinalIgnoreCase)); + + ArgumentNullException.ThrowIfNull(resource); + + return resource; + } + + public static async Task>> GetIncrementalMigrationEnvironmentVariableValuesAsync(this AspireFixture fixture, string resourceName, ITestOutputHelper output) + where TEntryPoint : class + { + var app = await fixture.GetApplicationAsync(); + var resource = Assert.IsAssignableFrom(app.GetResource(resourceName)); + var values = await resource.GetEnvironmentVariableValuesAsync(DistributedApplicationOperation.Publish); + var filtered = values.Where(s => s.Key.StartsWith("IncrementalMigration__", StringComparison.Ordinal)).OrderBy(s => s.Key).ToList(); + + output.WriteLine($"Environment variables for resource '{resourceName}':"); + + foreach (var kvp in filtered) + { + output.WriteLine($"{kvp.Key} = {kvp.Value}"); + } + + output.WriteLine("---------------------------------"); + + return filtered; + } + + static void ThrowIfNotStarted(DistributedApplication app) + { + var lifetime = app.Services.GetRequiredService(); + if (!lifetime.ApplicationStarted.IsCancellationRequested) + { + throw new InvalidOperationException("App not started"); + } + } +} diff --git a/test/Microsoft.AspNetCore.SystemWebAdapters.E2E.Tests/RemoteAuthFormsTests.cs b/test/Microsoft.AspNetCore.SystemWebAdapters.E2E.Tests/RemoteAuthFormsTests.cs index d7f381c106..e009a29420 100644 --- a/test/Microsoft.AspNetCore.SystemWebAdapters.E2E.Tests/RemoteAuthFormsTests.cs +++ b/test/Microsoft.AspNetCore.SystemWebAdapters.E2E.Tests/RemoteAuthFormsTests.cs @@ -1,11 +1,61 @@ +using System.Globalization; using Aspire.Hosting; using Microsoft.Playwright.Xunit; using Xunit; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.SystemWebAdapters.E2E.Tests; -public class RemoteAuthFormsTests(AspireFixture aspire) : DebugPageTest, IClassFixture> +public class RemoteAuthFormsTests(ITestOutputHelper output, AspireFixture aspire) : DebugPageTest, IClassFixture> { + [Fact] + public async Task EnvironmentVariablesSet() + { + // Arrange + var coreEnvVariables = await aspire.GetIncrementalMigrationEnvironmentVariableValuesAsync("core", output); + var frameworkEnvVariables = await aspire.GetIncrementalMigrationEnvironmentVariableValuesAsync("framework", output); + + // Act + Assert.Collection(coreEnvVariables, + kvp => + { + Assert.Equal("IncrementalMigration__Default__Remote__ApiKey", kvp.Key); + Assert.Equal("{Default-IncrementalMigration-ApiKey.value}", kvp.Value); + }, + kvp => + { + Assert.Equal("IncrementalMigration__Default__Remote__Authentication__IsDefaultScheme", kvp.Key); + Assert.Equal("True", kvp.Value); + }, + kvp => + { + Assert.Equal("IncrementalMigration__Default__Remote__Authentication__IsEnabled", kvp.Key); + Assert.Equal("True", kvp.Value); + }, + kvp => + { + Assert.Equal("IncrementalMigration__Default__Remote__RemoteAppUrl", kvp.Key); + Assert.Equal("{framework.bindings.https.url}", kvp.Value); + }); + + Assert.Collection(frameworkEnvVariables, + kvp => + { + Assert.Equal("IncrementalMigration__Default__Proxy__UseForwardedHeaders", kvp.Key); + Assert.Equal("True", kvp.Value); + }, + kvp => + { + Assert.Equal("IncrementalMigration__Default__Remote__ApiKey", kvp.Key); + Assert.Equal("{Default-IncrementalMigration-ApiKey.value}", kvp.Value); + }, + kvp => + { + Assert.Equal("IncrementalMigration__Default__Remote__Authentication__IsEnabled", kvp.Key); + Assert.Equal("True", kvp.Value); + }); + } + [Fact] public async Task CoreAppCanLogout() { diff --git a/test/Microsoft.AspNetCore.SystemWebAdapters.E2E.Tests/RemoteAuthIdentityTests.cs b/test/Microsoft.AspNetCore.SystemWebAdapters.E2E.Tests/RemoteAuthIdentityTests.cs index 1ff12f8083..2145af9cfc 100644 --- a/test/Microsoft.AspNetCore.SystemWebAdapters.E2E.Tests/RemoteAuthIdentityTests.cs +++ b/test/Microsoft.AspNetCore.SystemWebAdapters.E2E.Tests/RemoteAuthIdentityTests.cs @@ -2,13 +2,63 @@ using Aspire.Hosting; using Microsoft.AspNetCore.Routing; using Microsoft.Playwright.Xunit; +using Microsoft.VisualStudio.TestPlatform.Utilities; using Projects; using Xunit; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.SystemWebAdapters.E2E.Tests; -public class RemoteAuthIdentityTests(AspireFixture aspire) : DebugPageTest, IClassFixture> +public class RemoteAuthIdentityTests(ITestOutputHelper output, AspireFixture aspire) : DebugPageTest, IClassFixture> { + [Fact] + public async Task EnvironmentVariablesSet() + { + // Arrange + var coreEnvVariables = await aspire.GetIncrementalMigrationEnvironmentVariableValuesAsync("core", output); + var frameworkEnvVariables = await aspire.GetIncrementalMigrationEnvironmentVariableValuesAsync("framework", output); + + // Act + Assert.Collection(coreEnvVariables, + kvp => + { + Assert.Equal("IncrementalMigration__Default__Remote__ApiKey", kvp.Key); + Assert.Equal("{Default-IncrementalMigration-ApiKey.value}", kvp.Value); + }, + kvp => + { + Assert.Equal("IncrementalMigration__Default__Remote__Authentication__IsDefaultScheme", kvp.Key); + Assert.Equal("True", kvp.Value); + }, + kvp => + { + Assert.Equal("IncrementalMigration__Default__Remote__Authentication__IsEnabled", kvp.Key); + Assert.Equal("True", kvp.Value); + }, + kvp => + { + Assert.Equal("IncrementalMigration__Default__Remote__RemoteAppUrl", kvp.Key); + Assert.Equal("{framework.bindings.https.url}", kvp.Value); + }); + + Assert.Collection(frameworkEnvVariables, + kvp => + { + Assert.Equal("IncrementalMigration__Default__Proxy__UseForwardedHeaders", kvp.Key); + Assert.Equal("True", kvp.Value); + }, + kvp => + { + Assert.Equal("IncrementalMigration__Default__Remote__ApiKey", kvp.Key); + Assert.Equal("{Default-IncrementalMigration-ApiKey.value}", kvp.Value); + }, + kvp => + { + Assert.Equal("IncrementalMigration__Default__Remote__Authentication__IsEnabled", kvp.Key); + Assert.Equal("True", kvp.Value); + }); + } + [Fact] public async Task MVCCoreAppCanLogoutBothApps() { diff --git a/test/Microsoft.AspNetCore.SystemWebAdapters.E2E.Tests/RemoteSessionTests.cs b/test/Microsoft.AspNetCore.SystemWebAdapters.E2E.Tests/RemoteSessionTests.cs index 51ae08befb..1a6468776b 100644 --- a/test/Microsoft.AspNetCore.SystemWebAdapters.E2E.Tests/RemoteSessionTests.cs +++ b/test/Microsoft.AspNetCore.SystemWebAdapters.E2E.Tests/RemoteSessionTests.cs @@ -11,6 +11,49 @@ namespace Microsoft.AspNetCore.SystemWebAdapters.E2E.Tests; public class RemoteSessionTests(ITestOutputHelper output, AspireFixture aspire) : DebugPageTest, IClassFixture> { + [Fact] + public async Task EnvironmentVariablesSet() + { + // Arrange + var coreEnvVariables = await aspire.GetIncrementalMigrationEnvironmentVariableValuesAsync("core", output); + var frameworkEnvVariables = await aspire.GetIncrementalMigrationEnvironmentVariableValuesAsync("framework", output); + + // Act + Assert.Collection(coreEnvVariables, + kvp => + { + Assert.Equal("IncrementalMigration__Default__Remote__ApiKey", kvp.Key); + Assert.Equal("{Default-IncrementalMigration-ApiKey.value}", kvp.Value); + }, + kvp => + { + Assert.Equal("IncrementalMigration__Default__Remote__RemoteAppUrl", kvp.Key); + Assert.Equal("{framework.bindings.https.url}", kvp.Value); + }, + kvp => + { + Assert.Equal("IncrementalMigration__Default__Remote__Session__IsEnabled", kvp.Key); + Assert.Equal("True", kvp.Value); + }); + + Assert.Collection(frameworkEnvVariables, + kvp => + { + Assert.Equal("IncrementalMigration__Default__Proxy__UseForwardedHeaders", kvp.Key); + Assert.Equal("True", kvp.Value); + }, + kvp => + { + Assert.Equal("IncrementalMigration__Default__Remote__ApiKey", kvp.Key); + Assert.Equal("{Default-IncrementalMigration-ApiKey.value}", kvp.Value); + }, + kvp => + { + Assert.Equal("IncrementalMigration__Default__Remote__Session__IsEnabled", kvp.Key); + Assert.Equal("True", kvp.Value); + }); + } + [Fact] public async Task SessionTests() { diff --git a/test/Microsoft.AspNetCore.SystemWebAdapters.E2E.Tests/WebFormsToBlazorTests.cs b/test/Microsoft.AspNetCore.SystemWebAdapters.E2E.Tests/WebFormsToBlazorTests.cs index f0b299e43f..4ff4b2eb8c 100644 --- a/test/Microsoft.AspNetCore.SystemWebAdapters.E2E.Tests/WebFormsToBlazorTests.cs +++ b/test/Microsoft.AspNetCore.SystemWebAdapters.E2E.Tests/WebFormsToBlazorTests.cs @@ -1,10 +1,55 @@ +using Microsoft.VisualStudio.TestPlatform.Utilities; using Projects; using Xunit; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.SystemWebAdapters.E2E.Tests; -public class WebFormsToBlazorTests(AspireFixture aspire) : DebugPageTest, IClassFixture> +public class WebFormsToBlazorTests(ITestOutputHelper output, AspireFixture aspire) : DebugPageTest, IClassFixture> { + [Fact] + public async Task EnvironmentVariablesSet() + { + // Arrange + var coreEnvVariables = await aspire.GetIncrementalMigrationEnvironmentVariableValuesAsync("core", output); + var frameworkEnvVariables = await aspire.GetIncrementalMigrationEnvironmentVariableValuesAsync("framework", output); + + // Act + Assert.Collection(coreEnvVariables, + kvp => + { + Assert.Equal("IncrementalMigration__Default__Remote__ApiKey", kvp.Key); + Assert.Equal("{Default-IncrementalMigration-ApiKey.value}", kvp.Value); + }, + kvp => + { + Assert.Equal("IncrementalMigration__Default__Remote__RemoteAppUrl", kvp.Key); + Assert.Equal("{framework.bindings.https.url}", kvp.Value); + }, + kvp => + { + Assert.Equal("IncrementalMigration__Default__Remote__Session__IsEnabled", kvp.Key); + Assert.Equal("True", kvp.Value); + }); + + Assert.Collection(frameworkEnvVariables, + kvp => + { + Assert.Equal("IncrementalMigration__Default__Proxy__UseForwardedHeaders", kvp.Key); + Assert.Equal("True", kvp.Value); + }, + kvp => + { + Assert.Equal("IncrementalMigration__Default__Remote__ApiKey", kvp.Key); + Assert.Equal("{Default-IncrementalMigration-ApiKey.value}", kvp.Value); + }, + kvp => + { + Assert.Equal("IncrementalMigration__Default__Remote__Session__IsEnabled", kvp.Key); + Assert.Equal("True", kvp.Value); + }); + } + [Fact] public async Task CanNavigateToWebFormsPage() {