Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

DamianEdwards
Copy link
Member

@DamianEdwards DamianEdwards commented Oct 5, 2024

This updates the starter template with changes from the relevant ASP.NET Core 9 templates.

  • net8 version gets just a Bootstrap update & some accessibility fixes
  • net9 version gets all changes

Contributes to #6076

Microsoft Reviewers: Open in CodeFlow

- net8 version gets just a Bootstrap update
- net9 version gets all changes
@DamianEdwards DamianEdwards marked this pull request as draft October 7, 2024 16:41
@DamianEdwards DamianEdwards marked this pull request as ready for review October 7, 2024 16:44
@eerhardt
Copy link
Member

eerhardt commented Oct 7, 2024

            Endpoints: ["http://localhost:\\d+", "https://localhost:\\d+"]),

Why are we changing this test? Shouldn't we still be hitting this endpoint?


Refers to: tests/Aspire.Workload.Tests/StarterTemplateRunTestsBase.cs:122 in f3d49cf. [](commit_id = f3d49cf, deletion_comment = False)

@DamianEdwards
Copy link
Member Author

Why are we changing this test? Shouldn't we still be hitting this endpoint?

Because the launchUrl was changed and the test was failing as it was attempting to verify the endpoints showed up in the dashboard.

@eerhardt
Copy link
Member

eerhardt commented Oct 7, 2024

Why are we changing this test? Shouldn't we still be hitting this endpoint?

Because the launchUrl was changed and the test was failing as it was attempting to verify the endpoints showed up in the dashboard.

@radical - should the test be hitting this endpoint and ensure it "works" (returns a success status code)? Or does that happen elsewhere?

@radical
Copy link
Member

radical commented Oct 7, 2024

Why are we changing this test? Shouldn't we still be hitting this endpoint?

Because the launchUrl was changed and the test was failing as it was attempting to verify the endpoints showed up in the dashboard.

@radical - should the test be hitting this endpoint and ensure it "works" (returns a success status code)? Or does that happen elsewhere?

The endpoint tried is what it finds on the dashboard, and checks that it is the weather page. For the redis cache case, this method checks the returned results too.

public static async Task CheckWebFrontendWorksAsync(IBrowserContext context, string url, ITestOutputHelper testOutput, string logPath, bool hasRedisCache = false)
{
var page = await context.NewPageWithLoggingAsync(testOutput);
try
{
// Enabling routing disables the http cache
await page.RouteAsync("**", async route => await route.ContinueAsync());
await page.GotoAsync(url);
await page.GetByRole(AriaRole.Link, new PageGetByRoleOptions { Name = "Weather" }).ClickAsync();
var tableLoc = page.Locator("//table[//thead/tr/th/text()='Date']");
await Expect(tableLoc).ToBeVisibleAsync();
if (hasRedisCache)
{
// Compare weather data after refreshes
var firstLoadText = string.Join(',', (await GetAndValidateCellTexts(tableLoc)).SelectMany(r => r));
await Task.Delay(10_000);
await page.ReloadAsync(new PageReloadOptions { WaitUntil = WaitUntilState.Load });
var secondLoadText = string.Join(',', (await GetAndValidateCellTexts(tableLoc)).SelectMany(r => r));
Assert.NotEqual(firstLoadText, secondLoadText);
}
}
catch (Exception ex)
{
testOutput.WriteLine($"Error: {ex}");
string screenshotPath = Path.Combine(logPath, "webfrontend-fail.png");
await page.ScreenshotAsync(new PageScreenshotOptions { Path = screenshotPath });
throw;
}
static async Task<List<string[]>> GetAndValidateCellTexts(ILocator tableLoc)
{
List<string[]> cellTexts = [];
var rowsLoc = tableLoc.Locator("//tbody/tr");
foreach (var row in await rowsLoc.AllAsync())
{
var texts = (await row.Locator("//td").AllAsync())
.Select(cell => cell.InnerHTMLAsync())
.Select(t => t.Result)
.ToArray();
cellTexts.Add(texts);
}
foreach (var row in cellTexts)
{
Assert.Collection(row,
r => Assert.True(DateTime.TryParse(r, out _)),
r => Assert.True(int.TryParse(r, out var actualTempC) && actualTempC >= -20 && actualTempC <= 55),
r => Assert.True(int.TryParse(r, out var actualTempF) && actualTempF >= -5 && actualTempF <= 133),
r => Assert.Contains(r, new HashSet<string>{"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"}));
}
return cellTexts;
}
}

