Skip to content

Add ASP.NET Core testing series samples on .NET 10 - #2118

Open
vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/48759-aspnetcore-unit-testing-xunit
Open

Add ASP.NET Core testing series samples on .NET 10#2118
vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/48759-aspnetcore-unit-testing-xunit

Conversation

@vladimir-pecanac-main

Copy link
Copy Markdown
Collaborator

Brings the whole Testing ASP.NET Core Applications series into this repository, one folder per article under dotnet-testing/AspNetCoreTestingSeries, so the samples build and their tests run in CI like every other sample here. The code came from the separate testing-aspnetcore-mvc repository, where it lived on six branches and had not been touched since 2021.

LayoutStartingProject (the app the series starts from), UnitTestingWithXUnit, TestingMvcControllers, IntegrationTestingMvc, TestingAntiForgeryToken, UiTestingSelenium. Each folder has its own solution so a reader can open just the article they are on; AspNetCoreTestingSeries.sln builds and tests all six together.

What had to change to get it running on .NET 10

  • Every project retargeted to net10.0, with EF Core, ASP.NET Core testing, xUnit, Moq, Selenium and the test SDK moved to current releases. The apps were still referencing EF Core 6.0.0-rc previews.
  • Four of the six projects did not compile at all: Migrations/ held two InitialMigration classes in one namespace, one from EF Core 2.2 and one from 6.0. The model snapshot matches the 2021 one, so the 2.2 leftover is removed.
  • AccountNumberValidation.IsValid now takes a nullable string and rejects a null or empty account number, instead of the controller passing Employee.AccountNumber (string?) into a non-nullable parameter.
  • TestingWebAppFactory removes IDbContextOptionsConfiguration<EmployeeContext> as well as DbContextOptions<EmployeeContext>. Removing only the options is no longer enough — EF Core keeps the provider registration separately, so the SQL Server and in-memory providers both ended up registered and every integration test failed.
  • The Selenium UI tests drive a real browser against the app on https://localhost:5001, so they cannot run unattended. They are built as part of the solution but excluded from automated test discovery, and Selenium Manager now resolves ChromeDriver instead of a package pinned to Chrome 95.

Verification — all six solutions build on .NET 10.0.10 and all 90 tests pass (78 unit, 12 integration; the 3 Selenium UI tests are build-only, as described above).

The wwwroot/lib folders are the vendored Bootstrap/jQuery assets that ship with each copy of the app, matching how the other MVC samples in this repository are stored.

Bring the whole "Testing ASP.NET Core Applications" series into this
repository, one folder per article under
dotnet-testing/AspNetCoreTestingSeries, so the samples build and their
tests run in CI like every other sample here.

- StartingProject, UnitTestingWithXUnit, TestingMvcControllers,
  IntegrationTestingMvc, TestingAntiForgeryToken and UiTestingSelenium,
  each with its own solution, plus a convenience solution that builds
  all six together.
- Retarget every project to net10.0 and move EF Core, ASP.NET Core
  testing, xUnit, Moq, Selenium and the test SDK to current releases
  (the apps were still on EF Core 6.0.0-rc previews).
- Remove the duplicate InitialMigration left over from EF Core 2.2. It
  clashed with the 2021 migration the model snapshot actually matches,
  and it stopped four of the six projects from compiling at all.
- Handle a null account number in AccountNumberValidation instead of
  passing a nullable string into a non-nullable parameter from the
  controller.
- Swap the database provider in TestingWebAppFactory the way EF Core 10
  needs it, removing the options configuration as well as the options
  themselves, so the integration tests run against the in-memory
  provider again.
- The Selenium UI tests need a browser and a running application, so
  they are built but left out of automated test discovery, and Selenium
  Manager now supplies ChromeDriver instead of a pinned package.

All six solutions build on .NET 10 and all 90 tests pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant