Skip to content

Make AssertEmptyMigration whitespace-insensitive#66792

Open
BrennanConroy wants to merge 1 commit into
mainfrom
brennanconroy/silver-spork
Open

Make AssertEmptyMigration whitespace-insensitive#66792
BrennanConroy wants to merge 1 commit into
mainfrom
brennanconroy/silver-spork

Conversation

@BrennanConroy
Copy link
Copy Markdown
Member

Problem

Template tests that assert a freshly added EF migration is empty (e.g. MvcTemplate_IndividualAuth, BlazorTemplate, RazorPagesTemplate, IdentityUIPackageTest) started failing with:

Assert.Contains() Failure: Sub-string not found
String:    "using Microsoft.EntityFrameworkCore.Migra"...
Not found: "/// <inheritdoc />        protected overr"...

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.

AssertEmptyMigration did a Contains check 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/Down method 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

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>
Copilot AI review requested due to automatic review settings May 21, 2026 23:11
@github-actions github-actions Bot added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label May 21, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 AssertEmptyMigration check from newline-stripping to full whitespace normalization before doing the substring comparison.
  • Replaces the local RemoveNewLines helper with NormalizeWhitespace.

// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
using System.Linq;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants