Skip to content

Replace Assert.NotNull with Assert.Empty in AsyncEnumerable SequenceTests #117821

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 18, 2025

This PR updates the test assertions in SequenceTests.cs for System.Linq.AsyncEnumerable to replace all Assert.NotNull calls with Assert.Empty calls, reflecting updated test expectations.

Changes Made

  • Line 56: Changed Assert.NotNull(AsyncEnumerable.Sequence(...)) to Assert.Empty(AsyncEnumerable.Sequence(...))
  • Line 66: Changed Assert.NotNull(AsyncEnumerable.Sequence(...)) to Assert.Empty(AsyncEnumerable.Sequence(...))
  • Line 71: Changed Assert.NotNull(AsyncEnumerable.Sequence(...)) to Assert.Empty(AsyncEnumerable.Sequence(...))

Context

The modified assertions are within the EndOutOfRange_Throws test method, specifically in the ValidateUnsigned<T>() and ValidateSigned<T>() helper methods. These changes represent a semantic shift from verifying that sequences are not null to verifying that they contain no elements.

Test Impact

⚠️ Note: This change represents a significant semantic shift in test expectations. The original Assert.NotNull assertions were verifying that the AsyncEnumerable.Sequence() method returns a non-null sequence, while the new Assert.Empty assertions verify that the sequences contain no elements.

According to the current implementation of AsyncEnumerable.Sequence(), the method always returns at least one element (the start value) and never returns an empty sequence. The test cases being modified include:

  • AsyncEnumerable.Sequence(123, 123, 0) - returns [123]
  • AsyncEnumerable.Sequence(123, 124, 1) - returns [123, 124]
  • AsyncEnumerable.Sequence(123, 122, -1) - returns [123, 122]

This change may indicate that either:

  1. The test expectations have been updated to reflect new requirements
  2. The implementation of AsyncEnumerable.Sequence() is expected to change
  3. These specific parameter combinations should now throw exceptions instead of returning sequences

Files Modified

  • src/libraries/System.Linq.AsyncEnumerable/tests/SequenceTests.cs

This pull request was created as a result of the following prompt from Copilot chat.

In the SequenceTests file for AsyncEnumerable, replace all Assert.NotNull calls with Assert.Empty calls. This change should ensure that any test currently asserting that a value is not null will instead assert that the value is empty, which may reflect a more accurate or updated test expectation. Only modify Assert.NotNull usages within this file and do not alter other assertions or files. Ensure all tests continue to run successfully after the change.


💡 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 Copilot AI changed the title [WIP] Replace Assert.NotNull with Assert.Empty in AsyncEnumerable SequenceTests file Replace Assert.NotNull with Assert.Empty in AsyncEnumerable SequenceTests Jul 18, 2025
@Copilot Copilot AI requested a review from stephentoub July 18, 2025 16:45
Copilot finished work on behalf of stephentoub July 18, 2025 16:45
@stephentoub
Copy link
Member

@copilot, these should probably all be Assert.Single rather than Assert.Empty.

Copy link
Contributor Author

Copilot AI commented Jul 18, 2025

@copilot, these should probably all be Assert.Single rather than Assert.Empty.

I've implemented your suggestion with some refinements. Changed the assertions to use Assert.Single for cases that return exactly one element, and Assert.Equal(2, sequence.CountAsync().Result) for cases that return two elements. The specific behavior depends on the step size relative to the distance between start and end values. All tests now pass. Commit: 5ed6fdd

@stephentoub stephentoub marked this pull request as ready for review July 19, 2025 00:57
@Copilot Copilot AI review requested due to automatic review settings July 19, 2025 00:57
@stephentoub stephentoub enabled auto-merge (squash) July 19, 2025 00:57
Copy link
Contributor

@Copilot 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

This PR replaces Assert.NotNull calls with more specific assertions in the AsyncEnumerable SequenceTests, changing from null checks to element count verification. The changes improve test precision by verifying actual sequence behavior rather than just non-nullness.

  • Replaced generic Assert.NotNull calls with specific count assertions (Assert.Equal, Assert.Single)
  • Added detailed comments explaining expected sequence behavior for different step values
  • Refactored loop-based assertions into explicit test cases with clear expectations

@stephentoub
Copy link
Member

@copilot, does the similar SequenceTests in System.Linq for Enumerable have the same issues with the corresponding asserts? If so, can you fix those, too?

auto-merge was automatically disabled July 19, 2025 01:23

Head branch was pushed to by a user without write access

Copy link
Contributor Author

Copilot AI commented Jul 19, 2025

@copilot, does the similar SequenceTests in System.Linq for Enumerable have the same issues with the corresponding asserts? If so, can you fix those, too?

Yes, the System.Linq SequenceTests had the exact same Assert.NotNull issues. I've fixed them using the same approach - replacing with Assert.Single for cases that return one element and Assert.Equal with Count() for cases that return two elements. All tests pass. Commit: 1496c27

@Copilot Copilot AI requested a review from stephentoub July 19, 2025 01:24
Copilot finished work on behalf of stephentoub July 19, 2025 01:24
Copilot finished work on behalf of stephentoub July 19, 2025 01:43
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.

2 participants