Skip to content

Conversation

@benrr101
Copy link
Contributor

@benrr101 benrr101 commented Jan 7, 2026

Description

Pulling together a few PRs from some test work I did over the holidays. This PR:

  • Moves SqlError tests to the UnitTest project (they are indeed just unit tests)
  • Moves SqlErrorCollection tests to the UnitTest project (they are also just unit tests)
  • Some improvements to the tests.

Issues

N/A

Testing

Tests run locally and seem to work in the draft runs I did previously

@benrr101 benrr101 requested a review from a team as a code owner January 7, 2026 19:24
Copilot AI review requested due to automatic review settings January 7, 2026 19:24
@benrr101 benrr101 added the Area\Tests Issues that are targeted to tests or test projects label Jan 7, 2026
Copy link
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

This PR reorganizes test files by moving SqlError and SqlErrorCollection tests from the FunctionalTests project to the UnitTests project, making them truly isolated unit tests that don't require a SQL Server connection.

  • Migrates SqlError serialization test from FunctionalTests to UnitTests with improved test structure
  • Adds comprehensive SqlErrorCollection unit tests covering collection operations, indexing, enumeration, and copy operations
  • Removes dependency on SQL Server connection for these tests by using internal constructors directly

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/SqlErrorTests.cs New unit test file for SqlError with serialization round-trip test
src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/SqlErrorCollectionTests.cs New comprehensive unit test file for SqlErrorCollection with tests for Add, CopyTo, GetEnumerator, and Indexer operations
src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlErrorTest.cs Removes old functional test file that required SQL Server connection
src/Microsoft.Data.SqlClient/tests/FunctionalTests/Microsoft.Data.SqlClient.FunctionalTests.csproj Removes reference to deleted SqlErrorTest.cs file

{
// Arrange
DataContractSerializer serializer = new(typeof(SqlError));
MemoryStream stream = new();
Copy link

Copilot AI Jan 7, 2026

Choose a reason for hiding this comment

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

The MemoryStream should be disposed after use to properly release resources. Consider wrapping it in a using statement or using declaration.

Suggested change
MemoryStream stream = new();
using MemoryStream stream = new();

Copilot uses AI. Check for mistakes.
Comment on lines +222 to +223
exception: new Exception(),
batchIndex: 345);
Copy link

Copilot AI Jan 7, 2026

Choose a reason for hiding this comment

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

Each test creates a new Exception object for the SqlError, which could be replaced with a shared static Exception instance or null if the exception value isn't being tested. This would make the tests more efficient and clearer about what's actually being tested.

Copilot uses AI. Check for mistakes.
errorMessage: "bar",
procedure: "baz",
lineNumber: 234,
exception: new Exception(),
Copy link

Copilot AI Jan 7, 2026

Choose a reason for hiding this comment

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

The Exception created here doesn't need to be a new instance since its actual content isn't being meaningfully tested. Consider using null or a shared static Exception instance to make it clearer that the exception value itself isn't the focus of this serialization test.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area\Tests Issues that are targeted to tests or test projects

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants