Tests | Add collation transcoding tests#4051
Open
edwardneal wants to merge 2 commits intodotnet:mainfrom
Open
Conversation
This previously only tested Kazakh_90_CI_AI and Georgian_Modern_Sort_CI_AS. The replacement tests every collation. It also performs a more comprehensive check that the string/byte[] roundtrips with the varbinary/varchar from the database instance. Finally, it no longer requires permission to drop and create databases: we can just use the COLLATE statement.
edwardneal
commented
Mar 15, 2026
| [InlineData("KAZAKH_90_CI_AI")] | ||
| [InlineData("Georgian_Modern_Sort_CI_AS")] | ||
| public static void CollatedDataReaderTest(string collation) | ||
| [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] |
Contributor
Author
There was a problem hiding this comment.
Although this is treated as a Fact, it'll operate over every known collation. There are >5000 of these in SQL 2025 and I wasn't convinced that having each of them as a test case was valuable.
edwardneal
commented
Mar 15, 2026
| using (SqlCommand dbCmd = dbCon.CreateCommand()) | ||
| { | ||
| string data = Guid.NewGuid().ToString(); | ||
| Assert.True(codePageEncoding is not null, |
Contributor
Author
There was a problem hiding this comment.
This flows from the decision to keep the test as a Fact rather than a Theory: I need to specify which collation is failing an assertion using a message, and Assert.NotNull doesn't have this.
The same pattern plays out for the other instances of Assert.True.
edwardneal
commented
Mar 15, 2026
| Assert.True(collatedStringBytes.AsSpan().SequenceEqual(clientSideStringBytes), | ||
| $@"Collation ""{collationName}"", LCID {lcid}, code page {codePageId}: server-supplied byte array does not match client-side encoded bytes."); | ||
|
|
||
| // The character é does not exist in the Cyrillic character set, so do not compare the |
Contributor
Author
There was a problem hiding this comment.
This note is to explain why we have a different set of assertions between this test and CollatedStringInOutputParameter_DecodesSuccessfully.
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.
Description
This PR replaces one test and introduces another.
CollatedDataReaderTestPreviously, CollatedDataReaderTest would create a brand new database with one of two collations (Kazakh_90_CI_AI and Georgian_Modern_Sort_CI_AS), then try to select an ASCII string from it. This had a few issues:
I've replaced this with something a little more robust. We now test every collation on a SQL instance, retrieving the character string and its byte representation, then we make sure that they roundtrip. It also uses a string containing the
écharacter; this isn't present in Kazakh_90_CI_AI's code page, so SQL Server converts it toe. This is legitimate behaviour which would otherwise have failed.CollatedStringInOutputParameter_DecodesSuccessfullyThis is a new test which proves that we can roundtrip non-ASCII characters in output parameters when the value's collation's code page represents these non-ASCII characters differently: the default English Windows code page represents
éas0xE9; code page 936 represents this as[0xA8, 0xA6]; and UTF8 represents this as[0xC3, 0xA9].Issues
Loosely related: #584 originally added the CollatedDataReaderTest test, and referred to making sure that the driver would maintain the collation/codepage mappings. These two tests provide sufficient test coverage for that effort (which would also unblock globalization invariant mode.)
Testing
New tests run, the other tests and code remain untouched.