-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX | Adding support for sharedInstances to managed SNI (#1237)
- Loading branch information
Javad
authored
Sep 20, 2021
1 parent
96a8b05
commit 5cd0f7d
Showing
6 changed files
with
88 additions
and
34 deletions.
There are no files selected for viewing
This file contains 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 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 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
82 changes: 60 additions & 22 deletions
82
src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/LocalDBTest/LocalDBTest.cs
This file contains 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 |
---|---|---|
@@ -1,57 +1,95 @@ | ||
// 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.Collections.Generic; | ||
using Xunit; | ||
|
||
namespace Microsoft.Data.SqlClient.ManualTesting.Tests | ||
{ | ||
public static class LocalDBTest | ||
{ | ||
private static bool IsLocalDBEnvironmentSet() => DataTestUtility.IsLocalDBInstalled(); | ||
private static bool IsLocalDbSharedInstanceSet() => DataTestUtility.IsLocalDbSharedInstanceSetup(); | ||
private static readonly string s_localDbConnectionString = @$"server=(localdb)\{DataTestUtility.LocalDbAppName}"; | ||
private static readonly string[] s_sharedLocalDbInstances = new string[] { @$"server=(localdb)\.\{DataTestUtility.LocalDbSharedInstanceName}", @$"server=(localdb)\." }; | ||
private static readonly string s_badConnectionString = $@"server=(localdb)\{DataTestUtility.LocalDbAppName};Database=DOES_NOT_EXIST;Pooling=false;"; | ||
|
||
static string LocalDbName = DataTestUtility.LocalDbAppName; | ||
#region LocalDbTests | ||
[SkipOnTargetFramework(TargetFrameworkMonikers.Uap)] // No Registry support on UAP | ||
[ConditionalFact(nameof(IsLocalDBEnvironmentSet))] | ||
public static void LocalDBConnectionTest() | ||
public static void SqlLocalDbConnectionTest() | ||
{ | ||
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(@$"server=(localdb)\{DataTestUtility.LocalDbAppName}"); | ||
builder.IntegratedSecurity = true; | ||
builder.ConnectTimeout = 2; | ||
OpenConnection(builder.ConnectionString); | ||
ConnectionTest(s_localDbConnectionString); | ||
} | ||
|
||
[SkipOnTargetFramework(TargetFrameworkMonikers.Uap)] // No Registry support on UAP | ||
[ConditionalFact(nameof(IsLocalDBEnvironmentSet))] | ||
public static void LocalDBMarsTest() | ||
{ | ||
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(@$"server=(localdb)\{DataTestUtility.LocalDbAppName}"); | ||
builder.IntegratedSecurity = true; | ||
builder.MultipleActiveResultSets = true; | ||
builder.ConnectTimeout = 2; | ||
OpenConnection(builder.ConnectionString); | ||
ConnectionWithMarsTest(s_localDbConnectionString); | ||
} | ||
|
||
[SkipOnTargetFramework(TargetFrameworkMonikers.Uap)] // No Registry support on UAP | ||
[ConditionalFact(nameof(IsLocalDBEnvironmentSet))] | ||
public static void InvalidDBTest() | ||
public static void InvalidLocalDBTest() | ||
{ | ||
using (var connection = new SqlConnection(@$"server=(localdb)\{DataTestUtility.LocalDbAppName};Database=DOES_NOT_EXIST;Pooling=false;")) | ||
using var connection = new SqlConnection(s_badConnectionString); | ||
DataTestUtility.AssertThrowsWrapper<SqlException>(() => connection.Open()); | ||
} | ||
#endregion | ||
|
||
#region SharedLocalDb tests | ||
[SkipOnTargetFramework(TargetFrameworkMonikers.Uap)] // No Registry support on UAP | ||
[ConditionalFact(nameof(IsLocalDbSharedInstanceSet))] | ||
public static void SharedLocalDbMarsTest() | ||
{ | ||
foreach (string connectionString in s_sharedLocalDbInstances) | ||
{ | ||
DataTestUtility.AssertThrowsWrapper<SqlException>(() => connection.Open()); | ||
ConnectionWithMarsTest(connectionString); | ||
} | ||
} | ||
|
||
private static void OpenConnection(string connString) | ||
[SkipOnTargetFramework(TargetFrameworkMonikers.Uap)] // No Registry support on UAP | ||
[ConditionalFact(nameof(IsLocalDbSharedInstanceSet))] | ||
public static void SqlLocalDbSharedInstanceConnectionTest() | ||
{ | ||
using (SqlConnection connection = new SqlConnection(connString)) | ||
foreach (string connectionString in s_sharedLocalDbInstances) | ||
{ | ||
connection.Open(); | ||
using (SqlCommand command = new SqlCommand("SELECT @@SERVERNAME", connection)) | ||
{ | ||
var result = command.ExecuteScalar(); | ||
Assert.NotNull(result); | ||
} | ||
ConnectionTest(connectionString); | ||
} | ||
} | ||
#endregion | ||
|
||
private static void ConnectionWithMarsTest(string connectionString) | ||
{ | ||
SqlConnectionStringBuilder builder = new(connectionString) | ||
{ | ||
IntegratedSecurity = true, | ||
MultipleActiveResultSets = true, | ||
ConnectTimeout = 2, | ||
Encrypt = false | ||
}; | ||
OpenConnection(builder.ConnectionString); | ||
} | ||
private static void ConnectionTest(string connectionString) | ||
{ | ||
SqlConnectionStringBuilder builder = new(connectionString) | ||
{ | ||
IntegratedSecurity = true, | ||
ConnectTimeout = 2, | ||
Encrypt = false | ||
}; | ||
OpenConnection(builder.ConnectionString); | ||
} | ||
|
||
private static void OpenConnection(string connString) | ||
{ | ||
using SqlConnection connection = new(connString); | ||
connection.Open(); | ||
using SqlCommand command = new SqlCommand("SELECT @@SERVERNAME", connection); | ||
var result = command.ExecuteScalar(); | ||
Assert.NotNull(result); | ||
} | ||
} | ||
} |
This file contains 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 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