Skip to content

Commit 55aff92

Browse files
committed
Deduplicate code
1 parent d732366 commit 55aff92

File tree

1 file changed

+1
-35
lines changed

1 file changed

+1
-35
lines changed

src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/InstanceNameTest/InstanceNameTest.cs

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static void ConnectManagedWithInstanceNameTest(bool useMultiSubnetFailove
4848
builder.IPAddressPreference = ipPreference;
4949

5050

51-
Assert.True(ParseDataSource(builder.DataSource, out string hostname, out _, out string instanceName));
51+
Assert.True(DataTestUtility.ParseDataSource(builder.DataSource, out string hostname, out _, out string instanceName));
5252

5353
if (IsBrowserAlive(hostname) && IsValidInstance(hostname, instanceName))
5454
{
@@ -82,40 +82,6 @@ public static void ConnectManagedWithInstanceNameTest(bool useMultiSubnetFailove
8282
}
8383
}
8484

85-
private static bool ParseDataSource(string dataSource, out string hostname, out int port, out string instanceName)
86-
{
87-
hostname = string.Empty;
88-
port = -1;
89-
instanceName = string.Empty;
90-
91-
if (dataSource.Contains(",") && dataSource.Contains("\\"))
92-
return false;
93-
94-
if (dataSource.Contains(":"))
95-
{
96-
dataSource = dataSource.Substring(dataSource.IndexOf(":") + 1);
97-
}
98-
99-
if (dataSource.Contains(","))
100-
{
101-
if (!int.TryParse(dataSource.Substring(dataSource.LastIndexOf(",") + 1), out port))
102-
{
103-
return false;
104-
}
105-
dataSource = dataSource.Substring(0, dataSource.IndexOf(",") - 1);
106-
}
107-
108-
if (dataSource.Contains("\\"))
109-
{
110-
instanceName = dataSource.Substring(dataSource.LastIndexOf("\\") + 1);
111-
dataSource = dataSource.Substring(0, dataSource.LastIndexOf("\\"));
112-
}
113-
114-
hostname = dataSource;
115-
116-
return hostname.Length > 0 && hostname.IndexOfAny(new char[] { '\\', ':', ',' }) == -1;
117-
}
118-
11985
private static bool IsBrowserAlive(string browserHostname)
12086
{
12187
const byte ClntUcastEx = 0x03;

0 commit comments

Comments
 (0)