From 865ac03ea9e0d362b38429348b8694ec960ae3a2 Mon Sep 17 00:00:00 2001 From: DavoudEshtehari <61173489+DavoudEshtehari@users.noreply.github.com> Date: Thu, 10 Mar 2022 16:18:53 -0800 Subject: [PATCH] Fix | Improved DSEnumerator's test and fixed string format (#1541) --- .../Data/Sql/SqlDataSourceEnumeratorNativeHelper.cs | 4 ++-- .../SqlDSEnumeratorTest/SqlDataSourceEnumeratorTest.cs | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/Sql/SqlDataSourceEnumeratorNativeHelper.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/Sql/SqlDataSourceEnumeratorNativeHelper.cs index db40a6439e..f6ebfc4b8f 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/Sql/SqlDataSourceEnumeratorNativeHelper.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/Sql/SqlDataSourceEnumeratorNativeHelper.cs @@ -46,7 +46,7 @@ internal static DataTable GetDataSources() finally { handle = SNINativeMethodWrapper.SNIServerEnumOpen(); - SqlClientEventSource.Log.TryTraceEvent(" {3} returned handle = {4}.", + SqlClientEventSource.Log.TryTraceEvent(" {2} returned handle = {3}.", nameof(SqlDataSourceEnumeratorNativeHelper), nameof(GetDataSources), nameof(SNINativeMethodWrapper.SNIServerEnumOpen), handle); @@ -80,7 +80,7 @@ internal static DataTable GetDataSources() if (handle != ADP.s_ptrZero) { SNINativeMethodWrapper.SNIServerEnumClose(handle); - SqlClientEventSource.Log.TryTraceEvent(" {3} called.", + SqlClientEventSource.Log.TryTraceEvent(" {2} called.", nameof(SqlDataSourceEnumeratorNativeHelper), nameof(GetDataSources), nameof(SNINativeMethodWrapper.SNIServerEnumClose)); diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlDSEnumeratorTest/SqlDataSourceEnumeratorTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlDSEnumeratorTest/SqlDataSourceEnumeratorTest.cs index 118a2412c3..f5a9a063ac 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlDSEnumeratorTest/SqlDataSourceEnumeratorTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlDSEnumeratorTest/SqlDataSourceEnumeratorTest.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System; +using System.Linq; using System.ServiceProcess; using Microsoft.Data.Sql; using Xunit; @@ -36,9 +37,12 @@ private SqlDataSourceEnumerator GetDSEnumerator() { // SQL Server Browser runs as a Windows service. // TODO: This assessment can be done on CI. - ServiceController sc = new("SQLBrowser"); - Assert.Equal(ServiceControllerStatus.Running, sc.Status); - + ServiceController[] services = ServiceController.GetServices(Environment.MachineName); + ServiceController service = services.FirstOrDefault(s => s.ServiceName == "SQLBrowser"); + if (service != null) + { + Assert.Equal(ServiceControllerStatus.Running, service.Status); + } return SqlDataSourceEnumerator.Instance; } }