Skip to content

Obsolete Assert.Equals and add obsolete Assert.ReferenceEquals#5815

Merged
Evangelink merged 16 commits intomainfrom
copilot/fix-5758
Jun 19, 2025
Merged

Obsolete Assert.Equals and add obsolete Assert.ReferenceEquals#5815
Evangelink merged 16 commits intomainfrom
copilot/fix-5758

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jun 18, 2025

Changes Assert.Equals from throwing an exception to being marked as obsolete, and adds a new obsolete Assert.ReferenceEquals method. This prevents silent failures that would occur if these methods were removed entirely.

Problem

The original plan was to remove Assert.Equals in v4, but this would create a dangerous scenario:

// If Assert.Equals is removed, this code would silently call object.Equals()
// and never actually assert anything - a silent test failure!
Assert.Equals(expected, actual); // Falls back to object.Equals() - no assertion!

Solution

Instead of removal, both methods are now marked with [Obsolete] attributes:

  • Assert.Equals: Now obsolete instead of throwing Assert.Fail()
  • Assert.ReferenceEquals: New obsolete method to prevent similar issues

Both methods consistently return false and guide users to proper alternatives:

  • Assert.Equals → Use Assert.AreEqual and overloads
  • Assert.ReferenceEquals → Use Assert.AreSame and overloads

Implementation Details

  • ✅ Modified Assert.Equals with [Obsolete] attribute
  • ✅ Added new Assert.ReferenceEquals with [Obsolete] attribute
  • ✅ Added DoNotUseAssertReferenceEquals resource string with full localization (13 languages)
  • ✅ Updated PublicAPI.Unshipped.txt for new method
  • ✅ Added unit tests to verify obsolete behavior
  • ✅ Updated XML documentation

Testing

#pragma warning disable CS0618 // Type or member is obsolete
bool result1 = Assert.Equals("test", "test");        // Returns false, shows obsolete warning
bool result2 = Assert.ReferenceEquals(obj, obj);     // Returns false, shows obsolete warning  
#pragma warning restore CS0618 // Type or member is obsolete

This approach provides compile-time warnings while preventing the dangerous silent failure scenario.

Fixes #5758.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 5rqvsblobprodcus385.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/testfx/testfx/.dotnet/dotnet msbuild /m /nologo /clp:Summary /v:minimal /nr:true /warnaserror /p:TreatWarningsAsErrors=true /p:ContinuousIntegrationBuild=false /home/REDACTED/work/testfx/testfx/artifacts/toolset/restore.proj /t:__WriteToolsetLocation /clp:ErrorsOnly;NoSummary /p:__ToolsetLocationOutputFile=/home/REDACTED/work/testfx/testfx/artifacts/toolset/10.0.0-beta.25316.2.txt (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Obsolete Assert.Equals, and add an obsolete ReferenceEquals Obsolete Assert.Equals and add obsolete Assert.ReferenceEquals Jun 18, 2025
Copilot AI requested a review from Evangelink June 18, 2025 12:45
Copy link
Copy Markdown
Member

@Evangelink Evangelink left a comment

Choose a reason for hiding this comment

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

Please so the same job for StringAssert and CollectionAssert classes.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jun 18, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 5rqvsblobprodcus385.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/testfx/testfx/.dotnet/dotnet msbuild /m /nologo /clp:Summary /v:minimal /nr:true /warnaserror /p:TreatWarningsAsErrors=true /p:ContinuousIntegrationBuild=false /home/REDACTED/work/testfx/testfx/artifacts/toolset/restore.proj /t:__WriteToolsetLocation /clp:ErrorsOnly;NoSummary /p:__ToolsetLocationOutputFile=/home/REDACTED/work/testfx/testfx/artifacts/toolset/10.0.0-beta.25316.2.txt (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jun 18, 2025

Please so the same job for StringAssert and CollectionAssert classes.

Done! Added obsolete Equals and ReferenceEquals methods to both StringAssert and CollectionAssert classes following the same pattern as Assert class - using constant string messages from FrameworkConstants and returning false to prevent silent failures. (b6650a9)

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 5rqvsblobprodcus385.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/testfx/testfx/.dotnet/dotnet msbuild /m /nologo /clp:Summary /v:minimal /nr:true /warnaserror /p:TreatWarningsAsErrors=true /p:ContinuousIntegrationBuild=false /home/REDACTED/work/testfx/testfx/artifacts/toolset/restore.proj /t:__WriteToolsetLocation /clp:ErrorsOnly;NoSummary /p:__ToolsetLocationOutputFile=/home/REDACTED/work/testfx/testfx/artifacts/toolset/10.0.0-beta.25316.2.txt (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

# Conflicts:
#	src/TestFramework/TestFramework/FrameworkConstants.cs
#	src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt
Copy link
Copy Markdown
Member

@Evangelink Evangelink left a comment

Choose a reason for hiding this comment

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

For all obsolete Equals and ReferenceEquals API, please instead of returning false ensuring we fail by calling the Assert.Fail API with a localized message.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jun 18, 2025

For all obsolete Equals and ReferenceEquals API, please instead of returning false ensuring we fail by calling the Assert.Fail API with a localized message.

Done! Changed all obsolete Equals and ReferenceEquals methods in Assert, StringAssert, and CollectionAssert to call Assert.Fail with localized messages instead of returning false. Added resource entries to FrameworkMessages.resx and all 13 xlf files, updated unit tests to expect AssertFailedException, and added comprehensive tests for all obsolete methods. (afb61d7)

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 5rqvsblobprodcus385.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/testfx/testfx/.dotnet/dotnet msbuild /m /nologo /clp:Summary /v:minimal /nr:true /warnaserror /p:TreatWarningsAsErrors=true /p:ContinuousIntegrationBuild=false /home/REDACTED/work/testfx/testfx/artifacts/toolset/restore.proj /t:__WriteToolsetLocation /clp:ErrorsOnly;NoSummary /p:__ToolsetLocationOutputFile=/home/REDACTED/work/testfx/testfx/artifacts/toolset/10.0.0-beta.25316.2.txt (dns block)
    • Triggering command: ./.dotnet/dotnet build src/TestFramework/TestFramework/TestFramework.csproj --no-restore --verbosity minimal (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested a review from Evangelink June 18, 2025 15:15
@Evangelink Evangelink marked this pull request as ready for review June 18, 2025 19:17
@Evangelink Evangelink enabled auto-merge (squash) June 18, 2025 19:39
# Conflicts:
#	src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt
Youssef1313
Youssef1313 previously approved these changes Jun 19, 2025
Youssef1313
Youssef1313 previously approved these changes Jun 19, 2025
# Conflicts:
#	src/TestFramework/TestFramework/Resources/FrameworkMessages.Designer.cs
#	src/TestFramework/TestFramework/Resources/FrameworkMessages.resx
@Evangelink Evangelink merged commit 77a4583 into main Jun 19, 2025
8 checks passed
@Evangelink Evangelink deleted the copilot/fix-5758 branch June 19, 2025 09:50
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.

Obsolete Assert.Equals, and add an obsolete ReferenceEquals

3 participants