-
Notifications
You must be signed in to change notification settings - Fork 543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes unit test templates for spaces in names #3959
Conversation
@@ -1,6 +1,6 @@ | |||
using System.Net; | |||
|
|||
namespace Aspire.Tests1; | |||
namespace Aspire.Tests._1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why _1
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I was going to ask this too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh this is required to instruct the template engine which naming convention to use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a pattern that instructs the template engine to do this replacement. See also: https://github.com/dotnet/aspire/blob/main/src/Aspire.ProjectTemplates/templates/aspire-starter/AspireStarterApplication.1.Web/WeatherApiClient.cs#L1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious why it's not needed in the ASP.NET Core templates though https://github.com/dotnet/aspnetcore/blob/eb18cb23cf2be9db70ae799e9b23a74a26e78d0b/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/Controllers/HomeController.cs#L18
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah
namespace Template._1; //uses `namespace` form
Isn't that link suggesting that AspireStarterApplication.1
would be the correct one, and would allow picking which "form" to use for namespace/classname etc, and AspireStarterApplication1
would break it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I made it AspireStarterApplication.1
when we first hit this issue but it still doesn't make the auto-value forms work. But, Aspire.StarerApplication1
would work, so we should just change to that to match what ASP.NET Core and others do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'd recommend sticking with this change only. The change to the others will affect path names as well and you'll change the csproj reference paths. Using this convention allows you to use the value forms and keep the 'identity' form for what the user put in.
Example, if we were to make the change to all. and you dotnet new foo-bar-baz
then the file-paths would not be translated (foo-bar-baz.csproj) but then you'd have sln/project references as foo_bar_baz.csproj.
Honestly it feels safer to look at just this change and keep the others as-is as they are functioning within the template engine value forms (identity + namespace + class).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I admit I'm a bit lost now lol.
Are you saying that if you change the form to Aspire.StarterApplication1
it breaks? Why is it that the ASP.NET Core and Blazor templates work? Also how can you run Explorer with file extensions hidden!!? 😱
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RE: File extensions LOL -- just a sandbox so no customizations -- view hidden always FTW!
But yes, As Ankit also points out the value form scheme allows us to actually achieve what we want. I can't explain why the Blazor ones work (as they have proj ref paths as well) other than the source name uses a dash rather than dot. But the Blazor one is actually broken as well with dashes :-) (root namespace doesn't get corrected)
line 11: |
This works; diff --git a/src/Aspire.ProjectTemplates/templates/aspire-starter/AspireStarterApplication.1.Tests/WebTests.cs b/src/Aspire.ProjectTemplates/templates/aspire-starter/AspireStarterApplication.1.Tests/WebTests.cs
index 26eb9fb66..a0a114dde 100644
--- a/src/Aspire.ProjectTemplates/templates/aspire-starter/AspireStarterApplication.1.Tests/WebTests.cs
+++ b/src/Aspire.ProjectTemplates/templates/aspire-starter/AspireStarterApplication.1.Tests/WebTests.cs
@@ -17,7 +17,7 @@ public class WebTests
public async Task GetWebResourceRootReturnsOkStatusCode()
{
// Arrange
- var appHost = await DistributedApplicationTestingBuilder.CreateAsync<Projects.AspireStarterApplication.1_AppHost>();
+ var appHost = await DistributedApplicationTestingBuilder.CreateAsync<Projects.AspireStarterApplication._1_AppHost>();
await using var app = await appHost.BuildAsync();
await app.StartAsync(); |
@radical I implemented the last one you found...did your local tests find anything else in the template tests? |
@@ -8,7 +8,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspireStarterApplication.1. | |||
EndProject | |||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspireStarterApplication.1.ApiService", "AspireStarterApplication.1.ApiService\AspireStarterApplication.1.ApiService.csproj", "{9FEB877E-015D-4E20-AE63-06C596E242E4}" | |||
EndProject | |||
#if (CreateTestsProject) | |||
#if (TestFramework != 'None') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! I assume you verified this fixes it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@radical do we have test coverage the starter template creation? Can we add this as a case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. I assume the conditionals may be case-insensitive, but matched the literal default value in template config and verified 'None' and 'none' both work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the case that was caught here? Using none
type as the framework generated a test project when it shouldn't have? I check for non-existence of a test project in case of none
but I didn't see it failing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the current shipping templates the option is CreateTestsProject since there was only one type: xunit. Now that we added unit test framework choice, the option changed to TestFramework and is either none (no arg provided so no tests projects), xunit.net, nunit, or mstest
/backport to release/8.0 |
Started backporting to release/8.0: https://github.com/dotnet/aspire/actions/runs/8853529459 |
@timheuer an error occurred while backporting to release/8.0, please check the run log for details! Error: @timheuer is not a repo collaborator, backporting is not allowed. If you're a collaborator please make sure your dotnet team membership visibility is set to Public on https://github.com/orgs/dotnet/people?query=timheuer |
/backport to release/8.0 |
Started backporting to release/8.0: https://github.com/dotnet/aspire/actions/runs/8854015349 |
@DamianEdwards backporting to release/8.0 failed, the patch most likely resulted in conflicts: $ git am --3way --ignore-whitespace --keep-non-patch changes.patch
Applying: Fixes unit test templates for spaces in names Fix #3957
error: mode change for src/Aspire.ProjectTemplates/templates/aspire-mstest/Aspire.Tests1.csproj, which is not in current HEAD
error: could not build fake ancestor
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 Fixes unit test templates for spaces in names Fix #3957
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128 Please backport manually! |
@DamianEdwards an error occurred while backporting to release/8.0, please check the run log for details! Error: git am failed, most likely due to a merge conflict. |
@timheuer looks like you'll need to manually backport |
Fix #3957 and #3974
dotnet new aspire-starter -t xunit.net -o asp-starter-with-redis-with-xunit0
dotnet new
withaspire-xunit
,aspire-nunit
,aspire-mstest
using various hyphenated namesMicrosoft Reviewers: Open in CodeFlow