@radical
Copy link
Member

radical commented Oct 7, 2024

We'll need to add a check for the /weatherforecast endpoint explicitly.

@radical
Copy link
Member

radical commented Oct 7, 2024

I think we should test the 8.0 starter template too, so it doesn't regress.

@DamianEdwards
Copy link
Member Author

DamianEdwards commented Oct 7, 2024

We'll need to add a check for the /weatherforecast endpoint explicitly.

@radical OK. Where would that go? Another test method on StarterTemplateRunTestsBase<T> ?

@radical
Copy link
Member

radical commented Oct 7, 2024

We'll need to add a check for the /weatherforecast endpoint explicitly.

@radical OK. Where would that go? Another test method on StarterTemplateRunTestsBase<T> ?

Since this would be just checking that the endpoint exists, I would add it to AssertStarterTemplateRunAsync in WorkloadTestsBase.

@DamianEdwards
Copy link
Member Author

Since this would be just checking that the endpoint exists

@radical not quite following. Wouldn't we want it to send a request and verify the result? What do you mean by "checking the endpoint exists"?

@radical
Copy link
Member

radical commented Oct 7, 2024

Since this would be just checking that the endpoint exists

@radical not quite following. Wouldn't we want it to send a request and verify the result? What do you mean by "checking the endpoint exists"?

Sure, that makes sense. You can add a method to that class, and call from AssertStarterTemplateRunAsync so it gets used by any test checking the starter template.

@radical
Copy link
Member

radical commented Oct 7, 2024

I think we should test the 8.0 starter template too, so it doesn't regress.

Using the DefaultTargetFramework thing that I mentioned in the other comment, you can skip this part, as it will get covered in running all the tests with tfm=net8.0 .

@radical
Copy link
Member

radical commented Oct 7, 2024

I have added tfm=net8.0 variants of the starter template tests. I think the templates that explicitly differ should get checked on the PRs to, so I added them here, instead of depending on an OOB test run.

@radical
Copy link
Member

radical commented Oct 10, 2024

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@DamianEdwards
Copy link
Member Author

@radical yay this is passing! Now we can focus on the content getting approved 😄

@DamianEdwards DamianEdwards mentioned this pull request Oct 12, 2024
9 tasks
Copy link
Member

@joperezr joperezr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good, other than the two comments I left. Other than that this seems like good to go, thanks @DamianEdwards

@DamianEdwards
Copy link
Member Author

Looks like a Helix timeout for the Linux leg 😞

<NpgsqlEntityFrameworkCorePostgreSQLPackageVersion>8.0.8</NpgsqlEntityFrameworkCorePostgreSQLPackageVersion>
<!-- for templates -->
<MicrosoftExtensionsHttpResiliencePackageVersionForNet8>$(MicrosoftExtensionsHttpResiliencePackageVersion)</MicrosoftExtensionsHttpResiliencePackageVersionForNet8>
<MicrosoftExtensionsHttpResiliencePackageVersionForNet9>$(MicrosoftExtensionsHttpResiliencePackageVersion)</MicrosoftExtensionsHttpResiliencePackageVersionForNet9>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the story with MicrosoftExtensionsHttpResiliencePackageVersionForNet9? It has the same version as "ForNet8". Shouldn't these 2 versions be separate, so when I get a .NET 9 app, I get the 9.0 Resilience package?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, it's listed in #6076 as a TODO

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to address the remaining content items in #6076 as part of the next PR which refactors the templates down to a single template you can select TFM and Aspire version from.

@DamianEdwards DamianEdwards merged commit 269864e into main Oct 17, 2024
9 checks passed
@DamianEdwards DamianEdwards deleted the damianedwards/update-starter-web-net9 branch October 17, 2024 22:33
@github-actions github-actions bot locked and limited conversation to collaborators Dec 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants