Make AssertEmptyMigration whitespace-insensitive#66792
Open
BrennanConroy wants to merge 1 commit into
Open
Conversation
EF Core now emits generated migration files using file-scoped namespaces (dotnet/efcore@fe85801), which dedents class members by 4 spaces. The literal substring match in AssertEmptyMigration only stripped newlines, so the comparison broke for all template tests that call it (MvcTemplate_IndividualAuth, BlazorTemplate, RazorPagesTemplate, IdentityUIPackageTest). Normalize all whitespace when comparing so the assertion works for both block-scoped and file-scoped namespace output. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the template test helper AssertEmptyMigration to be resilient to EF Core’s migration formatting changes (notably indentation differences from file-scoped namespaces) by making the comparison whitespace-insensitive.
Changes:
- Switches the
AssertEmptyMigrationcheck from newline-stripping to full whitespace normalization before doing the substring comparison. - Replaces the local
RemoveNewLineshelper withNormalizeWhitespace.
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Diagnostics; | ||
| using System.Linq; |
wtgodbe
approved these changes
May 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Template tests that assert a freshly added EF migration is empty (e.g.
MvcTemplate_IndividualAuth,BlazorTemplate,RazorPagesTemplate,IdentityUIPackageTest) started failing with:Root cause
dotnet/efcore@fe85801 changed EF Core's generated code (including migration files) from block-scoped namespaces to file-scoped namespaces. That dedents class members by 4 spaces.
AssertEmptyMigrationdid aContainscheck against a literal string with the old 8-space indentation and only stripped newlines, so it no longer matched the dedented output.Fix
Normalize all whitespace when comparing. The literal only covers the
Up/Downmethod bodies (not the namespace declaration itself), so a whitespace-insensitive substring match still verifies the migration body is empty and works for both block-scoped and file-scoped namespace output.Example failing build: https://dev.azure.com/dnceng-public/public/_build/results?buildId=1430507&view=ms.vss-test-web.build-test-results-tab&runId=39729748&resultId=100063