aspire
aspire copied to clipboard
[tests] Fix generation of random ids for projects
In Aspire.Workload.Tests, Path.GetRandomFile() is used to generate part of the project id, like
jdzjmany.try, and that is used to generate the namespace names like
starter_test.Debug-nunit_jdzjmany.try.Web. But this generated
namespace name invalid because of the .try.
The fix is to sanitize the string returned from Path.GetRandomFile()
for use as an identifier.
The failures shows up as a build error:
C:\h\w\ABEA0983\t\testroot\starter test.Debug-nunit_jdzjmany.try\starter test.Debug-nunit_jdzjmany.try.Web\Program.cs(1,41): error CS1001: Identifier expected
C:\h\w\ABEA0983\t\testroot\starter test.Debug-nunit_jdzjmany.try\starter test.Debug-nunit_jdzjmany.try.Web\Program.cs(1,41): error CS1002: ; expected
C:\h\w\ABEA0983\t\testroot\starter test.Debug-nunit_jdzjmany.try\starter test.Debug-nunit_jdzjmany.try.Web\Program.cs(1,44): error CS1514: { expected
C:\h\w\ABEA0983\t\testroot\starter test.Debug-nunit_jdzjmany.try\starter test.Debug-nunit_jdzjmany.try.Web\Program.cs(1,44): error CS1513: } expected
C:\h\w\ABEA0983\t\testroot\starter test.Debug-nunit_jdzjmany.try\starter test.Debug-nunit_jdzjmany.try.Web\Program.cs(2,41): error CS1001: Identifier expected
C:\h\w\ABEA0983\t\testroot\starter test.Debug-nunit_jdzjmany.try\starter test.Debug-nunit_jdzjmany.try.Web\Program.cs(2,41): error CS1002: ; expected
C:\h\w\ABEA0983\t\testroot\starter test.Debug-nunit_jdzjmany.try\starter test.Debug-nunit_jdzjmany.try.Web\Program.cs(2,44): error CS1514: { expected
C:\h\w\ABEA0983\t\testroot\starter test.Debug-nunit_jdzjmany.try\starter test.Debug-nunit_jdzjmany.try.Web\Program.cs(2,44): error CS1513: } expected
C:\h\w\ABEA0983\t\testroot\starter test.Debug-nunit_jdzjmany.try\starter test.Debug-nunit_jdzjmany.try.Web\Program.cs(43,11): error CS1513: } expected
C:\h\w\ABEA0983\t\testroot\starter test.Debug-nunit_jdzjmany.try\starter test.Debug-nunit_jdzjmany.try.Web\WeatherApiClient.cs(1,45): error CS1001: Identifier expected
C:\h\w\ABEA0983\t\testroot\starter test.Debug-nunit_jdzjmany.try\starter test.Debug-nunit_jdzjmany.try.Web\WeatherApiClient.cs(1,49): error CS0116: A namespace cannot directly contain members such as fields, methods or statements
C:\h\w\ABEA0983\t\testroot\starter test.Debug-nunit_jdzjmany.try\starter test.Debug-nunit_jdzjmany.try.Web\WeatherApiClient.cs(1,45): error CS1514: { expected
C:\h\w\ABEA0983\t\testroot\starter test.Debug-nunit_jdzjmany.try\starter test.Debug-nunit_jdzjmany.try.Web\WeatherApiClient.cs(1,48): error CS1022: Type or namespace definition, or end-of-file expected
C:\h\w\ABEA0983\t\testroot\starter test.Debug-nunit_jdzjmany.try\starter test.Debug-nunit_jdzjmany.try.Web\WeatherApiClient.cs(1,52): error CS1022: Type or namespace definition, or end-of-file expected
C:\h\w\ABEA0983\t\testroot\starter test.Debug-nunit_jdzjmany.try\starter test.Debug-nunit_jdzjmany.try.Web\WeatherApiClient.cs(29,2): error CS1513: } expected
starter test.Debug-nunit_jdzjmany.try.ApiService -> C:\h\w\ABEA0983\t\testroot\starter test.Debug-nunit_jdzjmany.try\starter test.Debug-nunit_jdzjmany.try.ApiService\bin\Debug\net9.0\starter test.Debug-nunit_jdzjmany.try.ApiService.dll
Similar issue was seen in dotnet/runtime - https://github.com/dotnet/runtime/commit/26990158d9725aa55d0af81f050a7a8e90c35f58