mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
Feature/sql exception bug check (#90)
* Added test for OSX/Linux to check for the SqlException error code bug in .NET core * fix style * closed summary
This commit is contained in:
@@ -7,6 +7,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
|
using System.Data.SqlClient;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -830,5 +831,35 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
|||||||
ConnectionInfo info;
|
ConnectionInfo info;
|
||||||
Assert.True(service.TryFindConnection(connectParams.OwnerUri, out info));
|
Assert.True(service.TryFindConnection(connectParams.OwnerUri, out info));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Verify that Linux/OSX SqlExceptions thrown do not contain an error code.
|
||||||
|
/// This is a bug in .NET core (see https://github.com/dotnet/corefx/issues/12472).
|
||||||
|
/// If this test ever fails, it means that this bug has been fixed. When this is
|
||||||
|
/// the case, look at RetryPolicyUtils.cs in IsRetryableNetworkConnectivityError(),
|
||||||
|
/// and remove the code block specific to Linux/OSX.
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void TestThatLinuxAndOSXSqlExceptionHasNoErrorCode()
|
||||||
|
{
|
||||||
|
TestUtils.RunIfLinuxOrOSX(() =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
|
||||||
|
builder.DataSource = "bad-server-name";
|
||||||
|
builder.UserID = "sa";
|
||||||
|
builder.Password = "bad password";
|
||||||
|
|
||||||
|
SqlConnection connection = new SqlConnection(builder.ConnectionString);
|
||||||
|
connection.Open(); // This should fail
|
||||||
|
}
|
||||||
|
catch (SqlException ex)
|
||||||
|
{
|
||||||
|
// Error code should be 0 due to bug
|
||||||
|
Assert.Equal(ex.Number, 0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,14 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Utility
|
|||||||
test();
|
test();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void RunIfLinuxOrOSX(Action test)
|
||||||
|
{
|
||||||
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||||
|
{
|
||||||
|
test();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void RunIfWindows(Action test)
|
public static void RunIfWindows(Action test)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user