Skip to content

Commit

Permalink
Change | Separate tests for NetFx and NetCore - NetFx-Only Connection…
Browse files Browse the repository at this point in the history
… String Properties (#2466)

* Adding TransparentNetworkIpResolution to list of unsupported on platform connection string error messages
Splitting unit test for netfx-only connection string properties such that test does not fail on netcore

* Remove DeprecatedSynonymCount since referencing the unsupported array is not possible
  • Loading branch information
benrr101 committed May 29, 2024
1 parent 815e5ab commit 808d4c3
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,6 @@ internal static class DbConnectionStringKeywords
internal const string OmitOracleConnectionName = "Omit Oracle Connection Name";

// SqlClient
internal const string TransparentNetworkIPResolution = "Transparent Network IP Resolution";
internal const string Certificate = "Certificate";
#endif
// SqlClient
Expand Down Expand Up @@ -1073,6 +1072,7 @@ internal static class DbConnectionStringKeywords
internal const string IPAddressPreference = "IP Address Preference";
internal const string ServerSPN = "Server SPN";
internal const string FailoverPartnerSPN = "Failover Partner SPN";
internal const string TransparentNetworkIPResolution = "Transparent Network IP Resolution";

// common keywords (OleDb, OracleClient, SqlClient)
internal const string DataSource = "Data Source";
Expand All @@ -1092,10 +1092,9 @@ internal static class DbConnectionStringKeywords

internal static class DbConnectionStringSynonyms
{
#if NETFRAMEWORK
//internal const string TransparentNetworkIPResolution = TRANSPARENTNETWORKIPRESOLUTION;
internal const string TRANSPARENTNETWORKIPRESOLUTION = "transparentnetworkipresolution";
#endif

//internal const string ApplicationName = APP;
internal const string APP = "app";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ internal static class TRANSACTIONBINDING
internal const int SynonymCount = 33;
#else
internal const int SynonymCount = 30;
internal const int DeprecatedSynonymCount = 2;
#endif // NETFRAMEWORK

private static Dictionary<string, string> s_sqlClientSynonyms;
Expand Down Expand Up @@ -837,7 +836,7 @@ internal static Dictionary<string, string> GetParseSynonyms()

int count = SqlConnectionStringBuilder.KeywordsCount + SynonymCount;
#if NET6_0_OR_GREATER
count += SqlConnectionStringBuilder.DeprecatedKeywordsCount + DeprecatedSynonymCount;
count += SqlConnectionStringBuilder.DeprecatedKeywordsCount;
#endif
synonyms = new Dictionary<string, string>(count, StringComparer.OrdinalIgnoreCase)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private enum Keywords
private string _certificate = DbConnectionStringDefaults.Certificate;
#endif
#else
internal const int DeprecatedKeywordsCount = 3;
internal const int DeprecatedKeywordsCount = 5;
#endif
#endregion //Fields

Expand Down Expand Up @@ -363,7 +363,6 @@ private object GetAt(Keywords index)
return MinPoolSize;
case Keywords.MultiSubnetFailover:
return MultiSubnetFailover;
// case Keywords.NamedConnection: return NamedConnection;
case Keywords.PacketSize:
return PacketSize;
case Keywords.Password:
Expand Down Expand Up @@ -912,17 +911,19 @@ public override StandardValuesCollection GetStandardValues(ITypeDescriptorContex
}
}
#else
private static readonly string[] s_notSupportedKeywords = new string[DeprecatedKeywordsCount] {
private static readonly string[] s_notSupportedKeywords = {
DbConnectionStringKeywords.ConnectionReset,
DbConnectionStringKeywords.ContextConnection,
DbConnectionStringKeywords.TransactionBinding,
DbConnectionStringKeywords.TransparentNetworkIPResolution,
DbConnectionStringSynonyms.TRANSPARENTNETWORKIPRESOLUTION,
};

private static readonly string[] s_notSupportedNetworkLibraryKeywords = new string[] {
private static readonly string[] s_notSupportedNetworkLibraryKeywords = {
DbConnectionStringKeywords.NetworkLibrary,

DbConnectionStringSynonyms.NET,
DbConnectionStringSynonyms.NETWORK
DbConnectionStringSynonyms.NETWORK,
};
#endif
#endregion //Private Methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,34 @@ public void ConnectionStringTests(string connectionString)
ExecuteConnectionStringTests(connectionString);
}

public static readonly IEnumerable<object[]> ConnectionStringTestsNetFx_TestCases = new[]
{
new object[] { "Connection Reset = false" },
new object[] { "Context Connection = false" },
new object[] { "Network Library = dbmssocn" },
new object[] { "Network = dbnmpntw" },
new object[] { "Net = dbmsrpcn" },
new object[] { "TransparentNetworkIPResolution = false" },
new object[] { "Transparent Network IP Resolution = true" },
};

[Theory]
[InlineData("Connection Reset = false")]
[InlineData("Context Connection = false")]
[InlineData("Network Library = dbmssocn")]
[InlineData("Network = dbnmpntw")]
[InlineData("Net = dbmsrpcn")]
[InlineData("TransparentNetworkIPResolution = false")]
[InlineData("Transparent Network IP Resolution = true")]
[SkipOnTargetFramework(~TargetFrameworkMonikers.NetFramework)]
public void ConnectionStringTestsNetFx(string connectionString)
[MemberData(nameof(ConnectionStringTestsNetFx_TestCases))]
#if NETFRAMEWORK
public void ConnectionStringTestsNetFx_OnNetFx_Success(string connectionString)
{
ExecuteConnectionStringTests(connectionString);
}
#else
public void ConnectionStringTestsNetFx_OnNetCore_Throws(string connectionString)
{
// Act
Action action = () => _ = new SqlConnectionStringBuilder(connectionString);

// Assert
Assert.Throws<NotSupportedException>(action);
}
#endif

[Fact]
public void SetInvalidApplicationIntent_Throws()
Expand Down

0 comments on commit 808d4c3

Please sign in to comment.