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:
Mitchell Sternke
2016-10-12 14:00:33 -07:00
committed by GitHub
parent 253298b158
commit 9f39ac6014
2 changed files with 39 additions and 0 deletions

View File

@@ -7,6 +7,7 @@ using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
@@ -830,5 +831,35 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
ConnectionInfo 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);
}
});
}
}
}

View File

@@ -14,6 +14,14 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Utility
test();
}
}
public static void RunIfLinuxOrOSX(Action test)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
test();
}
}
public static void RunIfWindows(Action test)
{