diff --git a/Directory.Build.props b/Directory.Build.props index 291e3b4f05..f8cec32fb2 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -34,6 +34,26 @@ net6.0;net7.0;net8.0 + + + + + + + + + false + true + true + $(DefineConstants);IS_DATA_SOURCE_SUPPORTED + + diff --git a/Directory.Packages.props b/Directory.Packages.props index 45514197e9..fae29b7552 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -30,6 +30,9 @@ + + + @@ -37,6 +40,7 @@ + diff --git a/samples/FxExtensibility/FxExtensibility.csproj b/samples/FxExtensibility/FxExtensibility.csproj index 13face57bd..152e1d9d23 100644 --- a/samples/FxExtensibility/FxExtensibility.csproj +++ b/samples/FxExtensibility/FxExtensibility.csproj @@ -8,7 +8,7 @@ MSTest.Extensibility.Samples MSTest.Extensibility.Samples - TRACE + $(DefineConstants);TRACE prompt 4 diff --git a/src/Adapter/MSTest.TestAdapter/MSTest.TestAdapter.csproj b/src/Adapter/MSTest.TestAdapter/MSTest.TestAdapter.csproj index 7eda3660e6..ecf487a7c2 100644 --- a/src/Adapter/MSTest.TestAdapter/MSTest.TestAdapter.csproj +++ b/src/Adapter/MSTest.TestAdapter/MSTest.TestAdapter.csproj @@ -41,7 +41,7 @@ Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter - TRACE + $(DefineConstants);TRACE true diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Data/CsvDataConnection.cs b/src/Adapter/MSTestAdapter.PlatformServices/Data/CsvDataConnection.cs index 759b8f9645..f2e8d14525 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Data/CsvDataConnection.cs +++ b/src/Adapter/MSTestAdapter.PlatformServices/Data/CsvDataConnection.cs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#if NETFRAMEWORK +#if IS_DATA_SOURCE_SUPPORTED using System.Collections; using System.Data; @@ -77,6 +77,13 @@ public override List GetDataTablesAndViews() [SuppressMessage("Microsoft.Security", "CA2100:Review SQL queries for security", Justification = "Not passed in from user.")] public DataTable ReadTable(string tableName, IEnumerable? columns, int maxRows) { +#if !NETFRAMEWORK + if (!OperatingSystem.IsWindows()) + { + // TODO: It looks like the whole Csv logic can be refactored to work on all operating systems by not using OleDbConnection at all? + throw new NotSupportedException("CsvDataConnection is only supported on Windows."); + } +#endif // We specifically use OleDb to read a CSV file... WriteDiagnostics("ReadTable: {0}", tableName); WriteDiagnostics("Current Directory: {0}", Directory.GetCurrentDirectory()); diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Data/OdbcDataConnection.cs b/src/Adapter/MSTestAdapter.PlatformServices/Data/OdbcDataConnection.cs index a02afb0351..753c15ea9d 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Data/OdbcDataConnection.cs +++ b/src/Adapter/MSTestAdapter.PlatformServices/Data/OdbcDataConnection.cs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#if NETFRAMEWORK +#if IS_DATA_SOURCE_SUPPORTED using System.Data.Odbc; diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Data/OleDataConnection.cs b/src/Adapter/MSTestAdapter.PlatformServices/Data/OleDataConnection.cs index afe551583c..06000a76f0 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Data/OleDataConnection.cs +++ b/src/Adapter/MSTestAdapter.PlatformServices/Data/OleDataConnection.cs @@ -1,9 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#if NETFRAMEWORK +#if IS_DATA_SOURCE_SUPPORTED using System.Data.OleDb; +#if !NETFRAMEWORK +using System.Runtime.Versioning; +#endif using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -12,6 +15,9 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Dat /// /// Utility classes to access databases, and to handle quoted strings etc for OLE DB. /// +#if !NETFRAMEWORK +[SupportedOSPlatform("windows")] +#endif internal sealed class OleDataConnection : TestDataConnectionSql { private readonly bool _isMSSql; diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Data/SqlDataConnection.cs b/src/Adapter/MSTestAdapter.PlatformServices/Data/SqlDataConnection.cs index e0bb32fa1b..6f25bdd4df 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Data/SqlDataConnection.cs +++ b/src/Adapter/MSTestAdapter.PlatformServices/Data/SqlDataConnection.cs @@ -1,9 +1,13 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#if NETFRAMEWORK +#if IS_DATA_SOURCE_SUPPORTED +#if NETFRAMEWORK using System.Data.SqlClient; +#else +using Microsoft.Data.SqlClient; +#endif using Microsoft.VisualStudio.TestTools.UnitTesting; diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Data/TestDataConnection.cs b/src/Adapter/MSTestAdapter.PlatformServices/Data/TestDataConnection.cs index 799a4cfbfd..6c3f5a94ef 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Data/TestDataConnection.cs +++ b/src/Adapter/MSTestAdapter.PlatformServices/Data/TestDataConnection.cs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#if NETFRAMEWORK +#if IS_DATA_SOURCE_SUPPORTED using System.Collections; using System.Data; using System.Data.Common; diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Data/TestDataConnectionFactory.cs b/src/Adapter/MSTestAdapter.PlatformServices/Data/TestDataConnectionFactory.cs index aa332bbb2f..e85f181281 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Data/TestDataConnectionFactory.cs +++ b/src/Adapter/MSTestAdapter.PlatformServices/Data/TestDataConnectionFactory.cs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#if NETFRAMEWORK +#if IS_DATA_SOURCE_SUPPORTED using Microsoft.VisualStudio.TestTools.UnitTesting; diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Data/TestDataConnectionSql.cs b/src/Adapter/MSTestAdapter.PlatformServices/Data/TestDataConnectionSql.cs index 1f9ca7507c..7f7f076bd0 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Data/TestDataConnectionSql.cs +++ b/src/Adapter/MSTestAdapter.PlatformServices/Data/TestDataConnectionSql.cs @@ -1,17 +1,22 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#if NETFRAMEWORK +#if IS_DATA_SOURCE_SUPPORTED using System.Collections; using System.Data; using System.Data.Common; using System.Data.Odbc; using System.Data.OleDb; +#if NETFRAMEWORK using System.Data.SqlClient; +#endif using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Text; +#if !NETFRAMEWORK +using Microsoft.Data.SqlClient; +#endif using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -35,11 +40,11 @@ protected internal TestDataConnectionSql(string invariantProviderName, string co DebugEx.Assert(Factory != null, "factory should not be null."); WriteDiagnostics("DbProviderFactory {0}", Factory); - _connection = Factory.CreateConnection(); + _connection = Factory.CreateConnection()!; DebugEx.Assert(_connection != null, "connection"); WriteDiagnostics("DbConnection {0}", _connection); - CommandBuilder = Factory.CreateCommandBuilder(); + CommandBuilder = Factory.CreateCommandBuilder()!; DebugEx.Assert(CommandBuilder != null, "builder"); WriteDiagnostics("DbCommandBuilder {0}", CommandBuilder); @@ -81,6 +86,13 @@ public static TestDataConnectionSql Create(string invariantProviderName, string } else if (string.Equals(invariantProviderName, "System.Data.OleDb", StringComparison.OrdinalIgnoreCase)) { +#if !NETFRAMEWORK + if (!OperatingSystem.IsWindows()) + { + throw new NotSupportedException($"Failed to create connection to '{connectionString}'. OleDbConnection is only supported on Windows."); + } +#endif + return new OleDataConnection(invariantProviderName, connectionString, dataFolders); } else if (string.Equals(invariantProviderName, "System.Data.Odbc", StringComparison.OrdinalIgnoreCase)) @@ -485,7 +497,7 @@ public override List GetDataTablesAndViews() try { WriteDiagnostics("Getting schema table {0}", metadata.SchemaTable); - dataTable = Connection.GetSchema(metadata.SchemaTable); + dataTable = Connection.GetSchema(metadata.SchemaTable!); } catch (Exception ex) { @@ -521,9 +533,9 @@ public override List GetDataTablesAndViews() } // Get the schema name, and filter bad schemas - if (row[metadata.SchemaColumn] != DBNull.Value) + if (row[metadata.SchemaColumn!] != DBNull.Value) { - tableSchema = row[metadata.SchemaColumn] as string; + tableSchema = row[metadata.SchemaColumn!] as string; if (IsInArray(tableSchema, metadata.InvalidSchemas)) { @@ -536,7 +548,7 @@ public override List GetDataTablesAndViews() isDefaultSchema = string.Equals(tableSchema, defaultSchema, StringComparison.OrdinalIgnoreCase); } - string? tableName = row[metadata.NameColumn] as string; + string? tableName = row[metadata.NameColumn!] as string; WriteDiagnostics("Table {0}{1} found", tableSchema != null ? tableSchema + "." : string.Empty, tableName); // If schema is defined and is not equal to default, prepend table schema in front of the table. @@ -599,7 +611,7 @@ public override List GetDataTablesAndViews() foreach (DataRow columnRow in columns.Rows) { WriteDiagnostics("Column info: {0}", columnRow); - result.Add(columnRow["COLUMN_NAME"].ToString()); + result.Add(columnRow["COLUMN_NAME"].ToString()!); } // Now we are done, since for any particular table or view, all the columns @@ -723,6 +735,12 @@ protected virtual bool IsUserSchema(string tableSchema) => { var oleDbConnection = Connection as OleDbConnection; var odbcConnection = Connection as OdbcConnection; +#if !NETFRAMEWORK + if (oleDbConnection is not null && !OperatingSystem.IsWindows()) + { + throw new NotSupportedException("OleDbConnection is only supported on Windows."); + } +#endif DebugEx.Assert( Connection is SqlConnection || (oleDbConnection != null && IsMSSql(oleDbConnection.Provider)) || @@ -732,7 +750,11 @@ Connection is SqlConnection || DebugEx.Assert(IsOpen(), "The connection must already be open!"); DebugEx.Assert(!StringEx.IsNullOrEmpty(Connection.ServerVersion), "GetDefaultSchema: the ServerVersion is null or empty!"); +#if NETFRAMEWORK int index = Connection.ServerVersion.IndexOf(".", StringComparison.Ordinal); +#else + int index = Connection.ServerVersion.IndexOf('.'); +#endif DebugEx.Assert(index > 0, "GetDefaultSchema: index should be 0"); string versionString = Connection.ServerVersion.Substring(0, index); @@ -776,8 +798,8 @@ Connection is SqlConnection || public override DataTable ReadTable(string tableName, IEnumerable? columns) #pragma warning restore SA1202 // Elements must be ordered by access { - using DbDataAdapter dataAdapter = Factory.CreateDataAdapter(); - using DbCommand command = Factory.CreateCommand(); + using DbDataAdapter dataAdapter = Factory.CreateDataAdapter()!; + using DbCommand command = Factory.CreateCommand()!; // We need to escape bad characters in table name like [Sheet1$] in Excel. // But if table name is quoted in terms of provider, don't touch it to avoid e.g. [dbo.tables.etc]. diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Data/XmlDataConnection.cs b/src/Adapter/MSTestAdapter.PlatformServices/Data/XmlDataConnection.cs index dfa7b3be55..1ca1073195 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Data/XmlDataConnection.cs +++ b/src/Adapter/MSTestAdapter.PlatformServices/Data/XmlDataConnection.cs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#if NETFRAMEWORK +#if IS_DATA_SOURCE_SUPPORTED using System.Collections; using System.Data; using System.Diagnostics.CodeAnalysis; @@ -87,6 +87,9 @@ public XmlDataConnection(string fileName, List dataFolders) [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "Un-tested. Preserving behavior.")] [SuppressMessage("Security", "CA3075:Insecure DTD processing in XML", Justification = "Not enough tests to understand if we would break")] [SuppressMessage("Security", "CA5366:Use XmlReader for 'DataSet.ReadXml()'", Justification = "Not enough tests to understand if we would break")] + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "While this can fail and the analysis is actually correct, it seems like if it happened it's likely to be user's fault?" + + "If the user is referencing type from XML, they should be confident that they are not trimmed.")] private DataSet? LoadDataSet(bool schemaOnly) { try diff --git a/src/Adapter/MSTestAdapter.PlatformServices/MSTestAdapter.PlatformServices.csproj b/src/Adapter/MSTestAdapter.PlatformServices/MSTestAdapter.PlatformServices.csproj index 7752d8d63a..9d68017fa5 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/MSTestAdapter.PlatformServices.csproj +++ b/src/Adapter/MSTestAdapter.PlatformServices/MSTestAdapter.PlatformServices.csproj @@ -13,7 +13,7 @@ Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices - TRACE + $(DefineConstants);TRACE @@ -36,6 +36,10 @@ + + + + diff --git a/src/Adapter/MSTestAdapter.PlatformServices/PublicAPI/net6.0/PublicAPI.Unshipped.txt b/src/Adapter/MSTestAdapter.PlatformServices/PublicAPI/net6.0/PublicAPI.Unshipped.txt index 7dc5c58110..928bd1b127 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/PublicAPI/net6.0/PublicAPI.Unshipped.txt +++ b/src/Adapter/MSTestAdapter.PlatformServices/PublicAPI/net6.0/PublicAPI.Unshipped.txt @@ -1 +1,3 @@ #nullable enable +override Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.TestContextImplementation.DataConnection.get -> System.Data.Common.DbConnection? +override Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.TestContextImplementation.DataRow.get -> System.Data.DataRow? diff --git a/src/Adapter/MSTestAdapter.PlatformServices/PublicAPI/net7.0/PublicAPI.Unshipped.txt b/src/Adapter/MSTestAdapter.PlatformServices/PublicAPI/net7.0/PublicAPI.Unshipped.txt index 7dc5c58110..928bd1b127 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/PublicAPI/net7.0/PublicAPI.Unshipped.txt +++ b/src/Adapter/MSTestAdapter.PlatformServices/PublicAPI/net7.0/PublicAPI.Unshipped.txt @@ -1 +1,3 @@ #nullable enable +override Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.TestContextImplementation.DataConnection.get -> System.Data.Common.DbConnection? +override Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.TestContextImplementation.DataRow.get -> System.Data.DataRow? diff --git a/src/Adapter/MSTestAdapter.PlatformServices/PublicAPI/net8.0/PublicAPI.Unshipped.txt b/src/Adapter/MSTestAdapter.PlatformServices/PublicAPI/net8.0/PublicAPI.Unshipped.txt index 7dc5c58110..928bd1b127 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/PublicAPI/net8.0/PublicAPI.Unshipped.txt +++ b/src/Adapter/MSTestAdapter.PlatformServices/PublicAPI/net8.0/PublicAPI.Unshipped.txt @@ -1 +1,3 @@ #nullable enable +override Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.TestContextImplementation.DataConnection.get -> System.Data.Common.DbConnection? +override Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.TestContextImplementation.DataRow.get -> System.Data.DataRow? diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Services/TestContextImplementation.cs b/src/Adapter/MSTestAdapter.PlatformServices/Services/TestContextImplementation.cs index b67fa921c0..824d12aea5 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Services/TestContextImplementation.cs +++ b/src/Adapter/MSTestAdapter.PlatformServices/Services/TestContextImplementation.cs @@ -2,7 +2,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System.Collections; -#if NETFRAMEWORK +#if IS_DATA_SOURCE_SUPPORTED using System.Data; using System.Data.Common; #endif @@ -53,7 +53,7 @@ public class TestContextImplementation : TestContext, ITestContext /// private UnitTestOutcome _outcome; -#if NETFRAMEWORK +#if IS_DATA_SOURCE_SUPPORTED /// /// DB connection for test context. /// @@ -100,7 +100,7 @@ public TestContextImplementation(ITestMethod testMethod, StringWriter stringWrit /// public override UnitTestOutcome CurrentTestOutcome => _outcome; -#if NETFRAMEWORK +#if IS_DATA_SOURCE_SUPPORTED /// public override DbConnection? DataConnection => _dbConnection; @@ -266,7 +266,7 @@ public void SetException(Exception? exception) /// data row. public void SetDataRow(object? dataRow) { -#if NETFRAMEWORK +#if IS_DATA_SOURCE_SUPPORTED #pragma warning disable IDE0022 // Use expression body for method _dataRow = dataRow as DataRow; #pragma warning restore IDE0022 // Use expression body for method @@ -282,7 +282,7 @@ public void SetDataRow(object? dataRow) /// db Connection. public void SetDataConnection(object? dbConnection) { -#if NETFRAMEWORK +#if IS_DATA_SOURCE_SUPPORTED #pragma warning disable IDE0022 // Use expression body for method _dbConnection = dbConnection as DbConnection; #pragma warning restore IDE0022 // Use expression body for method diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Services/TestDataSource.cs b/src/Adapter/MSTestAdapter.PlatformServices/Services/TestDataSource.cs index 04b6218b9e..2a4c844be9 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Services/TestDataSource.cs +++ b/src/Adapter/MSTestAdapter.PlatformServices/Services/TestDataSource.cs @@ -1,10 +1,13 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#if NETFRAMEWORK +#if IS_DATA_SOURCE_SUPPORTED using System.Configuration; using System.Data; using System.Diagnostics; +#if NET6_0_OR_GREATER +using System.Diagnostics.CodeAnalysis; +#endif using System.Globalization; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Data; @@ -31,15 +34,26 @@ public class TestDataSource : ITestDataSource #if NETFRAMEWORK public IEnumerable? GetData(UTF.ITestMethod testMethodInfo, ITestContext testContext) #else +#if NET6_0_OR_GREATER && IS_DATA_SOURCE_SUPPORTED + [UnconditionalSuppressMessage("SingleFile", "IL3000: Avoid accessing Assembly file path when publishing as a single file", + Justification = "The code handles the Assembly.Location equals null")] +#endif IEnumerable? ITestDataSource.GetData(UTF.ITestMethod testMethodInfo, ITestContext testContext) #endif { -#if NETFRAMEWORK +#if IS_DATA_SOURCE_SUPPORTED // Figure out where (as well as the current directory) we could look for data files // for unit tests this means looking at the location of the test itself + string location = +#if NETFRAMEWORK + testMethodInfo.MethodInfo.Module.Assembly.CodeBase; +#else + // TODO: Should we use AppContext.BaseDirectory when Assembly.Location is null? + testMethodInfo.MethodInfo.Module.Assembly.Location ?? throw new NotSupportedException("DataSourceAttribute is currently not supported when publishing as single file."); +#endif List dataFolders = [ - Path.GetDirectoryName(new Uri(testMethodInfo.MethodInfo.Module.Assembly.CodeBase).LocalPath), + Path.GetDirectoryName(new Uri(location).LocalPath), ]; List dataRowResults = []; @@ -89,7 +103,7 @@ public class TestDataSource : ITestDataSource #endif } -#if NETFRAMEWORK +#if IS_DATA_SOURCE_SUPPORTED /// /// Get permutations for data row access. /// diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Utilities/RandomIntPermutation.cs b/src/Adapter/MSTestAdapter.PlatformServices/Utilities/RandomIntPermutation.cs index 668da63a8a..665e58201b 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Utilities/RandomIntPermutation.cs +++ b/src/Adapter/MSTestAdapter.PlatformServices/Utilities/RandomIntPermutation.cs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#if NETFRAMEWORK +#if IS_DATA_SOURCE_SUPPORTED using System.Collections; diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Utilities/SequentialIntPermutation.cs b/src/Adapter/MSTestAdapter.PlatformServices/Utilities/SequentialIntPermutation.cs index c77c8fe83d..e700c906cd 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Utilities/SequentialIntPermutation.cs +++ b/src/Adapter/MSTestAdapter.PlatformServices/Utilities/SequentialIntPermutation.cs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#if NETFRAMEWORK +#if IS_DATA_SOURCE_SUPPORTED using System.Collections; diff --git a/src/Platform/Microsoft.Testing.Platform.MSBuild/Microsoft.Testing.Platform.MSBuild.csproj b/src/Platform/Microsoft.Testing.Platform.MSBuild/Microsoft.Testing.Platform.MSBuild.csproj index 3af417a7eb..cb2f33b3b0 100644 --- a/src/Platform/Microsoft.Testing.Platform.MSBuild/Microsoft.Testing.Platform.MSBuild.csproj +++ b/src/Platform/Microsoft.Testing.Platform.MSBuild/Microsoft.Testing.Platform.MSBuild.csproj @@ -1,7 +1,7 @@ $(MicrosoftTestingTargetFrameworks);netstandard2.0 - PLATFORM_MSBUILD + $(DefineConstants);PLATFORM_MSBUILD $(NoWarn);NU5100 diff --git a/src/TestFramework/TestFramework.Extensions/ConfigurationSettings/ConfigurationNames.cs b/src/TestFramework/TestFramework.Extensions/ConfigurationSettings/ConfigurationNames.cs index 7350f0802f..7999863010 100644 --- a/src/TestFramework/TestFramework.Extensions/ConfigurationSettings/ConfigurationNames.cs +++ b/src/TestFramework/TestFramework.Extensions/ConfigurationSettings/ConfigurationNames.cs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#if NETFRAMEWORK +#if IS_DATA_SOURCE_SUPPORTED namespace Microsoft.VisualStudio.TestTools.UnitTesting; /// diff --git a/src/TestFramework/TestFramework.Extensions/ConfigurationSettings/DataSourceElement.cs b/src/TestFramework/TestFramework.Extensions/ConfigurationSettings/DataSourceElement.cs index 1d630e02b8..1ead013963 100644 --- a/src/TestFramework/TestFramework.Extensions/ConfigurationSettings/DataSourceElement.cs +++ b/src/TestFramework/TestFramework.Extensions/ConfigurationSettings/DataSourceElement.cs @@ -1,8 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#if NETFRAMEWORK - +#if IS_DATA_SOURCE_SUPPORTED using System.Configuration; namespace Microsoft.VisualStudio.TestTools.UnitTesting; @@ -10,7 +9,12 @@ namespace Microsoft.VisualStudio.TestTools.UnitTesting; /// /// The Data Source element. /// -public sealed class DataSourceElement : ConfigurationElement +#if NETFRAMEWORK +public +#else +internal +#endif +sealed class DataSourceElement : ConfigurationElement { private static readonly ConfigurationProperty NameValue = new(ConfigurationNames.NameAttributeName, typeof(string), string.Empty, ConfigurationPropertyOptions.IsKey | ConfigurationPropertyOptions.IsRequired); private static readonly ConfigurationProperty ConnectionStringValue = new(ConfigurationNames.ConnectionStringAttributeName, typeof(string), string.Empty, ConfigurationPropertyOptions.IsRequired); diff --git a/src/TestFramework/TestFramework.Extensions/ConfigurationSettings/DataSourceElementCollection.cs b/src/TestFramework/TestFramework.Extensions/ConfigurationSettings/DataSourceElementCollection.cs index b2bd44da6f..77ba4a58b0 100644 --- a/src/TestFramework/TestFramework.Extensions/ConfigurationSettings/DataSourceElementCollection.cs +++ b/src/TestFramework/TestFramework.Extensions/ConfigurationSettings/DataSourceElementCollection.cs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#if NETFRAMEWORK +#if IS_DATA_SOURCE_SUPPORTED using System.Configuration; using System.Diagnostics.CodeAnalysis; @@ -12,7 +12,12 @@ namespace Microsoft.VisualStudio.TestTools.UnitTesting; /// The Data source element collection. /// [SuppressMessage("Microsoft.Design", "CA1010:CollectionsShouldImplementGenericInterface", Justification = "Compat")] -public sealed class DataSourceElementCollection : ConfigurationElementCollection +#if NETFRAMEWORK +public +#else +internal +#endif +sealed class DataSourceElementCollection : ConfigurationElementCollection { /// /// Initializes a new instance of the class. diff --git a/src/TestFramework/TestFramework.Extensions/ConfigurationSettings/TestConfiguration.cs b/src/TestFramework/TestFramework.Extensions/ConfigurationSettings/TestConfiguration.cs index cadeb8f74b..dc33c2ca26 100644 --- a/src/TestFramework/TestFramework.Extensions/ConfigurationSettings/TestConfiguration.cs +++ b/src/TestFramework/TestFramework.Extensions/ConfigurationSettings/TestConfiguration.cs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#if NETFRAMEWORK +#if IS_DATA_SOURCE_SUPPORTED using System.Configuration; namespace Microsoft.VisualStudio.TestTools.UnitTesting; @@ -9,7 +9,12 @@ namespace Microsoft.VisualStudio.TestTools.UnitTesting; /// /// Support for configuration settings for Tests. /// -public static class TestConfiguration +#if NETFRAMEWORK +public +#else +internal +#endif +static class TestConfiguration { /// /// Gets the configuration section for tests. diff --git a/src/TestFramework/TestFramework.Extensions/ConfigurationSettings/TestConfigurationSection.cs b/src/TestFramework/TestFramework.Extensions/ConfigurationSettings/TestConfigurationSection.cs index 91fde548cd..0e6eb7ad12 100644 --- a/src/TestFramework/TestFramework.Extensions/ConfigurationSettings/TestConfigurationSection.cs +++ b/src/TestFramework/TestFramework.Extensions/ConfigurationSettings/TestConfigurationSection.cs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#if NETFRAMEWORK +#if IS_DATA_SOURCE_SUPPORTED using System.Configuration; @@ -10,7 +10,12 @@ namespace Microsoft.VisualStudio.TestTools.UnitTesting; /// /// The configuration section for tests. /// -public sealed class TestConfigurationSection : ConfigurationSection +#if NETFRAMEWORK +public +#else +internal +#endif +sealed class TestConfigurationSection : ConfigurationSection { private static readonly ConfigurationProperty DataSourcesValue = new(ConfigurationNames.DataSourcesSectionName, typeof(DataSourceElementCollection), null); diff --git a/src/TestFramework/TestFramework.Extensions/PublicAPI/net6.0/PublicAPI.Unshipped.txt b/src/TestFramework/TestFramework.Extensions/PublicAPI/net6.0/PublicAPI.Unshipped.txt index 815c92006a..0c1292171f 100644 --- a/src/TestFramework/TestFramework.Extensions/PublicAPI/net6.0/PublicAPI.Unshipped.txt +++ b/src/TestFramework/TestFramework.Extensions/PublicAPI/net6.0/PublicAPI.Unshipped.txt @@ -1 +1,3 @@ -#nullable enable \ No newline at end of file +#nullable enable +abstract Microsoft.VisualStudio.TestTools.UnitTesting.TestContext.DataConnection.get -> System.Data.Common.DbConnection? +abstract Microsoft.VisualStudio.TestTools.UnitTesting.TestContext.DataRow.get -> System.Data.DataRow? \ No newline at end of file diff --git a/src/TestFramework/TestFramework.Extensions/PublicAPI/net7.0/PublicAPI.Unshipped.txt b/src/TestFramework/TestFramework.Extensions/PublicAPI/net7.0/PublicAPI.Unshipped.txt index 815c92006a..0c1292171f 100644 --- a/src/TestFramework/TestFramework.Extensions/PublicAPI/net7.0/PublicAPI.Unshipped.txt +++ b/src/TestFramework/TestFramework.Extensions/PublicAPI/net7.0/PublicAPI.Unshipped.txt @@ -1 +1,3 @@ -#nullable enable \ No newline at end of file +#nullable enable +abstract Microsoft.VisualStudio.TestTools.UnitTesting.TestContext.DataConnection.get -> System.Data.Common.DbConnection? +abstract Microsoft.VisualStudio.TestTools.UnitTesting.TestContext.DataRow.get -> System.Data.DataRow? \ No newline at end of file diff --git a/src/TestFramework/TestFramework.Extensions/PublicAPI/net8.0/PublicAPI.Unshipped.txt b/src/TestFramework/TestFramework.Extensions/PublicAPI/net8.0/PublicAPI.Unshipped.txt index 815c92006a..0c1292171f 100644 --- a/src/TestFramework/TestFramework.Extensions/PublicAPI/net8.0/PublicAPI.Unshipped.txt +++ b/src/TestFramework/TestFramework.Extensions/PublicAPI/net8.0/PublicAPI.Unshipped.txt @@ -1 +1,3 @@ -#nullable enable \ No newline at end of file +#nullable enable +abstract Microsoft.VisualStudio.TestTools.UnitTesting.TestContext.DataConnection.get -> System.Data.Common.DbConnection? +abstract Microsoft.VisualStudio.TestTools.UnitTesting.TestContext.DataRow.get -> System.Data.DataRow? \ No newline at end of file diff --git a/src/TestFramework/TestFramework.Extensions/TestContext.cs b/src/TestFramework/TestFramework.Extensions/TestContext.cs index 95f08dcde9..3f3b0ff059 100644 --- a/src/TestFramework/TestFramework.Extensions/TestContext.cs +++ b/src/TestFramework/TestFramework.Extensions/TestContext.cs @@ -2,7 +2,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System.Collections; -#if NETFRAMEWORK +#if IS_DATA_SOURCE_SUPPORTED using System.Data; using System.Data.Common; #endif @@ -57,7 +57,7 @@ public abstract class TestContext public string? TestDisplayName { get; protected set; } -#if NETFRAMEWORK +#if IS_DATA_SOURCE_SUPPORTED /// /// Gets the current data row when test is used for data driven testing. /// diff --git a/src/TestFramework/TestFramework.Extensions/TestFramework.Extensions.csproj b/src/TestFramework/TestFramework.Extensions/TestFramework.Extensions.csproj index 5dcc9df4a5..67f823017c 100644 --- a/src/TestFramework/TestFramework.Extensions/TestFramework.Extensions.csproj +++ b/src/TestFramework/TestFramework.Extensions/TestFramework.Extensions.csproj @@ -34,7 +34,7 @@ Microsoft.VisualStudio.TestTools.UnitTesting Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions - TRACE + $(DefineConstants);TRACE @@ -56,6 +56,7 @@ + diff --git a/src/TestFramework/TestFramework/TestFramework.csproj b/src/TestFramework/TestFramework/TestFramework.csproj index 8f67b0069d..67da309e7f 100644 --- a/src/TestFramework/TestFramework/TestFramework.csproj +++ b/src/TestFramework/TestFramework/TestFramework.csproj @@ -8,7 +8,7 @@ Microsoft.VisualStudio.TestTools.UnitTesting Microsoft.VisualStudio.TestPlatform.TestFramework - TRACE + $(DefineConstants);TRACE diff --git a/test/IntegrationTests/TestAssets/TestProject/TestProjectForDiscovery.csproj b/test/IntegrationTests/TestAssets/TestProject/TestProjectForDiscovery.csproj index c243ff45e2..47fb7b1742 100644 --- a/test/IntegrationTests/TestAssets/TestProject/TestProjectForDiscovery.csproj +++ b/test/IntegrationTests/TestAssets/TestProject/TestProjectForDiscovery.csproj @@ -5,7 +5,7 @@ - TRACE + $(DefineConstants);TRACE prompt 4 False