Test | Convert DateTimeVariantTests to xunit#4196
Open
mdaigle wants to merge 18 commits into
Open
Conversation
Remove the [Collection], [Trait("Category", "flaky")] attributes and
CultureInfo workaround. These were masking underlying issues that will
be addressed by converting to direct xunit assertions.
Convert DateTimeVariantTests from a single monolithic test to xunit [ConditionalTheory] with [MemberData] providing parameterized test cases for each date/time type combination. Each test case now calls SendInfo on its specific (value, typeName, baseTypeName) combination and compares against its own per-test baseline file. Remove the TestAllDateTimeWithDataTypeAndVariant dispatch method from DateTimeVariantTest since each test case now invokes SendInfo directly. Make SendInfo public and pass the connection string explicitly.
Split test logic from error handling in DateTimeVariantTest.cs. Each test method now separates the core SQL operations from the try/catch exception handling. Consolidate error handling patterns across all 16 test variations. Pull some expected errors up into parameterized test input in DateTimeVariantTests.cs so callers declare which exceptions are expected. Remove exception handlers that are no longer needed.
Add TestVariations enum to explicitly identify each of the 16 test methods (TestSimpleParameter_Type, TestSimpleParameter_Variant, TVP variations, DataReader, BulkCopy, etc.). Associate expected exceptions with specific test variations in DateTimeVariantTests using dictionaries passed through MemberData. Register expected-but-uncaught exceptions so they can be tracked and asserted later.
Consolidate verification into a single method. Simplify date comparison logic. Remove unnecessary checks, casts, and unused parameters from the helper methods. Pull expected value mismatches and unexpected value overrides up into the parameterized test input so each test case declares its full expected behavior upfront.
Add xunit Assert.Equal/Assert.True for exception validation, value comparison, type checking, and base type verification. Replace all console output logging with direct assertions: - Exception logs → Assert.True with ExceptionChecker delegates - Value mismatch logs → Assert.Equal with expected value overrides - Type mismatch logs → Assert.Equal for type comparison - Base type mismatch logs → Assert.Equal with base type overrides Remove unused display methods. The baseline .bsl files are now empty since all verification is done through assertions.
All verification is now done through xunit assertions. The baseline .bsl files are empty and no longer needed. Remove the 16 per-test baseline files and the DateTimeVariant glob Content entry from the csproj.
Remove unused helper methods, description strings, and unnecessary casts from DateTimeVariantTest.cs. Consolidate exception checker delegates and value override dictionaries in DateTimeVariantTests.cs. Split test cases into separate methods and add missing expected values. Fix type comparison to remove cast exception.
Move all helper methods (xsql, DropStoredProcedure, DropTable, DropType, GetSqlDbType, RunTest) and the ExceptionChecker delegates from the old DateTimeVariantTest.cs static class into DateTimeVariantTests.cs. Each test variation is now a separate [ConditionalTheory] test method directly in the test class. Remove DateTimeVariantTest.cs and its csproj entry.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the manual DateTime/sql_variant coverage from a baseline-file-driven harness into xUnit ConditionalTheory test cases, and removes the legacy helper/baseline artifacts.
Changes:
- Replaced the single baseline-comparison test runner with multiple
[MemberData]-driven theory tests for different API paths (simple params, TVPs, bulk copy, reader paths). - Deleted the legacy
DateTimeVariantTest.csharness and theDateTimeVariant.bslbaseline file. - Updated the ManualTests project file to stop compiling/copying the removed files.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/DateTimeVariantTests.cs | Reworked DateTime variant testing into xUnit theory-based tests with shared runner/helpers. |
| src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/DateTimeVariantTest.cs | Removed legacy standalone test harness implementation. |
| src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/DateTimeVariant.bsl | Removed baseline output file previously used for comparison. |
| src/Microsoft.Data.SqlClient/tests/ManualTests/Microsoft.Data.SqlClient.ManualTests.csproj | Removed compile/content entries for the deleted harness and baseline file. |
Date/time formatting in the test helpers (e.g. DateTime.ToString("M/d/yyyy"))
is locale-dependent. On Linux, the default culture may not be en-US,
causing SQL INSERT statements to produce values the server cannot parse.
Wrap RunTest with CultureInfo("en-US") to ensure consistent formatting.
paulmedynski
previously approved these changes
Apr 24, 2026
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
edwardneal
reviewed
May 6, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4196 +/- ##
==========================================
- Coverage 65.96% 64.34% -1.62%
==========================================
Files 275 270 -5
Lines 42993 65777 +22784
==========================================
+ Hits 28361 42326 +13965
- Misses 14632 23451 +8819
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
cheenamalhotra
previously approved these changes
May 7, 2026
paulmedynski
approved these changes
May 8, 2026
paulmedynski
previously requested changes
May 8, 2026
…t/SqlClient into dev/mdaigle/datetime-xunit
Co-authored-by: Copilot <copilot@github.com>
cheenamalhotra
approved these changes
May 12, 2026
Changes addressed by author.
paulmedynski
approved these changes
May 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Parameterizes tests using shared test data. Expected exceptions are made explicit in test data. Logging and baseline file comparisons are replaced with assertions.
Each commit can be reviewed individually to see the logical progression of the conversion.