Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Jun 19, 2025

Conversation

Copilot
Copy link
Contributor

@Copilot 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 and others added 3 commits June 18, 2025 12:34
…enceEquals

Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
@Copilot 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 finished work on behalf of Evangelink June 18, 2025 12:45
@Copilot Copilot AI requested a review from Evangelink June 18, 2025 12:45
Copy link
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.

Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copy link
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:

@Copilot Copilot AI requested a review from Evangelink June 18, 2025 13:42
Copilot finished work on behalf of Evangelink June 18, 2025 13:42
…ollectionAssert

Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copy link
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:

Copilot finished work on behalf of Evangelink June 18, 2025 13:49
# Conflicts:
#	src/TestFramework/TestFramework/FrameworkConstants.cs
#	src/TestFramework/TestFramework/PublicAPI/PublicAPI.Unshipped.txt
Copy link
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.

Evangelink and others added 2 commits June 18, 2025 17:01
…l with localized messages

Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copy link
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 Copilot AI requested a review from Evangelink June 18, 2025 15:15
Copilot finished work on behalf of 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