Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ public class GoAppHostTests
[Fact]
public async Task GoAppHostCompiles()
{
await GoAppHostTest.Run(
await SqlPolyglotAppHostTest.Run(() => GoAppHostTest.Run(
appHostProject: "CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost.Go",
exampleName: "sql-database-projects",
// The prebuilt Windows AppHost server fails to load hostfxr for MSBuildLocator.
validatePublish: !OperatingSystem.IsWindows(),
cancellationToken: TestContext.Current.CancellationToken);
cancellationToken: TestContext.Current.CancellationToken));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests;

internal static class SqlPolyglotAppHostTest
{
private static readonly string[] s_msbuildEnvironmentVariables =
[
"MSBUILD_EXE_PATH",
"MSBuildExtensionsPath",
"MSBuildSDKsPath"
];

public static async Task Run(Func<Task> test)
{
// MSBuildLocator in other SQL tests configures in-process MSBuild; child dotnet builds
// must select their own SDK instead of inheriting those paths.
Dictionary<string, string?> originalValues = s_msbuildEnvironmentVariables.ToDictionary(
name => name, Environment.GetEnvironmentVariable);
try
{
foreach (string name in s_msbuildEnvironmentVariables)
{
Environment.SetEnvironmentVariable(name, null);
}

await test();
}
finally
{
foreach ((string name, string? value) in originalValues)
{
Environment.SetEnvironmentVariable(name, value);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
namespace CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests;

public class SqlPolyglotAppHostTestTests
{
[Fact]
public async Task RestoresMSBuildEnvironmentAfterFailure()
{
string[] variables = ["MSBUILD_EXE_PATH", "MSBuildExtensionsPath", "MSBuildSDKsPath"];
Dictionary<string, string?> originalValues = variables.ToDictionary(name => name, Environment.GetEnvironmentVariable);
try
{
foreach (string variable in variables)
{
Environment.SetEnvironmentVariable(variable, "test-sdk-path");
}

await Assert.ThrowsAsync<InvalidOperationException>(() => SqlPolyglotAppHostTest.Run(() =>
{
foreach (string variable in variables)
{
Assert.Null(Environment.GetEnvironmentVariable(variable));
}

throw new InvalidOperationException();
}));

foreach (string variable in variables)
{
Assert.Equal("test-sdk-path", Environment.GetEnvironmentVariable(variable));
}
}
finally
{
foreach ((string variable, string? value) in originalValues)
{
Environment.SetEnvironmentVariable(variable, value);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ public class TypeScriptAppHostTests
[Fact]
public async Task TypeScriptAppHostCompilesAndStarts()
{
await TypeScriptAppHostTest.Run(
await SqlPolyglotAppHostTest.Run(() => TypeScriptAppHostTest.Run(
appHostProject: "CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost.TypeScript",
packageName: "CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects",
exampleName: "sql-database-projects",
waitForResources: [],
cancellationToken: TestContext.Current.CancellationToken);
cancellationToken: TestContext.Current.CancellationToken));
}
}
Loading