Repository navigation
Remove some trim/AOT warnings: easy cases #4684
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ed1df46
Remove trim/AOT warnings with API swaps and DataTable fixes
charlesroddie 211ef3f
Test that explicit IP address preference list matches the enum
charlesroddie fb97034
Test that schema collection columns are not INullable
charlesroddie 0daa923
Narrow IL2072 suppression and test enumerator de-duplication
charlesroddie 6d78d8e
Address review: follow DataTable.CaseSensitive and document tests
charlesroddie 1b4d741
List IP address preference names in the lookup initializer
charlesroddie 6b93e5d
Make the BuildSchemaTable IL2111 suppression visible to the trimmer
charlesroddie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
30 changes: 30 additions & 0 deletions
30
....Data.SqlClient/tests/UnitTests/Microsoft/Data/Common/IpAddressPreferenceUtilitiesTest.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System; | ||
| using Microsoft.Data.Common.ConnectionString; | ||
| using Microsoft.Data.SqlClient; | ||
| using Xunit; | ||
|
|
||
| namespace Microsoft.Data.Common.UnitTests; | ||
|
|
||
| /// <summary> | ||
| /// Tests for <see cref="IpAddressPreferenceUtilities"/>. | ||
| /// </summary> | ||
| public class IpAddressPreferenceUtilitiesTest | ||
| { | ||
| /// <summary> | ||
| /// Verifies that each enum value's name converts back to that value, so the explicitly listed names | ||
| /// stay in sync with the enum definition. | ||
| /// </summary> | ||
| [Fact] | ||
| public void TryConvertToIPAddressPreference_AcceptsEveryEnumValueName() | ||
| { | ||
| foreach (SqlConnectionIPAddressPreference value in Enum.GetValues(typeof(SqlConnectionIPAddressPreference))) | ||
| { | ||
| Assert.True(IpAddressPreferenceUtilities.TryConvertToIPAddressPreference(value.ToString(), out SqlConnectionIPAddressPreference result), $"{value} is missing."); | ||
| Assert.Equal(value, result); | ||
| } | ||
| } | ||
| } |
129 changes: 129 additions & 0 deletions
129
...a.SqlClient/tests/UnitTests/Microsoft/Data/Sql/SqlDataSourceEnumeratorNativeHelperTest.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System; | ||
| using System.Data; | ||
| using System.Linq; | ||
| using Xunit; | ||
|
|
||
| namespace Microsoft.Data.Sql.UnitTests; | ||
|
|
||
| /// <summary> | ||
| /// Tests parsing and de-duplication of the native SNI server enumeration string in | ||
| /// <see cref="SqlDataSourceEnumeratorNativeHelper.ParseServerEnumString"/>, which must match | ||
| /// the string equality of the case-insensitive <see cref="DataTable"/> it populates. | ||
| /// </summary> | ||
| public class SqlDataSourceEnumeratorNativeHelperTest | ||
| { | ||
| /// <summary> | ||
| /// Gets server and instance names that a case-insensitive <see cref="DataTable"/> treats as equal to | ||
| /// "server" and "inst": identical, differing in case, with trailing ASCII or ideographic spaces, and full-width. | ||
| /// </summary> | ||
| /// <see cref="EquivalentEntry_IsDropped"/> | ||
| public static TheoryData<string, string> EquivalentNames => new() | ||
| { | ||
| { "server", "inst" }, | ||
| { "SERVER", "INST" }, | ||
| { "server ", "inst " }, | ||
| { "server" + (char)0x3000, "inst" + (char)0x3000 }, | ||
| { ToFullWidth("server"), ToFullWidth("inst") }, | ||
| }; | ||
|
|
||
| /// <summary> | ||
| /// Verifies that every column of distinct entries is returned, and that an entry without an instance | ||
| /// name stores <see cref="DBNull"/> for the instance. | ||
| /// </summary> | ||
| [Fact] | ||
| public void DistinctEntries_AreAllReturned() | ||
|
charlesroddie marked this conversation as resolved.
Resolved
|
||
| { | ||
| DataTable table = Parse(Entry("server1", "inst1", "Yes", "16.0.1000.6"), Entry("server2", null)); | ||
|
|
||
| Assert.Equal(2, table.Rows.Count); | ||
| Assert.Equal("server1", table.Rows[0][SqlDataSourceEnumeratorUtil.ServerNameCol]); | ||
| Assert.Equal("inst1", table.Rows[0][SqlDataSourceEnumeratorUtil.InstanceNameCol]); | ||
| Assert.Equal("Yes", table.Rows[0][SqlDataSourceEnumeratorUtil.IsClusteredCol]); | ||
| Assert.Equal("16.0.1000.6", table.Rows[0][SqlDataSourceEnumeratorUtil.VersionNameCol]); | ||
| Assert.Equal("server2", table.Rows[1][SqlDataSourceEnumeratorUtil.ServerNameCol]); | ||
| Assert.Equal(DBNull.Value, table.Rows[1][SqlDataSourceEnumeratorUtil.InstanceNameCol]); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Verifies that an entry equal to an earlier one under <see cref="DataTable"/> string comparison is dropped. | ||
| /// </summary> | ||
| /// <param name="serverName">A server name equivalent to "server".</param> | ||
| /// <param name="instanceName">An instance name equivalent to "inst".</param> | ||
| [Theory] | ||
| [MemberData(nameof(EquivalentNames))] | ||
| public void EquivalentEntry_IsDropped(string serverName, string instanceName) | ||
| { | ||
| DataTable table = Parse(Entry("server", "inst"), Entry(serverName, instanceName)); | ||
|
|
||
| Assert.Equal(1, table.Rows.Count); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Verifies that two instances on the same server are both returned. | ||
| /// </summary> | ||
| [Fact] | ||
| public void SameServerWithDifferentInstance_IsKept() | ||
| { | ||
| DataTable table = Parse(Entry("server", "inst1"), Entry("server", "inst2")); | ||
|
|
||
| Assert.Equal(2, table.Rows.Count); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Verifies that an entry without an instance name is treated as a duplicate of an earlier entry for the | ||
| /// same server, whatever that entry's instance. | ||
| /// </summary> | ||
| [Fact] | ||
| public void EntryWithoutInstance_MatchesExistingServerWithAnyInstance() | ||
| { | ||
| DataTable table = Parse(Entry("server", "inst"), Entry("server", null)); | ||
|
|
||
| Assert.Equal(1, table.Rows.Count); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Verifies that an entry with an instance name is not a duplicate of an earlier entry for the same server | ||
| /// that has no instance. | ||
| /// </summary> | ||
| [Fact] | ||
| public void EntryWithInstance_DoesNotMatchExistingServerWithoutInstance() | ||
| { | ||
| DataTable table = Parse(Entry("server", null), Entry("server", "inst")); | ||
|
|
||
| Assert.Equal(2, table.Rows.Count); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Joins entries with the native end-of-instance delimiter and parses them. | ||
| /// </summary> | ||
| /// <param name="entries">Entries formatted by <see cref="Entry"/>.</param> | ||
| /// <returns>The parsed data sources table.</returns> | ||
| private static DataTable Parse(params string[] entries) => | ||
| SqlDataSourceEnumeratorNativeHelper.ParseServerEnumString( | ||
| string.Join(SqlDataSourceEnumeratorUtil.EndOfServerInstanceDelimiter_Native.ToString(), entries)); | ||
|
|
||
| /// <summary> | ||
| /// Formats one entry as native SNI returns it: "serverName[\instanceName];Clustered:[Yes|No];Version:...". | ||
| /// </summary> | ||
| /// <param name="serverName">The server name.</param> | ||
| /// <param name="instanceName">The instance name, or <see langword="null"/> for a default instance.</param> | ||
| /// <param name="clustered">The clustered flag.</param> | ||
| /// <param name="version">The server version.</param> | ||
| /// <returns>The formatted entry.</returns> | ||
| private static string Entry(string serverName, string? instanceName, string clustered = "No", string version = "15.0.2000.5") => | ||
| (instanceName is null ? serverName : serverName + SqlDataSourceEnumeratorUtil.ServerNamesAndInstanceDelimiter + instanceName) + | ||
| SqlDataSourceEnumeratorUtil.InstanceKeysDelimiter + SqlDataSourceEnumeratorUtil.Clustered + clustered + | ||
| SqlDataSourceEnumeratorUtil.InstanceKeysDelimiter + SqlDataSourceEnumeratorUtil.Version + version; | ||
|
|
||
| /// <summary> | ||
| /// Converts printable ASCII characters to their full-width forms. | ||
| /// </summary> | ||
| /// <param name="value">A string of printable ASCII characters.</param> | ||
| /// <returns>The full-width string.</returns> | ||
| private static string ToFullWidth(string value) => | ||
| new(value.Select(c => (char)(c + 0xFEE0)).ToArray()); | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.