diff --git a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/Microsoft.Data.SqlClient.Tests.csproj b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/Microsoft.Data.SqlClient.Tests.csproj index f4617ced90..f575d34900 100644 --- a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/Microsoft.Data.SqlClient.Tests.csproj +++ b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/Microsoft.Data.SqlClient.Tests.csproj @@ -28,7 +28,6 @@ - @@ -43,11 +42,10 @@ - - + @@ -82,10 +80,6 @@ - - - - diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/Microsoft.Data.SqlClient.ManualTesting.Tests.csproj b/src/Microsoft.Data.SqlClient/tests/ManualTests/Microsoft.Data.SqlClient.ManualTesting.Tests.csproj index 3a596dd237..7d4617be71 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/Microsoft.Data.SqlClient.ManualTesting.Tests.csproj +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/Microsoft.Data.SqlClient.ManualTesting.Tests.csproj @@ -59,7 +59,7 @@ - + @@ -184,6 +184,7 @@ + PreserveNewest @@ -222,6 +223,10 @@ TCECryptoNativeBaselineRsa.txt + + + + @@ -241,6 +246,9 @@ Microsoft.DotNet.XUnitExtensions + + + Address @@ -267,6 +275,7 @@ + diff --git a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/DiagnosticTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/TracingTests/DiagnosticTest.cs similarity index 82% rename from src/Microsoft.Data.SqlClient/tests/FunctionalTests/DiagnosticTest.cs rename to src/Microsoft.Data.SqlClient/tests/ManualTests/TracingTests/DiagnosticTest.cs index 6017a7dd8e..b0661743c8 100644 --- a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/DiagnosticTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/TracingTests/DiagnosticTest.cs @@ -17,21 +17,20 @@ using System.Runtime.CompilerServices; using System; using System.Data; +using Microsoft.DotNet.RemoteExecutor; -namespace Microsoft.Data.SqlClient.Tests +namespace Microsoft.Data.SqlClient.ManualTesting.Tests { - public class DiagnosticTest : RemoteExecutorTestBase + [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)] + public class DiagnosticTest { private const string BadConnectionString = "data source = bad; initial catalog = bad; uid = bad; password = bad; connection timeout = 1;"; - private static readonly string s_tcpConnStr = Environment.GetEnvironmentVariable("TEST_TCP_CONN_STR") ?? string.Empty; - - public static bool IsConnectionStringConfigured() => s_tcpConnStr != string.Empty; + private static readonly string s_tcpConnStr = DataTestUtility.TCPConnectionString ?? string.Empty; - [Fact] - [SkipOnTargetFramework(TargetFrameworkMonikers.UapAot | TargetFrameworkMonikers.NetFramework, "Internals reflection not supported on UapAot | Feature not available on Framework")] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] public void ExecuteScalarTest() { - RemoteInvoke(() => + RemoteExecutor.Invoke(() => { CollectStatisticsDiagnostics(connectionString => { @@ -45,15 +44,14 @@ public void ExecuteScalarTest() var output = cmd.ExecuteScalar(); } }); - return SuccessExitCode; + return RemoteExecutor.SuccessExitCode; }).Dispose(); } - [Fact] - [SkipOnTargetFramework(TargetFrameworkMonikers.UapAot | TargetFrameworkMonikers.NetFramework, "Internals reflection not supported on UapAot | Feature not available on Framework")] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] public void ExecuteScalarErrorTest() { - RemoteInvoke(() => + RemoteExecutor.Invoke(() => { CollectStatisticsDiagnostics(connectionString => { @@ -64,20 +62,19 @@ public void ExecuteScalarErrorTest() cmd.CommandText = "select 1 / 0;"; conn.Open(); - - try { var output = cmd.ExecuteScalar(); } + try + { var output = cmd.ExecuteScalar(); } catch { } } }); - return SuccessExitCode; + return RemoteExecutor.SuccessExitCode; }).Dispose(); } - [Fact] - [SkipOnTargetFramework(TargetFrameworkMonikers.UapAot | TargetFrameworkMonikers.NetFramework, "Internals reflection not supported on UapAot | Feature not available on Framework")] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] public void ExecuteNonQueryTest() { - RemoteInvoke(() => + RemoteExecutor.Invoke(() => { CollectStatisticsDiagnostics(connectionString => { @@ -91,15 +88,14 @@ public void ExecuteNonQueryTest() var output = cmd.ExecuteNonQuery(); } }); - return SuccessExitCode; + return RemoteExecutor.SuccessExitCode; }).Dispose(); } - [Fact] - [SkipOnTargetFramework(TargetFrameworkMonikers.UapAot | TargetFrameworkMonikers.NetFramework, "Internals reflection not supported on UapAot | Feature not available on Framework")] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] public void ExecuteNonQueryErrorTest() { - RemoteInvoke(() => + RemoteExecutor.Invoke(() => { CollectStatisticsDiagnostics(connectionString => { @@ -109,7 +105,7 @@ public void ExecuteNonQueryErrorTest() { cmd.Connection = conn; cmd.CommandText = "select 1 / 0;"; - + // Limiting the command timeout to 3 seconds. This should be lower than the Process timeout. cmd.CommandTimeout = 3; conn.Open(); @@ -129,15 +125,14 @@ public void ExecuteNonQueryErrorTest() } Console.WriteLine("SqlClient.DiagnosticTest.ExecuteNonQueryErrorTest Connection Disposed"); }); - return SuccessExitCode; + return RemoteExecutor.SuccessExitCode; }).Dispose(); } - [Fact] - [SkipOnTargetFramework(TargetFrameworkMonikers.UapAot | TargetFrameworkMonikers.NetFramework, "Internals reflection not supported on UapAot | Feature not available on Framework")] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] public void ExecuteReaderTest() { - RemoteInvoke(() => + RemoteExecutor.Invoke(() => { CollectStatisticsDiagnostics(connectionString => { @@ -149,18 +144,18 @@ public void ExecuteReaderTest() conn.Open(); SqlDataReader reader = cmd.ExecuteReader(); - while (reader.Read()) { } + while (reader.Read()) + { } } }); - return SuccessExitCode; + return RemoteExecutor.SuccessExitCode; }).Dispose(); } - [Fact] - [SkipOnTargetFramework(TargetFrameworkMonikers.UapAot | TargetFrameworkMonikers.NetFramework, "Internals reflection not supported on UapAot | Feature not available on Framework")] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] public void ExecuteReaderErrorTest() { - RemoteInvoke(() => + RemoteExecutor.Invoke(() => { CollectStatisticsDiagnostics(connectionString => { @@ -173,20 +168,20 @@ public void ExecuteReaderErrorTest() try { SqlDataReader reader = cmd.ExecuteReader(); - while (reader.Read()) { } + while (reader.Read()) + { } } catch { } } }); - return SuccessExitCode; + return RemoteExecutor.SuccessExitCode; }).Dispose(); } - [Fact] - [SkipOnTargetFramework(TargetFrameworkMonikers.UapAot | TargetFrameworkMonikers.NetFramework, "Internals reflection not supported on UapAot | Feature not available on Framework")] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] public void ExecuteReaderWithCommandBehaviorTest() { - RemoteInvoke(() => + RemoteExecutor.Invoke(() => { CollectStatisticsDiagnostics(connectionString => { @@ -198,18 +193,18 @@ public void ExecuteReaderWithCommandBehaviorTest() conn.Open(); SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.Default); - while (reader.Read()) { } + while (reader.Read()) + { } } }); - return SuccessExitCode; + return RemoteExecutor.SuccessExitCode; }).Dispose(); } - [ConditionalFact(nameof(IsConnectionStringConfigured))] - [SkipOnTargetFramework(TargetFrameworkMonikers.UapAot | TargetFrameworkMonikers.NetFramework, "Internals reflection not supported on UapAot | Feature not available on Framework")] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] public void ExecuteXmlReaderTest() { - RemoteInvoke(cs => + RemoteExecutor.Invoke(cs => { CollectStatisticsDiagnostics(_ => { @@ -221,18 +216,18 @@ public void ExecuteXmlReaderTest() conn.Open(); XmlReader reader = cmd.ExecuteXmlReader(); - while (reader.Read()) { } + while (reader.Read()) + { } } }); - return SuccessExitCode; + return RemoteExecutor.SuccessExitCode; }, s_tcpConnStr).Dispose(); } - [Fact] - [SkipOnTargetFramework(TargetFrameworkMonikers.UapAot | TargetFrameworkMonikers.NetFramework, "Internals reflection not supported on UapAot | Feature not available on Framework")] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] public void ExecuteXmlReaderErrorTest() { - RemoteInvoke(() => + RemoteExecutor.Invoke(() => { CollectStatisticsDiagnostics(connectionString => { @@ -245,20 +240,20 @@ public void ExecuteXmlReaderErrorTest() try { XmlReader reader = cmd.ExecuteXmlReader(); - while (reader.Read()) { } + while (reader.Read()) + { } } catch { } } }); - return SuccessExitCode; + return RemoteExecutor.SuccessExitCode; }).Dispose(); } - [Fact] - [SkipOnTargetFramework(TargetFrameworkMonikers.UapAot | TargetFrameworkMonikers.NetFramework, "Internals reflection not supported on UapAot | Feature not available on Framework")] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] public void ExecuteScalarAsyncTest() { - RemoteInvoke(() => + RemoteExecutor.Invoke(() => { CollectStatisticsDiagnosticsAsync(async connectionString => { @@ -272,15 +267,14 @@ public void ExecuteScalarAsyncTest() var output = await cmd.ExecuteScalarAsync(); } }).GetAwaiter().GetResult(); - return SuccessExitCode; + return RemoteExecutor.SuccessExitCode; }).Dispose(); } - [Fact] - [SkipOnTargetFramework(TargetFrameworkMonikers.UapAot | TargetFrameworkMonikers.NetFramework, "Internals reflection not supported on UapAot | Feature not available on Framework")] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] public void ExecuteScalarAsyncErrorTest() { - RemoteInvoke(() => + RemoteExecutor.Invoke(() => { CollectStatisticsDiagnosticsAsync(async connectionString => { @@ -292,19 +286,19 @@ public void ExecuteScalarAsyncErrorTest() conn.Open(); - try { var output = await cmd.ExecuteScalarAsync(); } + try + { var output = await cmd.ExecuteScalarAsync(); } catch { } } }).GetAwaiter().GetResult(); - return SuccessExitCode; + return RemoteExecutor.SuccessExitCode; }).Dispose(); } - [Fact] - [SkipOnTargetFramework(TargetFrameworkMonikers.UapAot | TargetFrameworkMonikers.NetFramework, "Internals reflection not supported on UapAot | Feature not available on Framework")] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] public void ExecuteNonQueryAsyncTest() { - RemoteInvoke(() => + RemoteExecutor.Invoke(() => { CollectStatisticsDiagnosticsAsync(async connectionString => { @@ -318,15 +312,14 @@ public void ExecuteNonQueryAsyncTest() var output = await cmd.ExecuteNonQueryAsync(); } }).GetAwaiter().GetResult(); - return SuccessExitCode; + return RemoteExecutor.SuccessExitCode; }).Dispose(); } - [Fact] - [SkipOnTargetFramework(TargetFrameworkMonikers.UapAot | TargetFrameworkMonikers.NetFramework, "Internals reflection not supported on UapAot | Feature not available on Framework")] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] public void ExecuteNonQueryAsyncErrorTest() { - RemoteInvoke(() => + RemoteExecutor.Invoke(() => { CollectStatisticsDiagnosticsAsync(async connectionString => { @@ -337,19 +330,19 @@ public void ExecuteNonQueryAsyncErrorTest() cmd.CommandText = "select 1 / 0;"; conn.Open(); - try { var output = await cmd.ExecuteNonQueryAsync(); } + try + { var output = await cmd.ExecuteNonQueryAsync(); } catch { } } }).GetAwaiter().GetResult(); - return SuccessExitCode; + return RemoteExecutor.SuccessExitCode; }).Dispose(); } - [Fact] - [SkipOnTargetFramework(TargetFrameworkMonikers.UapAot | TargetFrameworkMonikers.NetFramework, "Internals reflection not supported on UapAot | Feature not available on Framework")] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] public void ExecuteReaderAsyncTest() { - RemoteInvoke(() => + RemoteExecutor.Invoke(() => { CollectStatisticsDiagnosticsAsync(async connectionString => { @@ -361,18 +354,18 @@ public void ExecuteReaderAsyncTest() conn.Open(); SqlDataReader reader = await cmd.ExecuteReaderAsync(); - while (reader.Read()) { } + while (reader.Read()) + { } } }).GetAwaiter().GetResult(); - return SuccessExitCode; + return RemoteExecutor.SuccessExitCode; }).Dispose(); } - [Fact] - [SkipOnTargetFramework(TargetFrameworkMonikers.UapAot | TargetFrameworkMonikers.NetFramework, "Internals reflection not supported on UapAot | Feature not available on Framework")] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] public void ExecuteReaderAsyncErrorTest() { - RemoteInvoke(() => + RemoteExecutor.Invoke(() => { CollectStatisticsDiagnosticsAsync(async connectionString => { @@ -385,20 +378,20 @@ public void ExecuteReaderAsyncErrorTest() try { SqlDataReader reader = await cmd.ExecuteReaderAsync(); - while (reader.Read()) { } + while (reader.Read()) + { } } catch { } } }).GetAwaiter().GetResult(); - return SuccessExitCode; + return RemoteExecutor.SuccessExitCode; }).Dispose(); } - [ConditionalFact(nameof(IsConnectionStringConfigured))] - [SkipOnTargetFramework(TargetFrameworkMonikers.UapAot | TargetFrameworkMonikers.NetFramework, "Internals reflection not supported on UapAot | Feature not available on Framework")] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] public void ExecuteXmlReaderAsyncTest() { - RemoteInvoke(cs => + RemoteExecutor.Invoke(cs => { CollectStatisticsDiagnosticsAsync(async _ => { @@ -410,18 +403,18 @@ public void ExecuteXmlReaderAsyncTest() conn.Open(); XmlReader reader = await cmd.ExecuteXmlReaderAsync(); - while (reader.Read()) { } + while (reader.Read()) + { } } }).GetAwaiter().GetResult(); - return SuccessExitCode; + return RemoteExecutor.SuccessExitCode; }, s_tcpConnStr).Dispose(); } - [ConditionalFact(nameof(IsConnectionStringConfigured))] - [SkipOnTargetFramework(TargetFrameworkMonikers.UapAot | TargetFrameworkMonikers.NetFramework, "Internals reflection not supported on UapAot | Feature not available on Framework")] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] public void ExecuteXmlReaderAsyncErrorTest() { - RemoteInvoke(cs => + RemoteExecutor.Invoke(cs => { CollectStatisticsDiagnosticsAsync(async _ => { @@ -434,20 +427,20 @@ public void ExecuteXmlReaderAsyncErrorTest() try { XmlReader reader = await cmd.ExecuteXmlReaderAsync(); - while (reader.Read()) { } + while (reader.Read()) + { } } catch { } } }).GetAwaiter().GetResult(); - return SuccessExitCode; + return RemoteExecutor.SuccessExitCode; }, s_tcpConnStr).Dispose(); } - [Fact] - [SkipOnTargetFramework(TargetFrameworkMonikers.UapAot | TargetFrameworkMonikers.NetFramework, "Internals reflection not supported on UapAot | Feature not available on Framework")] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] public void ConnectionOpenTest() { - RemoteInvoke(() => + RemoteExecutor.Invoke(() => { CollectStatisticsDiagnostics(connectionString => { @@ -460,32 +453,32 @@ public void ConnectionOpenTest() }, true); Console.WriteLine("SqlClient.DiagnosticsTest.ConnectionOpenTest:: Done with Diagnostics collection"); - return SuccessExitCode; + return RemoteExecutor.SuccessExitCode; }).Dispose(); } - [Fact] - [SkipOnTargetFramework(TargetFrameworkMonikers.UapAot | TargetFrameworkMonikers.NetFramework, "Internals reflection not supported on UapAot | Feature not available on Framework")] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] public void ConnectionOpenErrorTest() { - RemoteInvoke(() => + RemoteExecutor.Invoke(() => { CollectStatisticsDiagnostics(_ => { using (SqlConnection sqlConnection = new SqlConnection(BadConnectionString)) { - try { sqlConnection.Open(); } catch { } + try + { sqlConnection.Open(); } + catch { } } }); - return SuccessExitCode; + return RemoteExecutor.SuccessExitCode; }).Dispose(); } - [Fact] - [SkipOnTargetFramework(TargetFrameworkMonikers.UapAot | TargetFrameworkMonikers.NetFramework, "Internals reflection not supported on UapAot | Feature not available on Framework")] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] public void ConnectionOpenAsyncTest() { - RemoteInvoke(() => + RemoteExecutor.Invoke(() => { CollectStatisticsDiagnosticsAsync(async connectionString => { @@ -494,24 +487,25 @@ public void ConnectionOpenAsyncTest() await sqlConnection.OpenAsync(); } }).GetAwaiter().GetResult(); - return SuccessExitCode; + return RemoteExecutor.SuccessExitCode; }).Dispose(); } - [Fact] - [SkipOnTargetFramework(TargetFrameworkMonikers.UapAot | TargetFrameworkMonikers.NetFramework, "Internals reflection not supported on UapAot | Feature not available on Framework")] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] public void ConnectionOpenAsyncErrorTest() { - RemoteInvoke(() => + RemoteExecutor.Invoke(() => { CollectStatisticsDiagnosticsAsync(async _ => { using (SqlConnection sqlConnection = new SqlConnection(BadConnectionString)) { - try { await sqlConnection.OpenAsync(); } catch { } + try + { await sqlConnection.OpenAsync(); } + catch { } } }).GetAwaiter().GetResult(); - return SuccessExitCode; + return RemoteExecutor.SuccessExitCode; }).Dispose(); } @@ -520,7 +514,7 @@ private static void CollectStatisticsDiagnostics(Action sqlOperation, bo bool statsLogged = false; bool operationHasError = false; Guid beginOperationId = Guid.Empty; - + FakeDiagnosticListenerObserver diagnosticListenerObserver = new FakeDiagnosticListenerObserver(kvp => { IDictionary statistics; @@ -540,12 +534,12 @@ private static void CollectStatisticsDiagnostics(Action sqlOperation, bo Guid connectionId = GetPropertyValueFromType(kvp.Value, "ConnectionId"); if (sqlCommand.Connection.State == ConnectionState.Open) - { + { Assert.NotEqual(connectionId, Guid.Empty); } beginOperationId = retrievedOperationId; - + statsLogged = true; } else if (kvp.Key.Equals("Microsoft.Data.SqlClient.WriteCommandAfter")) @@ -702,13 +696,13 @@ private static void CollectStatisticsDiagnostics(Action sqlOperation, bo { Console.WriteLine(string.Format("Test: {0} Enabled Listeners", methodName)); - using (var server = TestTdsServer.StartServerWithQueryEngine(new DiagnosticsQueryEngine(), enableLog:enableServerLogging, methodName: methodName)) + using (var server = TestTdsServer.StartServerWithQueryEngine(new DiagnosticsQueryEngine(), enableLog: enableServerLogging, methodName: methodName)) { Console.WriteLine(string.Format("Test: {0} Started Server", methodName)); sqlOperation(server.ConnectionString); Console.WriteLine(string.Format("Test: {0} SqlOperation Successful", methodName)); - + Assert.True(statsLogged); diagnosticListenerObserver.Disable(); @@ -814,7 +808,7 @@ private static async Task CollectStatisticsDiagnosticsAsync(Func s Guid connectionId = GetPropertyValueFromType(kvp.Value, "ConnectionId"); if (sqlConnection.State == ConnectionState.Open) - { + { Assert.NotEqual(connectionId, Guid.Empty); } @@ -909,7 +903,7 @@ private static async Task CollectStatisticsDiagnosticsAsync(Func s } Console.WriteLine(string.Format("Test: {0} Listeners Disposed Successfully", methodName)); } - + private static T GetPropertyValueFromType(object obj, string propName) { Type type = obj.GetType(); @@ -929,7 +923,7 @@ public DiagnosticsQueryEngine() : base(new TDSServerArguments()) protected override TDSMessageCollection CreateQueryResponse(ITDSServerSession session, TDSSQLBatchToken batchRequest) { string lowerBatchText = batchRequest.Text.ToLowerInvariant(); - + if (lowerBatchText.Contains("1 / 0")) // SELECT 1/0 { TDSErrorToken errorToken = new TDSErrorToken(8134, 1, 16, "Divide by zero error encountered."); diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/EventSource/EventSourceTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/TracingTests/EventSourceTest.cs similarity index 100% rename from src/Microsoft.Data.SqlClient/tests/ManualTests/EventSource/EventSourceTest.cs rename to src/Microsoft.Data.SqlClient/tests/ManualTests/TracingTests/EventSourceTest.cs diff --git a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/FakeDiagnosticListenerObserver.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/TracingTests/FakeDiagnosticListenerObserver.cs similarity index 97% rename from src/Microsoft.Data.SqlClient/tests/FunctionalTests/FakeDiagnosticListenerObserver.cs rename to src/Microsoft.Data.SqlClient/tests/ManualTests/TracingTests/FakeDiagnosticListenerObserver.cs index 402dbfb3e6..36198c3bb5 100644 --- a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/FakeDiagnosticListenerObserver.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/TracingTests/FakeDiagnosticListenerObserver.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.Diagnostics; -namespace Microsoft.Data.SqlClient.Tests +namespace Microsoft.Data.SqlClient.ManualTesting.Tests { public sealed class FakeDiagnosticListenerObserver : IObserver { diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/TracingTests/TestTdsServer.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/TracingTests/TestTdsServer.cs new file mode 100644 index 0000000000..13f6f7926a --- /dev/null +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/TracingTests/TestTdsServer.cs @@ -0,0 +1,61 @@ +// 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; +using System.Net; +using System.Runtime.CompilerServices; +using Microsoft.SqlServer.TDS.EndPoint; +using Microsoft.SqlServer.TDS.Servers; + +namespace Microsoft.Data.SqlClient.ManualTesting.Tests +{ + internal class TestTdsServer : GenericTDSServer, IDisposable + { + private TDSServerEndPoint _endpoint = null; + + private SqlConnectionStringBuilder connectionStringBuilder; + + public TestTdsServer(TDSServerArguments args) : base(args) { } + + public TestTdsServer(QueryEngine engine, TDSServerArguments args) : base(args) + { + this.Engine = engine; + } + + public static TestTdsServer StartServerWithQueryEngine(QueryEngine engine, bool enableFedAuth = false, bool enableLog = false, [CallerMemberName] string methodName = "") + { + TDSServerArguments args = new TDSServerArguments() + { + Log = enableLog ? Console.Out : null, + }; + + if (enableFedAuth) + { + args.FedAuthRequiredPreLoginOption = Microsoft.SqlServer.TDS.PreLogin.TdsPreLoginFedAuthRequiredOption.FedAuthRequired; + } + + TestTdsServer server = engine == null ? new TestTdsServer(args) : new TestTdsServer(engine, args); + server._endpoint = new TDSServerEndPoint(server) { ServerEndPoint = new IPEndPoint(IPAddress.Any, 0) }; + server._endpoint.EndpointName = methodName; + // The server EventLog should be enabled as it logs the exceptions. + server._endpoint.EventLog = Console.Out; + server._endpoint.Start(); + + int port = server._endpoint.ServerEndPoint.Port; + server.connectionStringBuilder = new SqlConnectionStringBuilder() { DataSource = "localhost," + port, ConnectTimeout = 5, Encrypt = false }; + server.ConnectionString = server.connectionStringBuilder.ConnectionString; + return server; + } + + public static TestTdsServer StartTestServer(bool enableFedAuth = false, bool enableLog = false, [CallerMemberName] string methodName = "") + { + return StartServerWithQueryEngine(null, false, false, methodName); + } + + public void Dispose() => _endpoint?.Stop(); + + public string ConnectionString { get; private set; } + + } +} diff --git a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/CoreFx.Private.TestUtilities.csproj b/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/CoreFx.Private.TestUtilities.csproj index 067a522d0f..1825cd49b0 100644 --- a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/CoreFx.Private.TestUtilities.csproj +++ b/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/CoreFx.Private.TestUtilities.csproj @@ -18,15 +18,9 @@ - - - - - - - + diff --git a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/Diagnostics/RemoteExecutorTestBase.Process.cs b/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/Diagnostics/RemoteExecutorTestBase.Process.cs deleted file mode 100644 index c608daafe4..0000000000 --- a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/Diagnostics/RemoteExecutorTestBase.Process.cs +++ /dev/null @@ -1,80 +0,0 @@ -// 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.IO; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Threading.Tasks; -using Xunit; - -namespace System.Diagnostics -{ - /// Base class used for all tests that need to spawn a remote process. - public abstract partial class RemoteExecutorTestBase : FileCleanupTestBase - { - /// Invokes the method from this assembly in another process using the specified arguments. - /// The method to invoke. - /// The arguments to pass to the method. - /// true if this function should Start the Process; false if that responsibility is left up to the caller. - /// The ProcessStartInfo to use, or null for a default. - /// true if this function should paste the arguments (e.g. surrounding with quotes); false if that responsibility is left up to the caller. - private static RemoteInvokeHandle RemoteInvoke(MethodInfo method, string[] args, RemoteInvokeOptions options, bool pasteArguments = true) - { - options = options ?? new RemoteInvokeOptions(); - - // Verify the specified method returns an int (the exit code) or nothing, - // and that if it accepts any arguments, they're all strings. - Assert.True(method.ReturnType == typeof(void) || method.ReturnType == typeof(int) || method.ReturnType == typeof(Task)); - Assert.All(method.GetParameters(), pi => Assert.Equal(typeof(string), pi.ParameterType)); - - // And make sure it's in this assembly. This isn't critical, but it helps with deployment to know - // that the method to invoke is available because we're already running in this assembly. - Type t = method.DeclaringType; - Assembly a = t.GetTypeInfo().Assembly; - - // Start the other process and return a wrapper for it to handle its lifetime and exit checking. - var psi = options.StartInfo; - psi.UseShellExecute = false; - - if (!options.EnableProfiling) - { - // Profilers / code coverage tools doing coverage of the test process set environment - // variables to tell the targeted process what profiler to load. We don't want the child process - // to be profiled / have code coverage, so we remove these environment variables for that process - // before it's started. - psi.Environment.Remove("Cor_Profiler"); - psi.Environment.Remove("Cor_Enable_Profiling"); - psi.Environment.Remove("CoreClr_Profiler"); - psi.Environment.Remove("CoreClr_Enable_Profiling"); - } - - // If we need the host (if it exists), use it, otherwise target the console app directly. - string metadataArgs = PasteArguments.Paste(new string[] { a.FullName, t.FullName, method.Name, options.ExceptionFile }, pasteFirstArgumentUsingArgV0Rules: false); - string passedArgs = pasteArguments ? PasteArguments.Paste(args, pasteFirstArgumentUsingArgV0Rules: false) : string.Join(" ", args); - string testConsoleAppArgs = ExtraParameter + " " + metadataArgs + " " + passedArgs; - - if (!File.Exists(HostRunner)) - throw new IOException($"{HostRunner} test app isn't present in the test runtime directory."); - - if (options.RunAsSudo) - { - psi.FileName = "sudo"; - psi.Arguments = HostRunner + " " + testConsoleAppArgs; - } - else - { - psi.FileName = HostRunner; - psi.Arguments = testConsoleAppArgs; - } - - // Return the handle to the process, which may or not be started - return new RemoteInvokeHandle(options.Start ? - Process.Start(psi) : - new Process() { StartInfo = psi }, options, - a.FullName, t.FullName, method.Name - ); - } - } -} diff --git a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/Diagnostics/RemoteExecutorTestBase.cs b/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/Diagnostics/RemoteExecutorTestBase.cs deleted file mode 100644 index 881adc22ca..0000000000 --- a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/Diagnostics/RemoteExecutorTestBase.cs +++ /dev/null @@ -1,387 +0,0 @@ -// 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.IO; -using System.Reflection; -using System.Runtime.InteropServices; -using System.Threading.Tasks; -using Xunit; -using Xunit.Sdk; - -namespace System.Diagnostics -{ - /// Base class used for all tests that need to spawn a remote process. - public abstract partial class RemoteExecutorTestBase : FileCleanupTestBase - { - /// A timeout (milliseconds) after which a wait on a remote operation should be considered a failure. - public const int FailWaitTimeoutMilliseconds = 60 * 1000; - /// The exit code returned when the test process exits successfully. - public const int SuccessExitCode = 42; - - /// The name of the test console app. - protected static readonly string TestConsoleApp = Path.GetFullPath("RemoteExecutorConsoleApp.exe"); - - /// Invokes the method from this assembly in another process using the specified arguments. - /// The method to invoke. - /// Options to use for the invocation. - public static RemoteInvokeHandle RemoteInvoke( - Action method, - RemoteInvokeOptions options = null) - { - // There's no exit code to check - options = options ?? new RemoteInvokeOptions(); - options.CheckExitCode = false; - - return RemoteInvoke(GetMethodInfo(method), Array.Empty(), options); - } - - - /// Invokes the method from this assembly in another process using the specified arguments. - /// The method to invoke. - /// Options to use for the invocation. - public static RemoteInvokeHandle RemoteInvoke( - Action method, - string arg, - RemoteInvokeOptions options = null) - { - // There's no exit code to check - options = options ?? new RemoteInvokeOptions(); - options.CheckExitCode = false; - - return RemoteInvoke(GetMethodInfo(method), new[] { arg }, options); - } - - /// Invokes the method from this assembly in another process using the specified arguments. - /// The method to invoke. - /// Options to use for the invocation. - public static RemoteInvokeHandle RemoteInvoke( - Action method, - string arg1, - string arg2, - RemoteInvokeOptions options = null) - { - // There's no exit code to check - options = options ?? new RemoteInvokeOptions(); - options.CheckExitCode = false; - - return RemoteInvoke(GetMethodInfo(method), new[] { arg1, arg2 }, options); - } - - /// Invokes the method from this assembly in another process using the specified arguments. - /// The method to invoke. - /// Options to use for the invocation. - public static RemoteInvokeHandle RemoteInvoke( - Action method, - string arg1, - string arg2, - string arg3, - RemoteInvokeOptions options = null) - { - // There's no exit code to check - options = options ?? new RemoteInvokeOptions(); - options.CheckExitCode = false; - - return RemoteInvoke(GetMethodInfo(method), new[] { arg1, arg2, arg3 }, options); - } - - /// Invokes the method from this assembly in another process using the specified arguments. - /// The method to invoke. - /// Options to use for the invocation. - public static RemoteInvokeHandle RemoteInvoke( - Action method, - string arg1, - string arg2, - string arg3, - string arg4, - RemoteInvokeOptions options = null) - { - // There's no exit code to check - options = options ?? new RemoteInvokeOptions(); - options.CheckExitCode = false; - - return RemoteInvoke(GetMethodInfo(method), new[] { arg1, arg2, arg3, arg4 }, options); - } - - /// Invokes the method from this assembly in another process using the specified arguments. - /// The method to invoke. - /// Options to use for the invocation. - public static RemoteInvokeHandle RemoteInvoke( - Func method, - RemoteInvokeOptions options = null) - { - return RemoteInvoke(GetMethodInfo(method), Array.Empty(), options); - } - - /// Invokes the method from this assembly in another process using the specified arguments. - /// The method to invoke. - /// Options to use for the invocation. - public static RemoteInvokeHandle RemoteInvoke( - Func> method, - RemoteInvokeOptions options = null) - { - return RemoteInvoke(GetMethodInfo(method), Array.Empty(), options); - } - - /// Invokes the method from this assembly in another process using the specified arguments. - /// The method to invoke. - /// The argument to pass to the method. - /// Options to use for the invocation. - public static RemoteInvokeHandle RemoteInvoke( - Func> method, - string arg, - RemoteInvokeOptions options = null) - { - return RemoteInvoke(GetMethodInfo(method), new[] { arg }, options); - } - - /// Invokes the method from this assembly in another process using the specified arguments. - /// The method to invoke. - /// The first argument to pass to the method. - /// The second argument to pass to the method. - /// Options to use for the invocation. - public static RemoteInvokeHandle RemoteInvoke( - Func> method, - string arg1, string arg2, - RemoteInvokeOptions options = null) - { - return RemoteInvoke(GetMethodInfo(method), new[] { arg1, arg2 }, options); - } - - /// Invokes the method from this assembly in another process using the specified arguments. - /// The method to invoke. - /// The argument to pass to the method. - /// Options to use for the invocation. - public static RemoteInvokeHandle RemoteInvoke( - Func method, - string arg, - RemoteInvokeOptions options = null) - { - return RemoteInvoke(GetMethodInfo(method), new[] { arg }, options); - } - - /// Invokes the method from this assembly in another process using the specified arguments. - /// The method to invoke. - /// The first argument to pass to the method. - /// The second argument to pass to the method. - /// Options to use for the invocation. - public static RemoteInvokeHandle RemoteInvoke( - Func method, - string arg1, string arg2, - RemoteInvokeOptions options = null) - { - return RemoteInvoke(GetMethodInfo(method), new[] { arg1, arg2 }, options); - } - - /// Invokes the method from this assembly in another process using the specified arguments. - /// The method to invoke. - /// The first argument to pass to the method. - /// The second argument to pass to the method. - /// The third argument to pass to the method. - /// Options to use for the invocation. - public static RemoteInvokeHandle RemoteInvoke( - Func method, - string arg1, string arg2, string arg3, - RemoteInvokeOptions options = null) - { - return RemoteInvoke(GetMethodInfo(method), new[] { arg1, arg2, arg3 }, options); - } - - /// Invokes the method from this assembly in another process using the specified arguments. - /// The method to invoke. - /// The first argument to pass to the method. - /// The second argument to pass to the method. - /// The third argument to pass to the method. - /// The fourth argument to pass to the method. - /// Options to use for the invocation. - public static RemoteInvokeHandle RemoteInvoke( - Func method, - string arg1, string arg2, string arg3, string arg4, - RemoteInvokeOptions options = null) - { - return RemoteInvoke(GetMethodInfo(method), new[] { arg1, arg2, arg3, arg4 }, options); - } - - /// Invokes the method from this assembly in another process using the specified arguments. - /// The method to invoke. - /// The first argument to pass to the method. - /// The second argument to pass to the method. - /// The third argument to pass to the method. - /// The fourth argument to pass to the method. - /// The fifth argument to pass to the method. - /// Options to use for the invocation. - public static RemoteInvokeHandle RemoteInvoke( - Func method, - string arg1, string arg2, string arg3, string arg4, string arg5, - RemoteInvokeOptions options = null) - { - return RemoteInvoke(GetMethodInfo(method), new[] { arg1, arg2, arg3, arg4, arg5 }, options); - } - - /// Invokes the method from this assembly in another process using the specified arguments without performing any modifications to the arguments. - /// The method to invoke. - /// The arguments to pass to the method. - /// Options to use for the invocation. - public static RemoteInvokeHandle RemoteInvokeRaw(Delegate method, string unparsedArg, - RemoteInvokeOptions options = null) - { - return RemoteInvoke(GetMethodInfo(method), new[] { unparsedArg }, options, pasteArguments: false); - } - - private static MethodInfo GetMethodInfo(Delegate d) - { - // RemoteInvoke doesn't support marshaling state on classes associated with - // the delegate supplied (often a display class of a lambda). If such fields - // are used, odd errors result, e.g. NullReferenceExceptions during the remote - // execution. Try to ward off the common cases by proactively failing early - // if it looks like such fields are needed. - if (d.Target != null) - { - // The only fields on the type should be compiler-defined (any fields of the compiler's own - // making generally include '<' and '>', as those are invalid in C# source). Note that this logic - // may need to be revised in the future as the compiler changes, as this relies on the specifics of - // actually how the compiler handles lifted fields for lambdas. - Type targetType = d.Target.GetType(); - Assert.All( - targetType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fi => Assert.True(fi.Name.IndexOf('<') != -1, $"Field marshaling is not supported by {nameof(RemoteInvoke)}: {fi.Name}")); - } - - return d.GetMethodInfo(); - } - - /// A cleanup handle to the Process created for the remote invocation. - public sealed class RemoteInvokeHandle : IDisposable - { - public RemoteInvokeHandle(Process process, RemoteInvokeOptions options, string assemblyName = null, string className = null, string methodName = null) - { - Process = process; - Options = options; - AssemblyName = assemblyName; - ClassName = className; - MethodName = methodName; - } - - private int _exitCode; - public int ExitCode - { - get - { - if (!PlatformDetection.IsUap) - { - Process.WaitForExit(); - return Process.ExitCode; - } - return _exitCode; - } - internal set - { - if (!PlatformDetection.IsUap) - { - throw new PlatformNotSupportedException("ExitCode property can only be set in UWP"); - } - _exitCode = value; - } - } - public Process Process { get; set; } - public RemoteInvokeOptions Options { get; private set; } - public string AssemblyName { get; private set; } - public string ClassName { get; private set; } - public string MethodName { get; private set; } - - public void Dispose() - { - GC.SuppressFinalize(this); // before Dispose(true) in case the Dispose call throws - Dispose(disposing: true); - } - - private void Dispose(bool disposing) - { - Assert.True(disposing, $"A test {AssemblyName}!{ClassName}.{MethodName} forgot to Dispose() the result of RemoteInvoke()"); - - if (Process != null) - { - // A bit unorthodox to do throwing operations in a Dispose, but by doing it here we avoid - // needing to do this in every derived test and keep each test much simpler. - try - { - Assert.True(Process.WaitForExit(Options.TimeOut), - $"Timed out after {Options.TimeOut}ms waiting for remote process {Process.Id}"); - - if (File.Exists(Options.ExceptionFile)) - { - throw new RemoteExecutionException(File.ReadAllText(Options.ExceptionFile)); - } - - if (Options.CheckExitCode) - { - int expected = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? Options.ExpectedExitCode : unchecked((sbyte)Options.ExpectedExitCode); - int actual = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? Process.ExitCode : unchecked((sbyte)Process.ExitCode); - - Assert.True(expected == actual, $"Exit code was {Process.ExitCode} but it should have been {Options.ExpectedExitCode}"); - } - } - finally - { - if (File.Exists(Options.ExceptionFile)) - { - File.Delete(Options.ExceptionFile); - } - - // Cleanup - try - { Process.Kill(); } - catch { } // ignore all cleanup errors - - Process.Dispose(); - Process = null; - } - } - } - - ~RemoteInvokeHandle() - { - // Finalizer flags tests that omitted the explicit Dispose() call; they must have it, or they aren't - // waiting on the remote execution - Dispose(disposing: false); - } - - private sealed class RemoteExecutionException : XunitException - { - internal RemoteExecutionException(string stackTrace) : base("Remote process failed with an unhandled exception.", stackTrace) { } - } - } - } - - /// Options used with RemoteInvoke. - public sealed class RemoteInvokeOptions - { - private bool _runAsSudo; - - public bool Start { get; set; } = true; - public ProcessStartInfo StartInfo { get; set; } = new ProcessStartInfo(); - public bool EnableProfiling { get; set; } = true; - public bool CheckExitCode { get; set; } = true; - - public int TimeOut { get; set; } = RemoteExecutorTestBase.FailWaitTimeoutMilliseconds; - public int ExpectedExitCode { get; set; } = RemoteExecutorTestBase.SuccessExitCode; - public string ExceptionFile { get; } = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); - - public bool RunAsSudo - { - get - { - return _runAsSudo; - } - set - { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - throw new PlatformNotSupportedException(); - } - - _runAsSudo = value; - } - } - } -} diff --git a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/Diagnostics/RemoteExecutorTestBase.netcore.cs b/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/Diagnostics/RemoteExecutorTestBase.netcore.cs deleted file mode 100644 index d0b9aa043b..0000000000 --- a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/Diagnostics/RemoteExecutorTestBase.netcore.cs +++ /dev/null @@ -1,18 +0,0 @@ -// 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.IO; -using System.Runtime.InteropServices; - -namespace System.Diagnostics -{ - /// Base class used for all tests that need to spawn a remote process. - public abstract partial class RemoteExecutorTestBase : FileCleanupTestBase - { - protected static readonly string HostRunnerName = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "dotnet.exe" : "dotnet"; - protected static readonly string HostRunner = Process.GetCurrentProcess().MainModule.FileName; - - private static readonly string ExtraParameter = TestConsoleApp; - } -} diff --git a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/Diagnostics/RemoteExecutorTestBase.netfx.cs b/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/Diagnostics/RemoteExecutorTestBase.netfx.cs deleted file mode 100644 index 01f6991471..0000000000 --- a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/Diagnostics/RemoteExecutorTestBase.netfx.cs +++ /dev/null @@ -1,17 +0,0 @@ -// 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.IO; - -namespace System.Diagnostics -{ - /// Base class used for all tests that need to spawn a remote process. - public abstract partial class RemoteExecutorTestBase : FileCleanupTestBase - { - protected static readonly string HostRunnerName = "xunit.console.exe"; - protected static readonly string HostRunner = TestConsoleApp; - - private static readonly string ExtraParameter = ""; - } -} diff --git a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/Diagnostics/RemoteExecutorTestBase.uap.cs b/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/Diagnostics/RemoteExecutorTestBase.uap.cs deleted file mode 100644 index a90e0c3270..0000000000 --- a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/Diagnostics/RemoteExecutorTestBase.uap.cs +++ /dev/null @@ -1,78 +0,0 @@ -// 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 Xunit; -using System.IO; -using System.Reflection; -using System.Threading.Tasks; -using Windows.ApplicationModel; -using Windows.Foundation.Collections; -using Windows.ApplicationModel.AppService; - -namespace System.Diagnostics -{ - /// Base class used for all tests that need to spawn a remote process. - public abstract partial class RemoteExecutorTestBase : FileCleanupTestBase - { - protected static readonly string HostRunnerName = "xunit.runner.uap.exe"; - protected static readonly string HostRunner = "xunit.runner.uap"; - - /// Invokes the method from this assembly in another process using the specified arguments. - /// The method to invoke. - /// The arguments to pass to the method. - /// The options to execute the remote process. - /// Unused in UAP. - private static RemoteInvokeHandle RemoteInvoke(MethodInfo method, string[] args, RemoteInvokeOptions options, bool pasteArguments = false) - { - options = options ?? new RemoteInvokeOptions(); - - // Verify the specified method returns an int (the exit code) or nothing, - // and that if it accepts any arguments, they're all strings. - Assert.True(method.ReturnType == typeof(void) || method.ReturnType == typeof(int) || method.ReturnType == typeof(Task)); - Assert.All(method.GetParameters(), pi => Assert.Equal(typeof(string), pi.ParameterType)); - - // And make sure it's in this assembly. This isn't critical, but it helps with deployment to know - // that the method to invoke is available because we're already running in this assembly. - Type t = method.DeclaringType; - Assembly a = t.GetTypeInfo().Assembly; - int exitCode; - - using (AppServiceConnection remoteExecutionService = new AppServiceConnection()) - { - // Here, we use the app service name defined in the app service provider's Package.appxmanifest file in the section. - remoteExecutionService.AppServiceName = "com.microsoft.corefxuaptests"; - remoteExecutionService.PackageFamilyName = Package.Current.Id.FamilyName; - - AppServiceConnectionStatus status = remoteExecutionService.OpenAsync().GetAwaiter().GetResult(); - if (status != AppServiceConnectionStatus.Success) - { - throw new IOException($"RemoteInvoke cannot open the remote service. Open Service Status: {status}"); - } - - ValueSet message = new ValueSet(); - - message.Add("AssemblyName", a.FullName); - message.Add("TypeName", t.FullName); - message.Add("MethodName", method.Name); - - int i = 0; - foreach (string arg in args) - { - message.Add("Arg" + i, arg); - i++; - } - - AppServiceResponse response = remoteExecutionService.SendMessageAsync(message).GetAwaiter().GetResult(); - - Assert.True(response.Status == AppServiceResponseStatus.Success, $"response.Status = {response.Status}"); - exitCode = (int)response.Message["Results"]; - Assert.True(!options.CheckExitCode || exitCode == options.ExpectedExitCode, (string)response.Message["Log"] + Environment.NewLine + $"Returned Error code: {exitCode}"); - } - // RemoteInvokeHandle is not really needed in the UAP scenario but we use it just to have consistent interface as non UAP - var handle = new RemoteInvokeHandle(null, options, null, null, null); - handle.ExitCode = exitCode; - return handle; - } - } -} diff --git a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/Diagnostics/RemoteExecutorTestBase.uapaot.cs b/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/Diagnostics/RemoteExecutorTestBase.uapaot.cs deleted file mode 100644 index adc0b6af27..0000000000 --- a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/Diagnostics/RemoteExecutorTestBase.uapaot.cs +++ /dev/null @@ -1,18 +0,0 @@ -// 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.IO; - -namespace System.Diagnostics -{ - /// Base class used for all tests that need to spawn a remote process. - public abstract partial class RemoteExecutorTestBase : FileCleanupTestBase - { - protected static readonly string HostRunnerName = "xunit.console.netcore.exe"; - protected static readonly string HostRunner = TestConsoleApp; - - private static readonly string ExtraParameter = ""; - } - -} diff --git a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/IO/FileCleanupTestBase.cs b/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/IO/FileCleanupTestBase.cs deleted file mode 100644 index 9c0157170c..0000000000 --- a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/IO/FileCleanupTestBase.cs +++ /dev/null @@ -1,131 +0,0 @@ -// 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 Xunit; -using System.Diagnostics; -using System.Runtime.CompilerServices; -using System.Threading; - -namespace System.IO -{ - /// Base class for test classes the use temporary files that need to be cleaned up. - public abstract class FileCleanupTestBase : IDisposable - { - private static readonly Lazy s_isElevated = new Lazy(() => AdminHelpers.IsProcessElevated()); - - private string fallbackGuid = Guid.NewGuid().ToString("N").Substring(0, 10); - - protected static bool IsProcessElevated => s_isElevated.Value; - - /// Initialize the test class base. This creates the associated test directory. - protected FileCleanupTestBase() - { - // Use a unique test directory per test class. The test directory lives in the user's temp directory, - // and includes both the name of the test class and a random string. The test class name is included - // so that it can be easily correlated if necessary, and the random string to helps avoid conflicts if - // the same test should be run concurrently with itself (e.g. if a [Fact] method lives on a base class) - // or if some stray files were left over from a previous run. - - // Make 3 attempts since we have seen this on rare occasions fail with access denied, perhaps due to machine - // configuration, and it doesn't make sense to fail arbitrary tests for this reason. - string failure = string.Empty; - for (int i = 0; i <= 2; i++) - { - TestDirectory = Path.Combine(Path.GetTempPath(), GetType().Name + "_" + Path.GetRandomFileName()); - try - { - Directory.CreateDirectory(TestDirectory); - break; - } - catch (Exception ex) - { - failure += ex.ToString() + Environment.NewLine; - Thread.Sleep(10); // Give a transient condition like antivirus/indexing a chance to go away - } - } - - Assert.True(Directory.Exists(TestDirectory), $"FileCleanupTestBase failed to create {TestDirectory}. {failure}"); - } - - /// Delete the associated test directory. - ~FileCleanupTestBase() - { - Dispose(false); - } - - /// Delete the associated test directory. - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - /// Delete the associated test directory. - protected virtual void Dispose(bool disposing) - { - // No managed resources to clean up, so disposing is ignored. - - try - { Directory.Delete(TestDirectory, recursive: true); } - catch { } // avoid exceptions escaping Dispose - } - - /// - /// Gets the test directory into which all files and directories created by tests should be stored. - /// This directory is isolated per test class. - /// - protected string TestDirectory { get; } - - /// Gets a test file full path that is associated with the call site. - /// An optional index value to use as a suffix on the file name. Typically a loop index. - /// The member name of the function calling this method. - /// The line number of the function calling this method. - protected string GetTestFilePath(int? index = null, [CallerMemberName] string memberName = null, [CallerLineNumber] int lineNumber = 0) => - Path.Combine(TestDirectory, GetTestFileName(index, memberName, lineNumber)); - - /// Gets a test file name that is associated with the call site. - /// An optional index value to use as a suffix on the file name. Typically a loop index. - /// The member name of the function calling this method. - /// The line number of the function calling this method. - protected string GetTestFileName(int? index = null, [CallerMemberName] string memberName = null, [CallerLineNumber] int lineNumber = 0) - { - string testFileName = GenerateTestFileName(index, memberName, lineNumber); - string testFilePath = Path.Combine(TestDirectory, testFileName); - - const int maxLength = 260 - 5; // Windows MAX_PATH minus a bit - - int excessLength = testFilePath.Length - maxLength; - - if (excessLength > 0) - { - // The path will be too long for Windows -- can we - // trim memberName to fix it? - if (excessLength < memberName.Length + "...".Length) - { - // Take a chunk out of the middle as perhaps it's the least interesting part of the name - memberName = memberName.Substring(0, memberName.Length / 2 - excessLength / 2) + "..." + memberName.Substring(memberName.Length / 2 + excessLength / 2); - - testFileName = GenerateTestFileName(index, memberName, lineNumber); - testFilePath = Path.Combine(TestDirectory, testFileName); - } - else - { - return fallbackGuid; - } - } - - Debug.Assert(testFilePath.Length <= maxLength + "...".Length); - - return testFileName; - } - - private string GenerateTestFileName(int? index, string memberName, int lineNumber) => - string.Format( - index.HasValue ? "{0}_{1}_{2}_{3}" : "{0}_{1}_{3}", - memberName ?? "TestBase", - lineNumber, - index.GetValueOrDefault(), - Guid.NewGuid().ToString("N").Substring(0, 8)); // randomness to avoid collisions between derived test classes using same base method concurrently - } -} diff --git a/src/Microsoft.Data.SqlClient/tests/tools/TDS/TDS.EndPoint/TDS.EndPoint.csproj b/src/Microsoft.Data.SqlClient/tests/tools/TDS/TDS.EndPoint/TDS.EndPoint.csproj index 2842287093..51e236bf35 100644 --- a/src/Microsoft.Data.SqlClient/tests/tools/TDS/TDS.EndPoint/TDS.EndPoint.csproj +++ b/src/Microsoft.Data.SqlClient/tests/tools/TDS/TDS.EndPoint/TDS.EndPoint.csproj @@ -59,4 +59,4 @@ - \ No newline at end of file + diff --git a/src/NuGet.config b/src/NuGet.config index 2ba88b8eb4..cb7e89cd4a 100644 --- a/src/NuGet.config +++ b/src/NuGet.config @@ -4,5 +4,6 @@ + diff --git a/tools/props/Versions.props b/tools/props/Versions.props index d1724e7806..a56e0d4473 100644 --- a/tools/props/Versions.props +++ b/tools/props/Versions.props @@ -18,7 +18,7 @@ 4.7.1 5.6.0 5.6.0 - 4.5.0 + 4.5.1 4.3.0 @@ -29,7 +29,7 @@ 4.7.0 4.7.0 4.3.0 - 4.5.3 + 4.5.4 4.3.0 4.7.0 4.7.0 @@ -58,5 +58,7 @@ 4.6.0 4.3.0 2.4.1 + 5.0.0-beta.20206.4 + 2.0.8 diff --git a/tools/specs/Microsoft.Data.SqlClient.nuspec b/tools/specs/Microsoft.Data.SqlClient.nuspec index c4b3efc0c2..5466991bb1 100644 --- a/tools/specs/Microsoft.Data.SqlClient.nuspec +++ b/tools/specs/Microsoft.Data.SqlClient.nuspec @@ -59,9 +59,9 @@ When using NuGet 3.x this package requires at least version 3.4. - + - +