From d5577c0f97a2885c4e886f8fb0416d452b14048e Mon Sep 17 00:00:00 2001 From: Maximilian Chaplin Date: Tue, 3 Mar 2020 22:56:59 +0100 Subject: [PATCH 01/24] CA1507 Use nameof in place of string literal. --- src/Adapter/MSTest.CoreAdapter/Execution/TypeCache.cs | 4 ++-- .../MSTest.CoreAdapter/Execution/UnitTestRunner.cs | 2 +- .../MSTest.CoreAdapter/ObjectModel/UnitTestElement.cs | 2 +- src/Adapter/PlatformServices.Desktop/AssemblyResolver.cs | 2 +- .../Services/DesktopTestContextImplementation.cs | 2 +- .../Utilities/RandomIntPermutation.cs | 2 +- .../Utilities/SequentialIntPermutation.cs | 2 +- .../PlatformServices.Desktop/Utilities/XmlUtilities.cs | 2 +- .../Services/NetCoreTestContextImplementation.cs | 2 +- src/TestFramework/Extension.Desktop/PrivateType.cs | 2 +- src/TestFramework/Extension.Desktop/RuntimeTypeHelper.cs | 2 +- src/TestFramework/MSTest.Core/Assertions/Assert.cs | 8 ++++---- .../MSTest.Core/Attributes/ExpectedExceptionAttribute.cs | 4 ++-- src/TestFramework/MSTest.Core/Logger.cs | 2 +- 14 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/Adapter/MSTest.CoreAdapter/Execution/TypeCache.cs b/src/Adapter/MSTest.CoreAdapter/Execution/TypeCache.cs index 69607ec196..d11c5639d5 100644 --- a/src/Adapter/MSTest.CoreAdapter/Execution/TypeCache.cs +++ b/src/Adapter/MSTest.CoreAdapter/Execution/TypeCache.cs @@ -127,12 +127,12 @@ public TestMethodInfo GetTestMethodInfo(TestMethod testMethod, ITestContext test { if (testMethod == null) { - throw new ArgumentNullException("testMethod"); + throw new ArgumentNullException(nameof(testMethod)); } if (testContext == null) { - throw new ArgumentNullException("testContext"); + throw new ArgumentNullException(nameof(testContext)); } // Get the classInfo (This may throw as GetType calls assembly.GetType(..,true);) diff --git a/src/Adapter/MSTest.CoreAdapter/Execution/UnitTestRunner.cs b/src/Adapter/MSTest.CoreAdapter/Execution/UnitTestRunner.cs index 679d5a8971..597e2a6ca8 100644 --- a/src/Adapter/MSTest.CoreAdapter/Execution/UnitTestRunner.cs +++ b/src/Adapter/MSTest.CoreAdapter/Execution/UnitTestRunner.cs @@ -68,7 +68,7 @@ internal UnitTestResult[] RunSingleTest(TestMethod testMethod, IDictionary directories) { if (directories == null || directories.Count == 0) { - throw new ArgumentNullException("directories"); + throw new ArgumentNullException(nameof(directories)); } this.searchDirectories = new List(directories); diff --git a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestContextImplementation.cs b/src/Adapter/PlatformServices.Desktop/Services/DesktopTestContextImplementation.cs index 8b36dae876..96363df5c3 100644 --- a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestContextImplementation.cs +++ b/src/Adapter/PlatformServices.Desktop/Services/DesktopTestContextImplementation.cs @@ -230,7 +230,7 @@ public override void AddResultFile(string fileName) { if (string.IsNullOrEmpty(fileName)) { - throw new ArgumentException(Resource.Common_CannotBeNullOrEmpty, "fileName"); + throw new ArgumentException(Resource.Common_CannotBeNullOrEmpty, nameof(fileName)); } this.testResultFiles.Add(Path.GetFullPath(fileName)); diff --git a/src/Adapter/PlatformServices.Desktop/Utilities/RandomIntPermutation.cs b/src/Adapter/PlatformServices.Desktop/Utilities/RandomIntPermutation.cs index 56b2ffd83b..9b713cc486 100644 --- a/src/Adapter/PlatformServices.Desktop/Utilities/RandomIntPermutation.cs +++ b/src/Adapter/PlatformServices.Desktop/Utilities/RandomIntPermutation.cs @@ -19,7 +19,7 @@ public RandomIntPermutation(int numberOfObjects) { if (numberOfObjects < 0) { - throw new ArgumentException(Resource.WrongNumberOfObjects, "numberOfObjects"); + throw new ArgumentException(Resource.WrongNumberOfObjects, nameof(numberOfObjects)); } this.objects = new int[numberOfObjects]; diff --git a/src/Adapter/PlatformServices.Desktop/Utilities/SequentialIntPermutation.cs b/src/Adapter/PlatformServices.Desktop/Utilities/SequentialIntPermutation.cs index 7d345e7e0b..921c4e5cf8 100644 --- a/src/Adapter/PlatformServices.Desktop/Utilities/SequentialIntPermutation.cs +++ b/src/Adapter/PlatformServices.Desktop/Utilities/SequentialIntPermutation.cs @@ -19,7 +19,7 @@ public SequentialIntPermutation(int numberOfObjects) { if (numberOfObjects < 0) { - throw new ArgumentException(Resource.WrongNumberOfObjects, "numberOfObjects"); + throw new ArgumentException(Resource.WrongNumberOfObjects, nameof(numberOfObjects)); } this.numberOfObjects = numberOfObjects; diff --git a/src/Adapter/PlatformServices.Desktop/Utilities/XmlUtilities.cs b/src/Adapter/PlatformServices.Desktop/Utilities/XmlUtilities.cs index 6d5d829f34..5a0871cdd7 100644 --- a/src/Adapter/PlatformServices.Desktop/Utilities/XmlUtilities.cs +++ b/src/Adapter/PlatformServices.Desktop/Utilities/XmlUtilities.cs @@ -109,7 +109,7 @@ private static void AddAssemblyBindingRedirect( Debug.Assert(assemblyName != null, "assemblyName should not be null."); if (assemblyName == null) { - throw new ArgumentNullException("assemblyName"); + throw new ArgumentNullException(nameof(assemblyName)); } // Convert the public key token into a string. diff --git a/src/Adapter/PlatformServices.NetCore/Services/NetCoreTestContextImplementation.cs b/src/Adapter/PlatformServices.NetCore/Services/NetCoreTestContextImplementation.cs index 40595a6bee..cb753cb41a 100644 --- a/src/Adapter/PlatformServices.NetCore/Services/NetCoreTestContextImplementation.cs +++ b/src/Adapter/PlatformServices.NetCore/Services/NetCoreTestContextImplementation.cs @@ -224,7 +224,7 @@ public override void AddResultFile(string fileName) { if (string.IsNullOrEmpty(fileName)) { - throw new ArgumentException(Resource.Common_CannotBeNullOrEmpty, "fileName"); + throw new ArgumentException(Resource.Common_CannotBeNullOrEmpty, nameof(fileName)); } this.testResultFiles.Add(Path.GetFullPath(fileName)); diff --git a/src/TestFramework/Extension.Desktop/PrivateType.cs b/src/TestFramework/Extension.Desktop/PrivateType.cs index 413ff1cba3..f463dae867 100644 --- a/src/TestFramework/Extension.Desktop/PrivateType.cs +++ b/src/TestFramework/Extension.Desktop/PrivateType.cs @@ -48,7 +48,7 @@ public PrivateType(Type type) { if (type == null) { - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); } this.type = type; diff --git a/src/TestFramework/Extension.Desktop/RuntimeTypeHelper.cs b/src/TestFramework/Extension.Desktop/RuntimeTypeHelper.cs index 987a27cf94..078cb90fee 100644 --- a/src/TestFramework/Extension.Desktop/RuntimeTypeHelper.cs +++ b/src/TestFramework/Extension.Desktop/RuntimeTypeHelper.cs @@ -120,7 +120,7 @@ internal static MethodBase SelectMethod(BindingFlags bindingAttr, MethodBase[] m { if (match == null) { - throw new ArgumentNullException("match"); + throw new ArgumentNullException(nameof(match)); } int i; diff --git a/src/TestFramework/MSTest.Core/Assertions/Assert.cs b/src/TestFramework/MSTest.Core/Assertions/Assert.cs index 25176aecf7..c4754169ac 100644 --- a/src/TestFramework/MSTest.Core/Assertions/Assert.cs +++ b/src/TestFramework/MSTest.Core/Assertions/Assert.cs @@ -2092,12 +2092,12 @@ public static T ThrowsException(Action action, string message, params object[ if (action == null) { - throw new ArgumentNullException("action"); + throw new ArgumentNullException(nameof(action)); } if (message == null) { - throw new ArgumentNullException("message"); + throw new ArgumentNullException(nameof(message)); } try @@ -2207,12 +2207,12 @@ public static async Task ThrowsExceptionAsync(Func action, string me if (action == null) { - throw new ArgumentNullException("action"); + throw new ArgumentNullException(nameof(action)); } if (message == null) { - throw new ArgumentNullException("message"); + throw new ArgumentNullException(nameof(message)); } try diff --git a/src/TestFramework/MSTest.Core/Attributes/ExpectedExceptionAttribute.cs b/src/TestFramework/MSTest.Core/Attributes/ExpectedExceptionAttribute.cs index 274d322c39..a7eb801c50 100644 --- a/src/TestFramework/MSTest.Core/Attributes/ExpectedExceptionAttribute.cs +++ b/src/TestFramework/MSTest.Core/Attributes/ExpectedExceptionAttribute.cs @@ -38,14 +38,14 @@ public ExpectedExceptionAttribute(Type exceptionType, string noExceptionMessage) { if (exceptionType == null) { - throw new ArgumentNullException("exceptionType"); + throw new ArgumentNullException(nameof(exceptionType)); } if (!typeof(Exception).GetTypeInfo().IsAssignableFrom(exceptionType.GetTypeInfo())) { throw new ArgumentException( FrameworkMessages.UTF_ExpectedExceptionTypeMustDeriveFromException, - "exceptionType"); + nameof(exceptionType)); } this.ExceptionType = exceptionType; diff --git a/src/TestFramework/MSTest.Core/Logger.cs b/src/TestFramework/MSTest.Core/Logger.cs index c0c3739931..81cc0d1569 100644 --- a/src/TestFramework/MSTest.Core/Logger.cs +++ b/src/TestFramework/MSTest.Core/Logger.cs @@ -37,7 +37,7 @@ public static void LogMessage(string format, params object[] args) { if (format == null) { - throw new ArgumentNullException("format"); + throw new ArgumentNullException(nameof(format)); } string message = string.Format(CultureInfo.InvariantCulture, format, args); From f0529e4473bc213c91016a89d5d63679afdecc9b Mon Sep 17 00:00:00 2001 From: Maximilian Chaplin Date: Tue, 3 Mar 2020 22:59:07 +0100 Subject: [PATCH 02/24] IDE0016 Null check can be simplified. --- src/TestFramework/Extension.Desktop/PrivateType.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/TestFramework/Extension.Desktop/PrivateType.cs b/src/TestFramework/Extension.Desktop/PrivateType.cs index f463dae867..2cb5c15d89 100644 --- a/src/TestFramework/Extension.Desktop/PrivateType.cs +++ b/src/TestFramework/Extension.Desktop/PrivateType.cs @@ -46,12 +46,7 @@ public PrivateType(string assemblyName, string typeName) /// The wrapped Type to create. public PrivateType(Type type) { - if (type == null) - { - throw new ArgumentNullException(nameof(type)); - } - - this.type = type; + this.type = type ?? throw new ArgumentNullException(nameof(type)); } /// From 4dc50eb148b5d892c9fe5fcdd8940e7eec4e4302 Mon Sep 17 00:00:00 2001 From: Maximilian Chaplin Date: Tue, 3 Mar 2020 23:04:08 +0100 Subject: [PATCH 03/24] IDE0017 Object initialization can be simplified. --- .../Execution/TestMethodRunner.cs | 18 +++++--- .../Helpers/RunSettingsUtilities.cs | 8 ++-- .../ObjectModel/UnitTestElement.cs | 6 ++- .../Data/CsvDataConnection.cs | 6 ++- .../Data/TestDataConnectionSql.cs | 6 ++- .../Data/XmlDataConnection.cs | 6 ++- .../Utilities/AppDomainUtilities.cs | 7 +-- .../Utilities/DesktopAssemblyUtility.cs | 6 ++- .../Attributes/DataRowAttributeTests.cs | 6 ++- .../Execution/TestMethodInfoTests.cs | 30 ++++++++---- .../Extensions/TestCaseExtensionsTests.cs | 6 ++- .../AssemblyResolverTests.cs | 33 ++++++------- .../Deployment/AssemblyLoadWorkerTests.cs | 28 ++++++----- .../ns10MSTestAdapterSettingsTests.cs | 46 ++++++++++++------- .../Utilities/ns10FileUtilityTests.cs | 6 ++- 15 files changed, 136 insertions(+), 82 deletions(-) diff --git a/src/Adapter/MSTest.CoreAdapter/Execution/TestMethodRunner.cs b/src/Adapter/MSTest.CoreAdapter/Execution/TestMethodRunner.cs index 30338d7c42..50882d8090 100644 --- a/src/Adapter/MSTest.CoreAdapter/Execution/TestMethodRunner.cs +++ b/src/Adapter/MSTest.CoreAdapter/Execution/TestMethodRunner.cs @@ -242,9 +242,11 @@ internal UnitTestResult[] RunTestMethod() if (dataRows == null) { watch.Stop(); - var inconclusiveResult = new UTF.TestResult(); - inconclusiveResult.Outcome = UTF.UnitTestOutcome.Inconclusive; - inconclusiveResult.Duration = watch.Elapsed; + var inconclusiveResult = new UTF.TestResult + { + Outcome = UTF.UnitTestOutcome.Inconclusive, + Duration = watch.Elapsed + }; results.Add(inconclusiveResult); } else @@ -294,10 +296,12 @@ internal UnitTestResult[] RunTestMethod() catch (Exception ex) { watch.Stop(); - var failedResult = new UTF.TestResult(); - failedResult.Outcome = UTF.UnitTestOutcome.Error; - failedResult.TestFailureException = ex; - failedResult.Duration = watch.Elapsed; + var failedResult = new UTF.TestResult + { + Outcome = UTF.UnitTestOutcome.Error, + TestFailureException = ex, + Duration = watch.Elapsed + }; results.Add(failedResult); } } diff --git a/src/Adapter/MSTest.CoreAdapter/Helpers/RunSettingsUtilities.cs b/src/Adapter/MSTest.CoreAdapter/Helpers/RunSettingsUtilities.cs index 646effd838..d059726135 100644 --- a/src/Adapter/MSTest.CoreAdapter/Helpers/RunSettingsUtilities.cs +++ b/src/Adapter/MSTest.CoreAdapter/Helpers/RunSettingsUtilities.cs @@ -21,9 +21,11 @@ internal static XmlReaderSettings ReaderSettings { get { - var settings = new XmlReaderSettings(); - settings.IgnoreComments = true; - settings.IgnoreWhitespace = true; + var settings = new XmlReaderSettings + { + IgnoreComments = true, + IgnoreWhitespace = true + }; return settings; } } diff --git a/src/Adapter/MSTest.CoreAdapter/ObjectModel/UnitTestElement.cs b/src/Adapter/MSTest.CoreAdapter/ObjectModel/UnitTestElement.cs index c9410ad184..c56b67ea9b 100644 --- a/src/Adapter/MSTest.CoreAdapter/ObjectModel/UnitTestElement.cs +++ b/src/Adapter/MSTest.CoreAdapter/ObjectModel/UnitTestElement.cs @@ -114,8 +114,10 @@ internal TestCase ToTestCase() this.TestMethod.FullClassName, this.TestMethod.Name); - TestCase testCase = new TestCase(fullName, TestAdapter.Constants.ExecutorUri, this.TestMethod.AssemblyName); - testCase.DisplayName = string.IsNullOrEmpty(this.DisplayName) ? this.TestMethod.Name : this.DisplayName; + TestCase testCase = new TestCase(fullName, TestAdapter.Constants.ExecutorUri, this.TestMethod.AssemblyName) + { + DisplayName = string.IsNullOrEmpty(this.DisplayName) ? this.TestMethod.Name : this.DisplayName + }; testCase.SetPropertyValue(TestAdapter.Constants.TestClassNameProperty, this.TestMethod.FullClassName); diff --git a/src/Adapter/PlatformServices.Desktop/Data/CsvDataConnection.cs b/src/Adapter/PlatformServices.Desktop/Data/CsvDataConnection.cs index 9972c24dbe..1b70166035 100644 --- a/src/Adapter/PlatformServices.Desktop/Data/CsvDataConnection.cs +++ b/src/Adapter/PlatformServices.Desktop/Data/CsvDataConnection.cs @@ -155,8 +155,10 @@ public DataTable ReadTable(string tableName, IEnumerable columns, int maxRows) dataAdapter.SelectCommand = command; - DataTable table = new DataTable(); - table.Locale = CultureInfo.InvariantCulture; + DataTable table = new DataTable + { + Locale = CultureInfo.InvariantCulture + }; dataAdapter.Fill(table); return table; } diff --git a/src/Adapter/PlatformServices.Desktop/Data/TestDataConnectionSql.cs b/src/Adapter/PlatformServices.Desktop/Data/TestDataConnectionSql.cs index 0593e22fcf..8c9b18f9a0 100644 --- a/src/Adapter/PlatformServices.Desktop/Data/TestDataConnectionSql.cs +++ b/src/Adapter/PlatformServices.Desktop/Data/TestDataConnectionSql.cs @@ -843,8 +843,10 @@ public override DataTable ReadTable(string tableName, IEnumerable columns) WriteDiagnostics("ReadTable: SQL Query: {0}", command.CommandText); dataAdapter.SelectCommand = command; - DataTable table = new DataTable(); - table.Locale = CultureInfo.InvariantCulture; + DataTable table = new DataTable + { + Locale = CultureInfo.InvariantCulture + }; dataAdapter.Fill(table); table.TableName = tableName; // Make table name in the data set the same as original table name. diff --git a/src/Adapter/PlatformServices.Desktop/Data/XmlDataConnection.cs b/src/Adapter/PlatformServices.Desktop/Data/XmlDataConnection.cs index fe5ad50af1..228976b26c 100644 --- a/src/Adapter/PlatformServices.Desktop/Data/XmlDataConnection.cs +++ b/src/Adapter/PlatformServices.Desktop/Data/XmlDataConnection.cs @@ -95,8 +95,10 @@ private DataSet LoadDataSet(bool schemaOnly) { try { - DataSet dataSet = new DataSet(); - dataSet.Locale = CultureInfo.CurrentCulture; + DataSet dataSet = new DataSet + { + Locale = CultureInfo.CurrentCulture + }; string path = this.FixPath(this.fileName) ?? Path.GetFullPath(this.fileName); if (schemaOnly) { diff --git a/src/Adapter/PlatformServices.Desktop/Utilities/AppDomainUtilities.cs b/src/Adapter/PlatformServices.Desktop/Utilities/AppDomainUtilities.cs index 7be4ff734c..f75880a87c 100644 --- a/src/Adapter/PlatformServices.Desktop/Utilities/AppDomainUtilities.cs +++ b/src/Adapter/PlatformServices.Desktop/Utilities/AppDomainUtilities.cs @@ -78,9 +78,10 @@ internal static void SetAppDomainFrameworkVersionBasedOnTestSource(AppDomainSetu [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1650:ElementDocumentationMustBeSpelledCorrectly", Justification = "Reviewed. Suppression is OK here.")] internal static string GetTargetFrameworkVersionString(string testSourcePath) { - AppDomainSetup appDomainSetup = new AppDomainSetup(); - - appDomainSetup.LoaderOptimization = LoaderOptimization.MultiDomainHost; + AppDomainSetup appDomainSetup = new AppDomainSetup + { + LoaderOptimization = LoaderOptimization.MultiDomainHost + }; AppDomainUtilities.SetConfigurationFile(appDomainSetup, new DeploymentUtility().GetConfigFile(testSourcePath)); diff --git a/src/Adapter/PlatformServices.Desktop/Utilities/DesktopAssemblyUtility.cs b/src/Adapter/PlatformServices.Desktop/Utilities/DesktopAssemblyUtility.cs index 006849bce7..1c98690ba4 100644 --- a/src/Adapter/PlatformServices.Desktop/Utilities/DesktopAssemblyUtility.cs +++ b/src/Adapter/PlatformServices.Desktop/Utilities/DesktopAssemblyUtility.cs @@ -189,8 +189,10 @@ internal virtual string[] GetFullPathToDependentAssemblies(string assemblyPath, EqtTrace.InfoIf(EqtTrace.IsInfoEnabled, "AssemblyDependencyFinder.GetDependentAssemblies: start."); - AppDomainSetup setupInfo = new AppDomainSetup(); - setupInfo.ApplicationBase = Path.GetDirectoryName(Path.GetFullPath(assemblyPath)); + AppDomainSetup setupInfo = new AppDomainSetup + { + ApplicationBase = Path.GetDirectoryName(Path.GetFullPath(assemblyPath)) + }; Debug.Assert(string.IsNullOrEmpty(configFile) || File.Exists(configFile), "Config file is specified but does not exist: {0}", configFile); diff --git a/test/UnitTests/MSTest.Core.Unit.Tests/Attributes/DataRowAttributeTests.cs b/test/UnitTests/MSTest.Core.Unit.Tests/Attributes/DataRowAttributeTests.cs index 93b8f5076f..f0e38e4ff3 100644 --- a/test/UnitTests/MSTest.Core.Unit.Tests/Attributes/DataRowAttributeTests.cs +++ b/test/UnitTests/MSTest.Core.Unit.Tests/Attributes/DataRowAttributeTests.cs @@ -93,8 +93,10 @@ public void GetDisplayNameShouldReturnAppropriateName() [TestMethod] public void GetDisplayNameShouldReturnSpecifiedDisplayName() { - var dataRowAttribute = new DataRowAttribute(null); - dataRowAttribute.DisplayName = "DataRowTestWithDisplayName"; + var dataRowAttribute = new DataRowAttribute(null) + { + DisplayName = "DataRowTestWithDisplayName" + }; this.dummyTestClass = new DummyTestClass(); this.testMethodInfo = this.dummyTestClass.GetType().GetTypeInfo().GetDeclaredMethod("DataRowTestMethod"); diff --git a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TestMethodInfoTests.cs b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TestMethodInfoTests.cs index 3fc72895d7..d63ed42dd6 100644 --- a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TestMethodInfoTests.cs +++ b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TestMethodInfoTests.cs @@ -859,8 +859,10 @@ public void TestMethodInfoInvokeShouldCallDiposeForDisposableTestClassIfTestClea DummyTestClassWithDisposable.DisposeMethodBody = () => disposeCalled = true; DummyTestClassWithDisposable.DummyTestCleanupMethodBody = classInstance => { throw new NotImplementedException(); }; var ctorInfo = typeof(DummyTestClassWithDisposable).GetConstructors().Single(); - var testClass = new TestClassInfo(typeof(DummyTestClassWithDisposable), ctorInfo, null, this.classAttribute, this.testAssemblyInfo); - testClass.TestCleanupMethod = typeof(DummyTestClassWithDisposable).GetMethod("DummyTestCleanupMethod"); + var testClass = new TestClassInfo(typeof(DummyTestClassWithDisposable), ctorInfo, null, this.classAttribute, this.testAssemblyInfo) + { + TestCleanupMethod = typeof(DummyTestClassWithDisposable).GetMethod("DummyTestCleanupMethod") + }; var method = new TestMethodInfo(typeof(DummyTestClassWithDisposable).GetMethod("DummyTestMethod"), testClass, this.testMethodOptions); method.Invoke(null); @@ -1069,8 +1071,10 @@ public void HandleMethodExceptionShouldInvokeVerifyOfDerivedCustomExpectedExcept [TestMethodV1] public void VerifyShouldNotThrowIfThrownExceptionCanBeAssignedToExpectedException() { - UTF.ExpectedExceptionAttribute expectedException = new UTF.ExpectedExceptionAttribute(typeof(Exception)); - expectedException.AllowDerivedTypes = true; + UTF.ExpectedExceptionAttribute expectedException = new UTF.ExpectedExceptionAttribute(typeof(Exception)) + { + AllowDerivedTypes = true + }; this.testMethodOptions.Timeout = 0; this.testMethodOptions.ExpectedException = expectedException; var method = new TestMethodInfo( @@ -1086,8 +1090,10 @@ public void VerifyShouldNotThrowIfThrownExceptionCanBeAssignedToExpectedExceptio [TestMethodV1] public void VerifyShouldThrowExceptionIfThrownExceptionCannotBeAssignedToExpectedException() { - UTF.ExpectedExceptionAttribute expectedException = new UTF.ExpectedExceptionAttribute(typeof(DivideByZeroException), "Custom Exception"); - expectedException.AllowDerivedTypes = true; + UTF.ExpectedExceptionAttribute expectedException = new UTF.ExpectedExceptionAttribute(typeof(DivideByZeroException), "Custom Exception") + { + AllowDerivedTypes = true + }; this.testMethodOptions.Timeout = 0; this.testMethodOptions.ExpectedException = expectedException; var method = new TestMethodInfo( @@ -1106,8 +1112,10 @@ public void VerifyShouldThrowExceptionIfThrownExceptionCannotBeAssignedToExpecte [TestMethodV1] public void VerifyShouldRethrowExceptionIfThrownExceptionIsAssertFailedException() { - UTF.ExpectedExceptionAttribute expectedException = new UTF.ExpectedExceptionAttribute(typeof(DivideByZeroException)); - expectedException.AllowDerivedTypes = true; + UTF.ExpectedExceptionAttribute expectedException = new UTF.ExpectedExceptionAttribute(typeof(DivideByZeroException)) + { + AllowDerivedTypes = true + }; this.testMethodOptions.Timeout = 0; this.testMethodOptions.ExpectedException = expectedException; var method = new TestMethodInfo( @@ -1125,8 +1133,10 @@ public void VerifyShouldRethrowExceptionIfThrownExceptionIsAssertFailedException [TestMethodV1] public void VerifyShouldRethrowExceptionIfThrownExceptionIsAssertInconclusiveException() { - UTF.ExpectedExceptionAttribute expectedException = new UTF.ExpectedExceptionAttribute(typeof(DivideByZeroException)); - expectedException.AllowDerivedTypes = true; + UTF.ExpectedExceptionAttribute expectedException = new UTF.ExpectedExceptionAttribute(typeof(DivideByZeroException)) + { + AllowDerivedTypes = true + }; this.testMethodOptions.Timeout = 0; this.testMethodOptions.ExpectedException = expectedException; var method = new TestMethodInfo( diff --git a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Extensions/TestCaseExtensionsTests.cs b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Extensions/TestCaseExtensionsTests.cs index 2a7a7d9a40..7a6f65e109 100644 --- a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Extensions/TestCaseExtensionsTests.cs +++ b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Extensions/TestCaseExtensionsTests.cs @@ -20,8 +20,10 @@ public class TestCaseExtensionsTests [TestMethod] public void ToUnitTestElementShouldReturnUnitTestElementWithFieldsSet() { - TestCase testCase = new TestCase("DummyClass.DummyMethod", new Uri("DummyUri", UriKind.Relative), Assembly.GetCallingAssembly().FullName); - testCase.DisplayName = "DummyDisplayName"; + TestCase testCase = new TestCase("DummyClass.DummyMethod", new Uri("DummyUri", UriKind.Relative), Assembly.GetCallingAssembly().FullName) + { + DisplayName = "DummyDisplayName" + }; var testCategories = new[] { "DummyCategory" }; testCase.SetPropertyValue(Constants.AsyncTestProperty, true); diff --git a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/AssemblyResolverTests.cs b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/AssemblyResolverTests.cs index e09bd17873..136b91e907 100644 --- a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/AssemblyResolverTests.cs +++ b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/AssemblyResolverTests.cs @@ -34,25 +34,26 @@ public void AddSubDirectoriesShouldReturnSubDirectoriesInDfsOrder() resultDirectories.Add(@"C:\unitTesting\a\c\d"); resultDirectories.Add(@"C:\unitTesting\b"); - TestableAssemblyResolver assemblyResolver = new TestableAssemblyResolver(new List { @"c:\dummy" }); - - assemblyResolver.DoesDirectoryExistSetter = (str) => true; - assemblyResolver.GetDirectoriesSetter = (str) => + TestableAssemblyResolver assemblyResolver = new TestableAssemblyResolver(new List { @"c:\dummy" }) { - if (string.Compare(path, str, StringComparison.OrdinalIgnoreCase) == 0) + DoesDirectoryExistSetter = (str) => true, + GetDirectoriesSetter = (str) => { - return new string[] { @"C:\unitTesting\a", @"C:\unitTesting\b" }; - } - else if (string.Compare(@"C:\unitTesting\a", str, StringComparison.OrdinalIgnoreCase) == 0) - { - return new string[] { @"C:\unitTesting\a\c" }; - } - else if (string.Compare(@"C:\unitTesting\a\c", str, StringComparison.OrdinalIgnoreCase) == 0) - { - return new string[] { @"C:\unitTesting\a\c\d" }; - } + if (string.Compare(path, str, StringComparison.OrdinalIgnoreCase) == 0) + { + return new string[] { @"C:\unitTesting\a", @"C:\unitTesting\b" }; + } + else if (string.Compare(@"C:\unitTesting\a", str, StringComparison.OrdinalIgnoreCase) == 0) + { + return new string[] { @"C:\unitTesting\a\c" }; + } + else if (string.Compare(@"C:\unitTesting\a\c", str, StringComparison.OrdinalIgnoreCase) == 0) + { + return new string[] { @"C:\unitTesting\a\c\d" }; + } - return new List().ToArray(); + return new List().ToArray(); + } }; // Act. diff --git a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Deployment/AssemblyLoadWorkerTests.cs b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Deployment/AssemblyLoadWorkerTests.cs index 76c0546e5f..00a42b330d 100644 --- a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Deployment/AssemblyLoadWorkerTests.cs +++ b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Deployment/AssemblyLoadWorkerTests.cs @@ -28,11 +28,13 @@ public void GetFullPathToDependentAssembliesShouldReturnV1FrameworkAssembly() { // Arrange. var v1AssemblyName = new AssemblyName("Microsoft.VisualStudio.QualityTools.UnitTestFramework"); - var testableAssembly = new TestableAssembly(); - testableAssembly.GetReferencedAssembliesSetter = () => - { - return new AssemblyName[] { v1AssemblyName }; - }; + var testableAssembly = new TestableAssembly + { + GetReferencedAssembliesSetter = () => + { + return new AssemblyName[] { v1AssemblyName }; + } + }; var mockAssemblyUtility = new Mock(); mockAssemblyUtility.Setup(au => au.ReflectionOnlyLoadFrom(It.IsAny())).Returns(testableAssembly); @@ -57,16 +59,20 @@ public void GetFullPathToDependentAssembliesShouldReturnV1FrameworkReferencedInA var v1AssemblyName = new AssemblyName("Microsoft.VisualStudio.QualityTools.UnitTestFramework"); var dependentAssemblyName = new AssemblyName("Common.TestFramework"); - var dependentAssembly = new TestableAssembly(dependentAssemblyName.Name); - dependentAssembly.GetReferencedAssembliesSetter = () => + var dependentAssembly = new TestableAssembly(dependentAssemblyName.Name) { - return new AssemblyName[] { v1AssemblyName }; + GetReferencedAssembliesSetter = () => + { + return new AssemblyName[] { v1AssemblyName }; + } }; - var testableAssembly = new TestableAssembly(); - testableAssembly.GetReferencedAssembliesSetter = () => + var testableAssembly = new TestableAssembly { - return new AssemblyName[] { dependentAssemblyName }; + GetReferencedAssembliesSetter = () => + { + return new AssemblyName[] { dependentAssemblyName }; + } }; var mockAssemblyUtility = new Mock(); diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Services/ns10MSTestAdapterSettingsTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Services/ns10MSTestAdapterSettingsTests.cs index c14a614824..051c1ae669 100644 --- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Services/ns10MSTestAdapterSettingsTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Services/ns10MSTestAdapterSettingsTests.cs @@ -47,8 +47,10 @@ public void ResolveEnvironmentVariableShouldResolvePathWhenPassedAbsolutePath() string baseDirectory = null; string expectedResult = @"C:\MsTest\Adapter"; - var adapterSettings = new TestableMSTestAdapterSettings(); - adapterSettings.DoesDirectoryExistSetter = (str) => { return true; }; + var adapterSettings = new TestableMSTestAdapterSettings + { + DoesDirectoryExistSetter = (str) => { return true; } + }; string result = adapterSettings.ResolveEnvironmentVariableAndReturnFullPathIfExist(path, baseDirectory); @@ -63,9 +65,11 @@ public void ResolveEnvironmentVariableShouldResolvePathWithAnEnvironmentVariable string baseDirectory = null; string expectedResult = @"C:\foo\unitTesting\MsTest\Adapter"; - var adapterSettings = new TestableMSTestAdapterSettings(); - adapterSettings.ExpandEnvironmentVariablesSetter = (str) => { return str.Replace("%temp%", "C:\\foo"); }; - adapterSettings.DoesDirectoryExistSetter = (str) => { return true; }; + var adapterSettings = new TestableMSTestAdapterSettings + { + ExpandEnvironmentVariablesSetter = (str) => { return str.Replace("%temp%", "C:\\foo"); }, + DoesDirectoryExistSetter = (str) => { return true; } + }; string result = adapterSettings.ResolveEnvironmentVariableAndReturnFullPathIfExist(path, baseDirectory); @@ -80,8 +84,10 @@ public void ResolveEnvironmentVariableShouldResolvePathWhenPassedRelativePathWit string baseDirectory = @"C:\unitTesting"; string expectedResult = @"C:\unitTesting\MsTest\Adapter"; - var adapterSettings = new TestableMSTestAdapterSettings(); - adapterSettings.DoesDirectoryExistSetter = (str) => { return true; }; + var adapterSettings = new TestableMSTestAdapterSettings + { + DoesDirectoryExistSetter = (str) => { return true; } + }; string result = adapterSettings.ResolveEnvironmentVariableAndReturnFullPathIfExist(path, baseDirectory); @@ -96,8 +102,10 @@ public void ResolveEnvironmentVariableShouldResolvePathWhenPassedRelativePathWit string baseDirectory = @"C:\unitTesting"; string expectedResult = @"C:\unitTesting\MsTest\Adapter"; - var adapterSettings = new TestableMSTestAdapterSettings(); - adapterSettings.DoesDirectoryExistSetter = (str) => { return true; }; + var adapterSettings = new TestableMSTestAdapterSettings + { + DoesDirectoryExistSetter = (str) => { return true; } + }; string result = adapterSettings.ResolveEnvironmentVariableAndReturnFullPathIfExist(path, baseDirectory); @@ -118,8 +126,10 @@ public void ResolveEnvironmentVariableShouldResolvePathWhenPassedRelativePath() string currentDrive = currentDirectory.Split('\\').First() + "\\"; string expectedResult = Path.Combine(currentDrive, @"MsTest\Adapter"); - var adapterSettings = new TestableMSTestAdapterSettings(); - adapterSettings.DoesDirectoryExistSetter = (str) => { return true; }; + var adapterSettings = new TestableMSTestAdapterSettings + { + DoesDirectoryExistSetter = (str) => { return true; } + }; string result = adapterSettings.ResolveEnvironmentVariableAndReturnFullPathIfExist(path, baseDirectory); @@ -135,8 +145,10 @@ public void ResolveEnvironmentVariableShouldResolvePathWhenPassedNetworkPath() string expectedResult = path; - var adapterSettings = new TestableMSTestAdapterSettings(); - adapterSettings.DoesDirectoryExistSetter = (str) => { return true; }; + var adapterSettings = new TestableMSTestAdapterSettings + { + DoesDirectoryExistSetter = (str) => { return true; } + }; string result = adapterSettings.ResolveEnvironmentVariableAndReturnFullPathIfExist(path, baseDirectory); @@ -168,9 +180,11 @@ public void GetDirectoryListWithRecursivePropertyShouldReadRunSettingCorrectly() expectedResult.Add(new RecursiveDirectoryPath(@"C:\MsTest\Adapter", true)); expectedResult.Add(new RecursiveDirectoryPath(@"C:\foo\unitTesting\MsTest\Adapter", false)); - var adapterSettings = new TestableMSTestAdapterSettings(expectedResult); - adapterSettings.ExpandEnvironmentVariablesSetter = (str) => { return str.Replace("%temp%", "C:\\foo"); }; - adapterSettings.DoesDirectoryExistSetter = (str) => { return true; }; + var adapterSettings = new TestableMSTestAdapterSettings(expectedResult) + { + ExpandEnvironmentVariablesSetter = (str) => { return str.Replace("%temp%", "C:\\foo"); }, + DoesDirectoryExistSetter = (str) => { return true; } + }; IList result = adapterSettings.GetDirectoryListWithRecursiveProperty(baseDirectory); Assert.IsNotNull(result); diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Utilities/ns10FileUtilityTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Utilities/ns10FileUtilityTests.cs index ad9a367823..7ed9f78e43 100644 --- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Utilities/ns10FileUtilityTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Utilities/ns10FileUtilityTests.cs @@ -29,8 +29,10 @@ public class FileUtilityTests [TestInitialize] public void TestInit() { - this.fileUtility = new Mock(); - this.fileUtility.CallBase = true; + this.fileUtility = new Mock + { + CallBase = true + }; } [TestMethod] From 9557e500f4a118122c3780200528425660084411 Mon Sep 17 00:00:00 2001 From: Maximilian Chaplin Date: Tue, 3 Mar 2020 23:07:17 +0100 Subject: [PATCH 04/24] IDE0028 Collection initialization can be simplified. --- .../Execution/StackTraceHelper.cs | 8 +++--- .../Execution/TestMethodRunner.cs | 6 +++-- .../Data/CsvDataConnection.cs | 6 +++-- .../Deployment/AssemblyLoadWorker.cs | 7 ++--- .../Services/DesktopTestDataSource.cs | 6 +++-- .../Services/DesktopTestSourceHost.cs | 8 +++--- .../Utilities/ns13DeploymentUtilityBase.cs | 6 +++-- .../DataSourceElement.cs | 12 +++++---- .../TestConfigurationSection.cs | 6 +++-- .../Attributes/TestCategoryAttribute.cs | 6 +++-- .../Discovery/AssemblyEnumeratorTests.cs | 7 ++--- .../AssemblyResolverTests.cs | 26 ++++++++++++------- .../ns10MSTestAdapterSettingsTests.cs | 8 +++--- 13 files changed, 70 insertions(+), 42 deletions(-) diff --git a/src/Adapter/MSTest.CoreAdapter/Execution/StackTraceHelper.cs b/src/Adapter/MSTest.CoreAdapter/Execution/StackTraceHelper.cs index 6b7fded5e5..414a21bcc5 100644 --- a/src/Adapter/MSTest.CoreAdapter/Execution/StackTraceHelper.cs +++ b/src/Adapter/MSTest.CoreAdapter/Execution/StackTraceHelper.cs @@ -32,9 +32,11 @@ private static List TypeToBeExcluded { if (typesToBeExcluded == null) { - typesToBeExcluded = new List(); - typesToBeExcluded.Add(typeof(Microsoft.VisualStudio.TestTools.UnitTesting.Assert).Namespace); - typesToBeExcluded.Add(typeof(MSTestExecutor).Namespace); + typesToBeExcluded = new List + { + typeof(Microsoft.VisualStudio.TestTools.UnitTesting.Assert).Namespace, + typeof(MSTestExecutor).Namespace + }; } return typesToBeExcluded; diff --git a/src/Adapter/MSTest.CoreAdapter/Execution/TestMethodRunner.cs b/src/Adapter/MSTest.CoreAdapter/Execution/TestMethodRunner.cs index 50882d8090..263ebc06ba 100644 --- a/src/Adapter/MSTest.CoreAdapter/Execution/TestMethodRunner.cs +++ b/src/Adapter/MSTest.CoreAdapter/Execution/TestMethodRunner.cs @@ -423,8 +423,10 @@ private UTF.UnitTestOutcome GetAggregateOutcome(List results) } // UpdatedResults contain parent result at first position and remaining results has parent info updated. - var updatedResults = new List(); - updatedResults.Add(parentResult); + var updatedResults = new List + { + parentResult + }; foreach (var result in results) { diff --git a/src/Adapter/PlatformServices.Desktop/Data/CsvDataConnection.cs b/src/Adapter/PlatformServices.Desktop/Data/CsvDataConnection.cs index 1b70166035..3fdfb6aa94 100644 --- a/src/Adapter/PlatformServices.Desktop/Data/CsvDataConnection.cs +++ b/src/Adapter/PlatformServices.Desktop/Data/CsvDataConnection.cs @@ -44,8 +44,10 @@ private string TableName public override List GetDataTablesAndViews() { - List tableNames = new List(1); - tableNames.Add(this.TableName); + List tableNames = new List(1) + { + this.TableName + }; return tableNames; } diff --git a/src/Adapter/PlatformServices.Desktop/Deployment/AssemblyLoadWorker.cs b/src/Adapter/PlatformServices.Desktop/Deployment/AssemblyLoadWorker.cs index 41db44b578..d931c48276 100644 --- a/src/Adapter/PlatformServices.Desktop/Deployment/AssemblyLoadWorker.cs +++ b/src/Adapter/PlatformServices.Desktop/Deployment/AssemblyLoadWorker.cs @@ -58,9 +58,10 @@ public string[] GetFullPathToDependentAssemblies(string assemblyPath, out IList< Debug.Assert(assembly != null, "assembly"); List result = new List(); - List visitedAssemblies = new List(); - - visitedAssemblies.Add(assembly.FullName); + List visitedAssemblies = new List + { + assembly.FullName + }; this.ProcessChildren(assembly, result, visitedAssemblies, warnings); diff --git a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestDataSource.cs b/src/Adapter/PlatformServices.Desktop/Services/DesktopTestDataSource.cs index 20a4d589b5..4627902a1a 100644 --- a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestDataSource.cs +++ b/src/Adapter/PlatformServices.Desktop/Services/DesktopTestDataSource.cs @@ -32,8 +32,10 @@ public IEnumerable GetData(UTF.ITestMethod testMethodInfo, ITestContext { // 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 - List dataFolders = new List(); - dataFolders.Add(Path.GetDirectoryName(new Uri(testMethodInfo.MethodInfo.Module.Assembly.CodeBase).LocalPath)); + List dataFolders = new List + { + Path.GetDirectoryName(new Uri(testMethodInfo.MethodInfo.Module.Assembly.CodeBase).LocalPath) + }; List dataRowResults = new List(); diff --git a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestSourceHost.cs b/src/Adapter/PlatformServices.Desktop/Services/DesktopTestSourceHost.cs index 227d338194..3c8f862beb 100644 --- a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestSourceHost.cs +++ b/src/Adapter/PlatformServices.Desktop/Services/DesktopTestSourceHost.cs @@ -246,10 +246,12 @@ internal string GetAppBaseAsPerPlatform() /// internal virtual List GetResolutionPaths(string sourceFileName, bool isPortableMode) { - List resolutionPaths = new List(); + List resolutionPaths = new List + { - // Add path of test assembly in resolution path. Mostly will be used for resolving winmd. - resolutionPaths.Add(Path.GetDirectoryName(sourceFileName)); + // Add path of test assembly in resolution path. Mostly will be used for resolving winmd. + Path.GetDirectoryName(sourceFileName) + }; if (!isPortableMode) { diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentUtilityBase.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentUtilityBase.cs index cfdf441016..29c8fcc86b 100644 --- a/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentUtilityBase.cs +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentUtilityBase.cs @@ -180,8 +180,10 @@ protected IEnumerable Deploy(IList deploymentItems, stri Debug.Assert(Path.IsPathRooted(deploymentItemFile), "File " + deploymentItemFile + " is not rooted"); // List of files to deploy, by default, just itemFile. - var filesToDeploy = new List(1); - filesToDeploy.Add(deploymentItemFile); + var filesToDeploy = new List(1) + { + deploymentItemFile + }; // Find dependencies of test deployment items and deploy them at the same time as master file. if (deploymentItem.OriginType == DeploymentItemOriginType.PerTestDeployment && diff --git a/src/TestFramework/Extension.Desktop/ConfigurationSettings/DataSourceElement.cs b/src/TestFramework/Extension.Desktop/ConfigurationSettings/DataSourceElement.cs index c961dbff77..14f804b5e4 100644 --- a/src/TestFramework/Extension.Desktop/ConfigurationSettings/DataSourceElement.cs +++ b/src/TestFramework/Extension.Desktop/ConfigurationSettings/DataSourceElement.cs @@ -19,11 +19,13 @@ public sealed class DataSourceElement : ConfigurationElement static DataSourceElement() { - properties = new ConfigurationPropertyCollection(); - properties.Add(NameValue); - properties.Add(ConnectionStringValue); - properties.Add(DataAccessMethodValue); - properties.Add(DataTableNameValue); + properties = new ConfigurationPropertyCollection + { + NameValue, + ConnectionStringValue, + DataAccessMethodValue, + DataTableNameValue + }; } /// diff --git a/src/TestFramework/Extension.Desktop/ConfigurationSettings/TestConfigurationSection.cs b/src/TestFramework/Extension.Desktop/ConfigurationSettings/TestConfigurationSection.cs index c92bed8d4f..d3fdb9bebe 100644 --- a/src/TestFramework/Extension.Desktop/ConfigurationSettings/TestConfigurationSection.cs +++ b/src/TestFramework/Extension.Desktop/ConfigurationSettings/TestConfigurationSection.cs @@ -15,8 +15,10 @@ public sealed class TestConfigurationSection : ConfigurationSection static TestConfigurationSection() { - properties = new ConfigurationPropertyCollection(); - properties.Add(DataSourcesValue); + properties = new ConfigurationPropertyCollection + { + DataSourcesValue + }; } /// diff --git a/src/TestFramework/MSTest.Core/Attributes/TestCategoryAttribute.cs b/src/TestFramework/MSTest.Core/Attributes/TestCategoryAttribute.cs index 6a801f7f1b..6b17e8a2c4 100644 --- a/src/TestFramework/MSTest.Core/Attributes/TestCategoryAttribute.cs +++ b/src/TestFramework/MSTest.Core/Attributes/TestCategoryAttribute.cs @@ -24,8 +24,10 @@ public sealed class TestCategoryAttribute : TestCategoryBaseAttribute /// public TestCategoryAttribute(string testCategory) { - List categories = new List(1); - categories.Add(testCategory); + List categories = new List(1) + { + testCategory + }; this.testCategories = categories; } diff --git a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Discovery/AssemblyEnumeratorTests.cs b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Discovery/AssemblyEnumeratorTests.cs index e01171621a..c47182a7e1 100644 --- a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Discovery/AssemblyEnumeratorTests.cs +++ b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Discovery/AssemblyEnumeratorTests.cs @@ -370,9 +370,10 @@ public void EnumerateAssemblyShouldLogWarningsIfPresent() { var mockAssembly = new Mock(); var testableAssemblyEnumerator = new TestableAssemblyEnumerator(); - ICollection warningsFromTypeEnumerator = new Collection(); - - warningsFromTypeEnumerator.Add("DummyWarning"); + ICollection warningsFromTypeEnumerator = new Collection + { + "DummyWarning" + }; // Setup mocks mockAssembly.Setup(a => a.DefinedTypes) diff --git a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/AssemblyResolverTests.cs b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/AssemblyResolverTests.cs index 136b91e907..622328ea2c 100644 --- a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/AssemblyResolverTests.cs +++ b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/AssemblyResolverTests.cs @@ -28,11 +28,13 @@ public void AddSubDirectoriesShouldReturnSubDirectoriesInDfsOrder() string path = @"C:\unitTesting"; List searchDirectories = new List(); - List resultDirectories = new List(); - resultDirectories.Add(@"C:\unitTesting\a"); - resultDirectories.Add(@"C:\unitTesting\a\c"); - resultDirectories.Add(@"C:\unitTesting\a\c\d"); - resultDirectories.Add(@"C:\unitTesting\b"); + List resultDirectories = new List + { + @"C:\unitTesting\a", + @"C:\unitTesting\a\c", + @"C:\unitTesting\a\c\d", + @"C:\unitTesting\b" + }; TestableAssemblyResolver assemblyResolver = new TestableAssemblyResolver(new List { @"c:\dummy" }) { @@ -70,12 +72,16 @@ public void OnResolveShouldAddSearchDirectoryListOnANeedToBasis() { int count = 0; - List recursiveDirectoryPath = new List(); - recursiveDirectoryPath.Add(new RecursiveDirectoryPath(@"C:\unitTesting", true)); - recursiveDirectoryPath.Add(new RecursiveDirectoryPath(@"C:\FunctionalTesting", false)); + List recursiveDirectoryPath = new List + { + new RecursiveDirectoryPath(@"C:\unitTesting", true), + new RecursiveDirectoryPath(@"C:\FunctionalTesting", false) + }; - List dummyDirectories = new List(); - dummyDirectories.Add(@"c:\dummy"); + List dummyDirectories = new List + { + @"c:\dummy" + }; TestableAssemblyResolver assemblyResolver = new TestableAssemblyResolver(dummyDirectories); // Adding search directory with recursive property true/false diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Services/ns10MSTestAdapterSettingsTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Services/ns10MSTestAdapterSettingsTests.cs index 051c1ae669..dd30c207c7 100644 --- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Services/ns10MSTestAdapterSettingsTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Services/ns10MSTestAdapterSettingsTests.cs @@ -176,9 +176,11 @@ public void GetDirectoryListWithRecursivePropertyShouldReadRunSettingCorrectly() { string baseDirectory = @"C:\unitTesting"; - List expectedResult = new List(); - expectedResult.Add(new RecursiveDirectoryPath(@"C:\MsTest\Adapter", true)); - expectedResult.Add(new RecursiveDirectoryPath(@"C:\foo\unitTesting\MsTest\Adapter", false)); + List expectedResult = new List + { + new RecursiveDirectoryPath(@"C:\MsTest\Adapter", true), + new RecursiveDirectoryPath(@"C:\foo\unitTesting\MsTest\Adapter", false) + }; var adapterSettings = new TestableMSTestAdapterSettings(expectedResult) { From 4b0c9428df72d0e9647494a0fab5a75c4b327df2 Mon Sep 17 00:00:00 2001 From: Maximilian Chaplin Date: Tue, 3 Mar 2020 23:08:39 +0100 Subject: [PATCH 05/24] IDE0029 Null check can be simplified. --- .../PlatformServices.Desktop/Data/XmlDataConnection.cs | 2 +- .../MSTest.Core/Assertions/CollectionAssert.cs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Adapter/PlatformServices.Desktop/Data/XmlDataConnection.cs b/src/Adapter/PlatformServices.Desktop/Data/XmlDataConnection.cs index 228976b26c..9e95e11a32 100644 --- a/src/Adapter/PlatformServices.Desktop/Data/XmlDataConnection.cs +++ b/src/Adapter/PlatformServices.Desktop/Data/XmlDataConnection.cs @@ -86,7 +86,7 @@ public override DataTable ReadTable(string tableName, IEnumerable columns) // once for every table in it. Oh well. Reading XML is pretty quick // compared to other forms of data source DataSet ds = this.LoadDataSet(false); - return ds != null ? ds.Tables[tableName] : null; + return ds?.Tables[tableName]; } [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Requirement is to handle all kinds of user exceptions and message appropriately.")] diff --git a/src/TestFramework/MSTest.Core/Assertions/CollectionAssert.cs b/src/TestFramework/MSTest.Core/Assertions/CollectionAssert.cs index 753ba68726..51beb86e90 100644 --- a/src/TestFramework/MSTest.Core/Assertions/CollectionAssert.cs +++ b/src/TestFramework/MSTest.Core/Assertions/CollectionAssert.cs @@ -350,7 +350,7 @@ public static void AllItemsAreUnique(ICollection collection, string message, par var finalMessage = string.Format( CultureInfo.CurrentCulture, FrameworkMessages.AllItemsAreUniqueFailMsg, - message == null ? string.Empty : message, + message ?? string.Empty, FrameworkMessages.Common_NullInMessages); Assert.HandleFail("CollectionAssert.AllItemsAreUnique", finalMessage, parameters); @@ -363,7 +363,7 @@ public static void AllItemsAreUnique(ICollection collection, string message, par string finalMessage = string.Format( CultureInfo.CurrentCulture, FrameworkMessages.AllItemsAreUniqueFailMsg, - message == null ? string.Empty : message, + message ?? string.Empty, Assert.ReplaceNulls(current)); Assert.HandleFail("CollectionAssert.AllItemsAreUnique", finalMessage, parameters); @@ -874,8 +874,8 @@ public static void AllItemsAreInstancesOfType(ICollection collection, Type expec int i = 0; foreach (object element in collection) { - var elementTypeInfo = element != null ? element.GetType().GetTypeInfo() : null; - var expectedTypeInfo = expectedType != null ? expectedType.GetTypeInfo() : null; + var elementTypeInfo = element?.GetType().GetTypeInfo(); + var expectedTypeInfo = expectedType?.GetTypeInfo(); if (expectedTypeInfo != null && elementTypeInfo != null && !expectedTypeInfo.IsAssignableFrom(elementTypeInfo)) { var finalMessage = string.Format( From 862549c593cda61ba8bbf6b95c0dcfd9bbea72b2 Mon Sep 17 00:00:00 2001 From: Maximilian Chaplin Date: Tue, 3 Mar 2020 23:10:50 +0100 Subject: [PATCH 06/24] IDE0034 'default' expression can be simplified. --- .../Execution/TcmTestPropertiesProvider.cs | 32 +++++++++---------- .../Execution/ThreadSafeStringWriter.cs | 2 +- .../Helpers/RunSettingsUtilities.cs | 2 +- .../Execution/TestExecutionManagerTests.cs | 2 +- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/Adapter/MSTest.CoreAdapter/Execution/TcmTestPropertiesProvider.cs b/src/Adapter/MSTest.CoreAdapter/Execution/TcmTestPropertiesProvider.cs index 7973da7a8c..6448b75cae 100644 --- a/src/Adapter/MSTest.CoreAdapter/Execution/TcmTestPropertiesProvider.cs +++ b/src/Adapter/MSTest.CoreAdapter/Execution/TcmTestPropertiesProvider.cs @@ -22,29 +22,29 @@ internal static class TcmTestPropertiesProvider // Return empty properties when testCase is null or when test case id is zero. if (testCase == null || - testCase.GetPropertyValue(Constants.TestCaseIdProperty, default(int)) == 0) + testCase.GetPropertyValue(Constants.TestCaseIdProperty, default) == 0) { return tcmProperties; } // Step 1: Add common properties. - tcmProperties[Constants.TestRunIdProperty] = testCase.GetPropertyValue(Constants.TestRunIdProperty, default(int)); - tcmProperties[Constants.TestPlanIdProperty] = testCase.GetPropertyValue(Constants.TestPlanIdProperty, default(int)); - tcmProperties[Constants.BuildConfigurationIdProperty] = testCase.GetPropertyValue(Constants.BuildConfigurationIdProperty, default(int)); - tcmProperties[Constants.BuildDirectoryProperty] = testCase.GetPropertyValue(Constants.BuildDirectoryProperty, default(string)); - tcmProperties[Constants.BuildFlavorProperty] = testCase.GetPropertyValue(Constants.BuildFlavorProperty, default(string)); - tcmProperties[Constants.BuildNumberProperty] = testCase.GetPropertyValue(Constants.BuildNumberProperty, default(string)); - tcmProperties[Constants.BuildPlatformProperty] = testCase.GetPropertyValue(Constants.BuildPlatformProperty, default(string)); - tcmProperties[Constants.BuildUriProperty] = testCase.GetPropertyValue(Constants.BuildUriProperty, default(string)); - tcmProperties[Constants.TfsServerCollectionUrlProperty] = testCase.GetPropertyValue(Constants.TfsServerCollectionUrlProperty, default(string)); - tcmProperties[Constants.TfsTeamProjectProperty] = testCase.GetPropertyValue(Constants.TfsTeamProjectProperty, default(string)); - tcmProperties[Constants.IsInLabEnvironmentProperty] = testCase.GetPropertyValue(Constants.IsInLabEnvironmentProperty, default(bool)); + tcmProperties[Constants.TestRunIdProperty] = testCase.GetPropertyValue(Constants.TestRunIdProperty, default); + tcmProperties[Constants.TestPlanIdProperty] = testCase.GetPropertyValue(Constants.TestPlanIdProperty, default); + tcmProperties[Constants.BuildConfigurationIdProperty] = testCase.GetPropertyValue(Constants.BuildConfigurationIdProperty, default); + tcmProperties[Constants.BuildDirectoryProperty] = testCase.GetPropertyValue(Constants.BuildDirectoryProperty, default); + tcmProperties[Constants.BuildFlavorProperty] = testCase.GetPropertyValue(Constants.BuildFlavorProperty, default); + tcmProperties[Constants.BuildNumberProperty] = testCase.GetPropertyValue(Constants.BuildNumberProperty, default); + tcmProperties[Constants.BuildPlatformProperty] = testCase.GetPropertyValue(Constants.BuildPlatformProperty, default); + tcmProperties[Constants.BuildUriProperty] = testCase.GetPropertyValue(Constants.BuildUriProperty, default); + tcmProperties[Constants.TfsServerCollectionUrlProperty] = testCase.GetPropertyValue(Constants.TfsServerCollectionUrlProperty, default); + tcmProperties[Constants.TfsTeamProjectProperty] = testCase.GetPropertyValue(Constants.TfsTeamProjectProperty, default); + tcmProperties[Constants.IsInLabEnvironmentProperty] = testCase.GetPropertyValue(Constants.IsInLabEnvironmentProperty, default); // Step 2: Add test case specific properties. - tcmProperties[Constants.TestCaseIdProperty] = testCase.GetPropertyValue(Constants.TestCaseIdProperty, default(int)); - tcmProperties[Constants.TestConfigurationIdProperty] = testCase.GetPropertyValue(Constants.TestConfigurationIdProperty, default(int)); - tcmProperties[Constants.TestConfigurationNameProperty] = testCase.GetPropertyValue(Constants.TestConfigurationNameProperty, default(string)); - tcmProperties[Constants.TestPointIdProperty] = testCase.GetPropertyValue(Constants.TestPointIdProperty, default(int)); + tcmProperties[Constants.TestCaseIdProperty] = testCase.GetPropertyValue(Constants.TestCaseIdProperty, default); + tcmProperties[Constants.TestConfigurationIdProperty] = testCase.GetPropertyValue(Constants.TestConfigurationIdProperty, default); + tcmProperties[Constants.TestConfigurationNameProperty] = testCase.GetPropertyValue(Constants.TestConfigurationNameProperty, default); + tcmProperties[Constants.TestPointIdProperty] = testCase.GetPropertyValue(Constants.TestPointIdProperty, default); return tcmProperties; } diff --git a/src/Adapter/MSTest.CoreAdapter/Execution/ThreadSafeStringWriter.cs b/src/Adapter/MSTest.CoreAdapter/Execution/ThreadSafeStringWriter.cs index cf170daf29..1f88f79efd 100644 --- a/src/Adapter/MSTest.CoreAdapter/Execution/ThreadSafeStringWriter.cs +++ b/src/Adapter/MSTest.CoreAdapter/Execution/ThreadSafeStringWriter.cs @@ -35,7 +35,7 @@ public override string ToString() } catch (ObjectDisposedException) { - return default(string); + return default; } } } diff --git a/src/Adapter/MSTest.CoreAdapter/Helpers/RunSettingsUtilities.cs b/src/Adapter/MSTest.CoreAdapter/Helpers/RunSettingsUtilities.cs index d059726135..d7e0b2ddee 100644 --- a/src/Adapter/MSTest.CoreAdapter/Helpers/RunSettingsUtilities.cs +++ b/src/Adapter/MSTest.CoreAdapter/Helpers/RunSettingsUtilities.cs @@ -97,7 +97,7 @@ private static T GetNodeValue(string settingsXml, string nodeName, Func Date: Tue, 3 Mar 2020 23:12:32 +0100 Subject: [PATCH 07/24] S1066 Merge this if statement with the enclosing one. --- .../MSTest.CoreAdapter/TestMethodFilter.cs | 9 ++------- .../Data/TestDataConnection.cs | 7 ++----- .../Data/TestDataConnectionSql.cs | 17 +++++++---------- .../Utilities/DesktopReflectionUtility.cs | 9 +++------ 4 files changed, 14 insertions(+), 28 deletions(-) diff --git a/src/Adapter/MSTest.CoreAdapter/TestMethodFilter.cs b/src/Adapter/MSTest.CoreAdapter/TestMethodFilter.cs index afc795f50d..ec491ab5c7 100644 --- a/src/Adapter/MSTest.CoreAdapter/TestMethodFilter.cs +++ b/src/Adapter/MSTest.CoreAdapter/TestMethodFilter.cs @@ -82,14 +82,9 @@ internal object PropertyValueProvider(TestCase currentTest, string propertyName) if (currentTest != null && propertyName != null) { TestProperty testProperty; - if (this.supportedProperties.TryGetValue(propertyName, out testProperty)) + if (this.supportedProperties.TryGetValue(propertyName, out testProperty) && currentTest.Properties.Contains(testProperty)) { - // Test case might not have defined this property. In that case GetPropertyValue() - // would return default value. For filtering, if property is not defined return null. - if (currentTest.Properties.Contains(testProperty)) - { - return currentTest.GetPropertyValue(testProperty); - } + return currentTest.GetPropertyValue(testProperty); } } diff --git a/src/Adapter/PlatformServices.Desktop/Data/TestDataConnection.cs b/src/Adapter/PlatformServices.Desktop/Data/TestDataConnection.cs index 7baa356ace..542309c636 100644 --- a/src/Adapter/PlatformServices.Desktop/Data/TestDataConnection.cs +++ b/src/Adapter/PlatformServices.Desktop/Data/TestDataConnection.cs @@ -96,12 +96,9 @@ public virtual void Dispose() internal static bool PathNeedsFixup(string path) { - if (!string.IsNullOrEmpty(path)) + if (!string.IsNullOrEmpty(path) && path.StartsWith(ConnectionDirectoryKey, StringComparison.Ordinal)) { - if (path.StartsWith(ConnectionDirectoryKey, StringComparison.Ordinal)) - { - return true; - } + return true; } return false; diff --git a/src/Adapter/PlatformServices.Desktop/Data/TestDataConnectionSql.cs b/src/Adapter/PlatformServices.Desktop/Data/TestDataConnectionSql.cs index 8c9b18f9a0..459c2a29e1 100644 --- a/src/Adapter/PlatformServices.Desktop/Data/TestDataConnectionSql.cs +++ b/src/Adapter/PlatformServices.Desktop/Data/TestDataConnectionSql.cs @@ -533,18 +533,15 @@ public override List GetDataTablesAndViews() bool isDefaultSchema = false; // Check the table type for validity - if (metadata.TableTypeColumn != null) + if (metadata.TableTypeColumn != null && row[metadata.TableTypeColumn] != DBNull.Value) { - if (row[metadata.TableTypeColumn] != DBNull.Value) + string tableType = row[metadata.TableTypeColumn] as string; + if (!IsInArray(tableType, metadata.ValidTableTypes)) { - string tableType = row[metadata.TableTypeColumn] as string; - if (!IsInArray(tableType, metadata.ValidTableTypes)) - { - WriteDiagnostics("Table type {0} is not acceptable", tableType); - - // Not a valid table type, get the next row - continue; - } + WriteDiagnostics("Table type {0} is not acceptable", tableType); + + // Not a valid table type, get the next row + continue; } } diff --git a/src/Adapter/PlatformServices.Desktop/Utilities/DesktopReflectionUtility.cs b/src/Adapter/PlatformServices.Desktop/Utilities/DesktopReflectionUtility.cs index 5cce3d9a3f..7bd0c629cd 100644 --- a/src/Adapter/PlatformServices.Desktop/Utilities/DesktopReflectionUtility.cs +++ b/src/Adapter/PlatformServices.Desktop/Utilities/DesktopReflectionUtility.cs @@ -108,14 +108,11 @@ internal object[] GetCustomAttributes(MemberInfo memberInfo, Type type, bool inh nonUniqueAttributes); var baseDefinition = tempMethodInfo.GetBaseDefinition(); - if (baseDefinition != null) - { - if (string.Equals( + if (baseDefinition != null && string.Equals( string.Concat(tempMethodInfo.DeclaringType.FullName, tempMethodInfo.Name), string.Concat(baseDefinition.DeclaringType.FullName, baseDefinition.Name))) - { - break; - } + { + break; } tempMethodInfo = baseDefinition; From 939edb01cc23d29d2ab9420cd264b611132cf85c Mon Sep 17 00:00:00 2001 From: Maximilian Chaplin Date: Tue, 3 Mar 2020 23:16:16 +0100 Subject: [PATCH 08/24] S1125 Remove the unnecessary Boolean literal(s). --- .../MSTest.CoreAdapter/Discovery/UnitTestDiscoverer.cs | 2 +- .../MSTest.CoreAdapter/Execution/TestExecutionManager.cs | 6 +++--- .../PlatformServices.Desktop/Data/OdbcDataConnection.cs | 2 +- .../PlatformServices.Desktop/Data/OleDataConnection.cs | 2 +- .../PlatformServices.Desktop/Data/TestDataConnectionSql.cs | 2 +- .../Services/DesktopTestDataSource.cs | 2 +- .../PlatformServices.Desktop/Services/DesktopTestSource.cs | 2 +- .../netstandard1.3/Utilities/ns13DeploymentUtilityBase.cs | 2 +- src/TestFramework/Extension.Desktop/RuntimeTypeHelper.cs | 2 +- .../MSTest.Core/Assertions/CollectionAssert.cs | 2 +- 10 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Adapter/MSTest.CoreAdapter/Discovery/UnitTestDiscoverer.cs b/src/Adapter/MSTest.CoreAdapter/Discovery/UnitTestDiscoverer.cs index 4a75207da4..b75f1f065a 100644 --- a/src/Adapter/MSTest.CoreAdapter/Discovery/UnitTestDiscoverer.cs +++ b/src/Adapter/MSTest.CoreAdapter/Discovery/UnitTestDiscoverer.cs @@ -112,7 +112,7 @@ internal void SendTestCases(string source, IEnumerable testElem var testCase = testElement.ToTestCase(); // Filter tests based on test case filters - if (filterExpression != null && filterExpression.MatchTestCase(testCase, (p) => this.TestMethodFilter.PropertyValueProvider(testCase, p)) == false) + if (filterExpression != null && !filterExpression.MatchTestCase(testCase, (p) => this.TestMethodFilter.PropertyValueProvider(testCase, p))) { continue; } diff --git a/src/Adapter/MSTest.CoreAdapter/Execution/TestExecutionManager.cs b/src/Adapter/MSTest.CoreAdapter/Execution/TestExecutionManager.cs index c8a8620d04..3f719555c3 100644 --- a/src/Adapter/MSTest.CoreAdapter/Execution/TestExecutionManager.cs +++ b/src/Adapter/MSTest.CoreAdapter/Execution/TestExecutionManager.cs @@ -189,7 +189,7 @@ internal void SendTestResults(TestCase test, UnitTestResult[] unitTestResults, D private static bool MatchTestFilter(ITestCaseFilterExpression filterExpression, TestCase test, TestMethodFilter testMethodFilter) { - if (filterExpression != null && filterExpression.MatchTestCase(test, p => testMethodFilter.PropertyValueProvider(test, p)) == false) + if (filterExpression != null && !filterExpression.MatchTestCase(test, p => testMethodFilter.PropertyValueProvider(test, p))) { // Skip test if not fitting filter criteria. return false; @@ -289,8 +289,8 @@ private void ExecuteTestsInSource(IEnumerable tests, IRunContext runCo // Parallel and not parallel sets. testsets = testsToRun.GroupBy(t => t.GetPropertyValue(TestAdapter.Constants.DoNotParallelizeProperty, false)); - var parallelizableTestSet = testsets.FirstOrDefault(g => g.Key == false); - var nonparallelizableTestSet = testsets.FirstOrDefault(g => g.Key == true); + var parallelizableTestSet = testsets.FirstOrDefault(g => !g.Key); + var nonparallelizableTestSet = testsets.FirstOrDefault(g => g.Key); if (parallelizableTestSet != null) { diff --git a/src/Adapter/PlatformServices.Desktop/Data/OdbcDataConnection.cs b/src/Adapter/PlatformServices.Desktop/Data/OdbcDataConnection.cs index 6280c485bb..13af29c8ff 100644 --- a/src/Adapter/PlatformServices.Desktop/Data/OdbcDataConnection.cs +++ b/src/Adapter/PlatformServices.Desktop/Data/OdbcDataConnection.cs @@ -21,7 +21,7 @@ public OdbcDataConnection(string invariantProviderName, string connectionString, // Need open connection to get Connection.Driver. Debug.Assert(this.IsOpen(), "The connection must be open!"); - this.isMSSql = this.Connection != null ? IsMSSql(this.Connection.Driver) : false; + this.isMSSql = this.Connection != null && IsMSSql(this.Connection.Driver); } public new OdbcCommandBuilder CommandBuilder diff --git a/src/Adapter/PlatformServices.Desktop/Data/OleDataConnection.cs b/src/Adapter/PlatformServices.Desktop/Data/OleDataConnection.cs index e4019c8777..35c4fcb89b 100644 --- a/src/Adapter/PlatformServices.Desktop/Data/OleDataConnection.cs +++ b/src/Adapter/PlatformServices.Desktop/Data/OleDataConnection.cs @@ -23,7 +23,7 @@ public OleDataConnection(string invariantProviderName, string connectionString, Debug.Assert(this.IsOpen(), "The connection must be open!"); // Fill m_isMSSql. - this.isMSSql = this.Connection != null ? IsMSSql(this.Connection.Provider) : false; + this.isMSSql = this.Connection != null && IsMSSql(this.Connection.Provider); } public new OleDbCommandBuilder CommandBuilder diff --git a/src/Adapter/PlatformServices.Desktop/Data/TestDataConnectionSql.cs b/src/Adapter/PlatformServices.Desktop/Data/TestDataConnectionSql.cs index 459c2a29e1..dac84ce07b 100644 --- a/src/Adapter/PlatformServices.Desktop/Data/TestDataConnectionSql.cs +++ b/src/Adapter/PlatformServices.Desktop/Data/TestDataConnectionSql.cs @@ -725,7 +725,7 @@ private static bool IsInArray(string candidate, string[] values) public bool IsOpen() #pragma warning restore SA1202 // Elements must be ordered by access { - return this.connection != null ? this.connection.State == ConnectionState.Open : false; + return this.connection != null && this.connection.State == ConnectionState.Open; } /// diff --git a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestDataSource.cs b/src/Adapter/PlatformServices.Desktop/Services/DesktopTestDataSource.cs index 4627902a1a..bf94dcf3be 100644 --- a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestDataSource.cs +++ b/src/Adapter/PlatformServices.Desktop/Services/DesktopTestDataSource.cs @@ -122,7 +122,7 @@ private IEnumerable GetPermutation(UTF.DataAccessMethod dataAccessMethod, i /// The data access method. private void GetConnectionProperties(UTF.DataSourceAttribute dataSourceAttribute, out string providerNameInvariant, out string connectionString, out string tableName, out UTF.DataAccessMethod dataAccessMethod) { - if (string.IsNullOrEmpty(dataSourceAttribute.DataSourceSettingName) == false) + if (!string.IsNullOrEmpty(dataSourceAttribute.DataSourceSettingName)) { UTF.DataSourceElement elem = UTF.TestConfiguration.ConfigurationSection.DataSources[dataSourceAttribute.DataSourceSettingName]; if (elem == null) diff --git a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestSource.cs b/src/Adapter/PlatformServices.Desktop/Services/DesktopTestSource.cs index f00b3095e3..ec86ae8bc9 100644 --- a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestSource.cs +++ b/src/Adapter/PlatformServices.Desktop/Services/DesktopTestSource.cs @@ -47,7 +47,7 @@ public bool IsAssemblyReferenced(AssemblyName assemblyName, string source) bool? utfReference = AssemblyHelper.DoesReferencesAssembly(source, assemblyName); // If no reference to UTF don't run discovery. Take conservative approach. If not able to find proceed with discovery. - if (utfReference.HasValue && utfReference.Value == false) + if (utfReference.HasValue && !utfReference.Value) { return false; } diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentUtilityBase.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentUtilityBase.cs index 29c8fcc86b..47b3277a6a 100644 --- a/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentUtilityBase.cs +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentUtilityBase.cs @@ -392,7 +392,7 @@ protected string AddTestSourceConfigFileIfExists(string testSource, IList Date: Wed, 4 Mar 2020 17:34:28 +0100 Subject: [PATCH 09/24] CA1825 Avoid unnecessary zero-length array allocations. Use Array.Empty. --- src/TestFramework/Extension.UWP/UITestMethodAttribute.cs | 2 +- .../netstandard1.0/Utilities/ns10FileUtilityTests.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/TestFramework/Extension.UWP/UITestMethodAttribute.cs b/src/TestFramework/Extension.UWP/UITestMethodAttribute.cs index 6382aee862..06a1d0565e 100644 --- a/src/TestFramework/Extension.UWP/UITestMethodAttribute.cs +++ b/src/TestFramework/Extension.UWP/UITestMethodAttribute.cs @@ -35,7 +35,7 @@ public override TestResult[] Execute(ITestMethod testMethod) Windows.UI.Core.CoreDispatcherPriority.Normal, () => { - result = testMethod.Invoke(new object[] { }); + result = testMethod.Invoke(Array.Empty()); }).AsTask().GetAwaiter().GetResult(); return new TestResult[] { result }; diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Utilities/ns10FileUtilityTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Utilities/ns10FileUtilityTests.cs index 7ed9f78e43..9d88b8092a 100644 --- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Utilities/ns10FileUtilityTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Utilities/ns10FileUtilityTests.cs @@ -57,7 +57,7 @@ public void AddFilesInADirectoryShouldReturnAllTopLevelFilesInADirectory() var topLevelFiles = new string[] { "tick.txt", "tock.tick.txt" }; this.fileUtility.Setup(fu => fu.GetFilesInADirectory(It.IsAny())).Returns(topLevelFiles); - this.fileUtility.Setup(fu => fu.GetDirectoriesInADirectory(It.IsAny())).Returns(new string[] { }); + this.fileUtility.Setup(fu => fu.GetDirectoriesInADirectory(It.IsAny())).Returns(Array.Empty()); var files = this.fileUtility.Object.AddFilesFromDirectory("C:\\randomclock", false); From c8a2e94299f66447039b412d22949c2893003f22 Mon Sep 17 00:00:00 2001 From: Maximilian Chaplin Date: Wed, 4 Mar 2020 17:38:46 +0100 Subject: [PATCH 10/24] IDE0054 Use compound assignment. --- .../PlatformServices.Desktop/Data/TestDataConnectionSql.cs | 4 ++-- .../Services/DesktopTestSourceHost.cs | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Adapter/PlatformServices.Desktop/Data/TestDataConnectionSql.cs b/src/Adapter/PlatformServices.Desktop/Data/TestDataConnectionSql.cs index dac84ce07b..c0791af865 100644 --- a/src/Adapter/PlatformServices.Desktop/Data/TestDataConnectionSql.cs +++ b/src/Adapter/PlatformServices.Desktop/Data/TestDataConnectionSql.cs @@ -443,7 +443,7 @@ private int FindIdentifierEnd(string text, int start) } // Skip the quote we just found - here = here + 1; + here += 1; // If this the end? if (here == end || text[here] != suffixChar) @@ -453,7 +453,7 @@ private int FindIdentifierEnd(string text, int start) } // We have a double quote, skip the second one, then keep looking - here = here + 1; + here += 1; } // If we fall off end of loop, diff --git a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestSourceHost.cs b/src/Adapter/PlatformServices.Desktop/Services/DesktopTestSourceHost.cs index 3c8f862beb..e7c9928fd4 100644 --- a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestSourceHost.cs +++ b/src/Adapter/PlatformServices.Desktop/Services/DesktopTestSourceHost.cs @@ -248,7 +248,6 @@ internal virtual List GetResolutionPaths(string sourceFileName, bool isP { List resolutionPaths = new List { - // Add path of test assembly in resolution path. Mostly will be used for resolving winmd. Path.GetDirectoryName(sourceFileName) }; From f456f61faace4e439b1740c765aee3d6d259e76d Mon Sep 17 00:00:00 2001 From: Maximilian Chaplin Date: Thu, 5 Mar 2020 15:45:32 +0100 Subject: [PATCH 11/24] IDE0059 Unnecessary assignment of a value --- .../Execution/TestAssemblyInfo.cs | 7 +++--- .../Execution/TestMethodInfo.cs | 20 ++++++++-------- .../Extensions/TestResultExtensions.cs | 2 +- .../Extensions/UnitTestOutcomeExtensions.cs | 2 +- .../Deployment/AssemblyLoadWorker.cs | 4 ++-- .../DesktopTestContextImplementation.cs | 2 +- .../NetCoreTestContextImplementation.cs | 4 ++-- .../Services/ns10TestContextImplementation.cs | 2 +- .../Utilities/ns13FileUtility.cs | 4 ++-- .../Extension.Desktop/PrivateObject.cs | 9 +++---- .../Extension.Desktop/RuntimeTypeHelper.cs | 2 +- .../MSTest.Core/Assertions/Assert.cs | 6 ++--- .../Execution/UnitTestRunnerTests.cs | 4 ++-- .../Extensions/ExceptionExtensionsTests.cs | 24 +++++++++---------- .../Utilities/ns10FileUtilityTests.cs | 2 +- 15 files changed, 44 insertions(+), 50 deletions(-) diff --git a/src/Adapter/MSTest.CoreAdapter/Execution/TestAssemblyInfo.cs b/src/Adapter/MSTest.CoreAdapter/Execution/TestAssemblyInfo.cs index 2d0a23e5b9..73595e7785 100644 --- a/src/Adapter/MSTest.CoreAdapter/Execution/TestAssemblyInfo.cs +++ b/src/Adapter/MSTest.CoreAdapter/Execution/TestAssemblyInfo.cs @@ -166,10 +166,9 @@ public void RunAssemblyInitialize(TestContext testContext) var realException = this.AssemblyInitializationException.InnerException ?? this.AssemblyInitializationException; - - var outcome = UnitTestOutcome.Failed; - string errorMessage = null; - StackTraceInformation stackTraceInfo = null; + UnitTestOutcome outcome; + string errorMessage; + StackTraceInformation stackTraceInfo; if (!realException.TryGetUnitTestAssertException(out outcome, out errorMessage, out stackTraceInfo)) { var exception = realException.GetType().ToString(); diff --git a/src/Adapter/MSTest.CoreAdapter/Execution/TestMethodInfo.cs b/src/Adapter/MSTest.CoreAdapter/Execution/TestMethodInfo.cs index fd918bd17d..ee2b06962a 100644 --- a/src/Adapter/MSTest.CoreAdapter/Execution/TestMethodInfo.cs +++ b/src/Adapter/MSTest.CoreAdapter/Execution/TestMethodInfo.cs @@ -453,10 +453,9 @@ private Exception HandleMethodException(Exception ex, string className, string m // Get the real exception thrown by the test method Exception realException = this.GetRealException(ex); - string exceptionMessage = null; - StackTraceInformation exceptionStackTraceInfo = null; - var outcome = TestTools.UnitTesting.UnitTestOutcome.Failed; - + string exceptionMessage; + StackTraceInformation exceptionStackTraceInfo; + UTF.UnitTestOutcome outcome; if (realException.TryGetUnitTestAssertException(out outcome, out exceptionMessage, out exceptionStackTraceInfo)) { return new TestFailedException(outcome.ToUnitTestOutcome(), exceptionMessage, exceptionStackTraceInfo, realException); @@ -531,7 +530,10 @@ private void RunTestCleanupMethod(object classInstance, TestResult result) } catch (Exception ex) { - var cleanupOutcome = UTF.UnitTestOutcome.Failed; + StackTraceInformation realExceptionStackTraceInfo; + UTF.UnitTestOutcome cleanupOutcome; + string exceptionMessage; + var cleanupError = new StringBuilder(); var cleanupStackTrace = new StringBuilder(); StackTraceInformation cleanupStackTraceInfo = null; @@ -546,8 +548,6 @@ private void RunTestCleanupMethod(object classInstance, TestResult result) } Exception realException = ex.GetInnerExceptionOrDefault(); - string exceptionMessage = null; - StackTraceInformation realExceptionStackTraceInfo = null; // special case UnitTestAssertException to trim off part of the stack trace if (!realException.TryGetUnitTestAssertException(out cleanupOutcome, out exceptionMessage, out realExceptionStackTraceInfo)) @@ -632,9 +632,9 @@ private bool RunTestInitializeMethod(object classInstance, TestResult result) catch (Exception ex) { var innerException = ex.GetInnerExceptionOrDefault(); - string exceptionMessage = null; - StackTraceInformation exceptionStackTraceInfo = null; - var outcome = TestTools.UnitTesting.UnitTestOutcome.Failed; + string exceptionMessage; + StackTraceInformation exceptionStackTraceInfo; + UTF.UnitTestOutcome outcome; if (innerException.TryGetUnitTestAssertException(out outcome, out exceptionMessage, out exceptionStackTraceInfo)) { diff --git a/src/Adapter/MSTest.CoreAdapter/Extensions/TestResultExtensions.cs b/src/Adapter/MSTest.CoreAdapter/Extensions/TestResultExtensions.cs index 60f3794969..c355435f97 100644 --- a/src/Adapter/MSTest.CoreAdapter/Extensions/TestResultExtensions.cs +++ b/src/Adapter/MSTest.CoreAdapter/Extensions/TestResultExtensions.cs @@ -20,7 +20,7 @@ public static UnitTestResult[] ToUnitTestResults(this UTF.TestResult[] testResul for (int i = 0; i < testResults.Length; ++i) { - UnitTestResult unitTestResult = null; + UnitTestResult unitTestResult; UnitTestOutcome outcome = testResults[i].Outcome.ToUnitTestOutcome(); if (testResults[i].TestFailureException != null) diff --git a/src/Adapter/MSTest.CoreAdapter/Extensions/UnitTestOutcomeExtensions.cs b/src/Adapter/MSTest.CoreAdapter/Extensions/UnitTestOutcomeExtensions.cs index 2df6c87710..181b698ddf 100644 --- a/src/Adapter/MSTest.CoreAdapter/Extensions/UnitTestOutcomeExtensions.cs +++ b/src/Adapter/MSTest.CoreAdapter/Extensions/UnitTestOutcomeExtensions.cs @@ -16,7 +16,7 @@ public static class UnitTestOutcomeExtensions /// The adapter's UnitTestOutcome object. public static UnitTestOutcome ToUnitTestOutcome(this UTF.UnitTestOutcome frameworkTestOutcome) { - UnitTestOutcome outcome = UnitTestOutcome.Passed; + UnitTestOutcome outcome; switch (frameworkTestOutcome) { diff --git a/src/Adapter/PlatformServices.Desktop/Deployment/AssemblyLoadWorker.cs b/src/Adapter/PlatformServices.Desktop/Deployment/AssemblyLoadWorker.cs index d931c48276..25d05f629c 100644 --- a/src/Adapter/PlatformServices.Desktop/Deployment/AssemblyLoadWorker.cs +++ b/src/Adapter/PlatformServices.Desktop/Deployment/AssemblyLoadWorker.cs @@ -43,7 +43,7 @@ public string[] GetFullPathToDependentAssemblies(string assemblyPath, out IList< Debug.Assert(!string.IsNullOrEmpty(assemblyPath), "assemblyPath"); warnings = new List(); - Assembly assembly = null; + Assembly assembly; try { // First time we load in LoadFromContext to avoid issues. @@ -231,7 +231,7 @@ private void GetDependentAssembliesInternal(string assemblyString, IList visitedAssemblies.Add(assemblyString); - Assembly assembly = null; + Assembly assembly; try { string postPolicyAssembly = AppDomain.CurrentDomain.ApplyPolicy(assemblyString); diff --git a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestContextImplementation.cs b/src/Adapter/PlatformServices.Desktop/Services/DesktopTestContextImplementation.cs index 96363df5c3..146cc7225f 100644 --- a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestContextImplementation.cs +++ b/src/Adapter/PlatformServices.Desktop/Services/DesktopTestContextImplementation.cs @@ -494,7 +494,7 @@ private static UTF.UnitTestOutcome ToUTF(UTF.UnitTestOutcome outcome) /// Property value private string GetStringPropertyValue(string propertyName) { - object propertyValue = null; + object propertyValue; this.properties.TryGetValue(propertyName, out propertyValue); return propertyValue as string; } diff --git a/src/Adapter/PlatformServices.NetCore/Services/NetCoreTestContextImplementation.cs b/src/Adapter/PlatformServices.NetCore/Services/NetCoreTestContextImplementation.cs index cb753cb41a..7d4be5eb3b 100644 --- a/src/Adapter/PlatformServices.NetCore/Services/NetCoreTestContextImplementation.cs +++ b/src/Adapter/PlatformServices.NetCore/Services/NetCoreTestContextImplementation.cs @@ -420,7 +420,7 @@ public void SetDataConnection(object dbConnection) /// Property value private object GetPropertyValue(string propertyName) { - object propertyValue = null; + object propertyValue; this.properties.TryGetValue(propertyName, out propertyValue); return propertyValue; @@ -433,7 +433,7 @@ private object GetPropertyValue(string propertyName) /// Property value private string GetStringPropertyValue(string propertyName) { - object propertyValue = null; + object propertyValue; this.properties.TryGetValue(propertyName, out propertyValue); return propertyValue as string; } diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.0/Services/ns10TestContextImplementation.cs b/src/Adapter/PlatformServices.Shared/netstandard1.0/Services/ns10TestContextImplementation.cs index acdc11a496..4f21bd4d64 100644 --- a/src/Adapter/PlatformServices.Shared/netstandard1.0/Services/ns10TestContextImplementation.cs +++ b/src/Adapter/PlatformServices.Shared/netstandard1.0/Services/ns10TestContextImplementation.cs @@ -327,7 +327,7 @@ public void SetDataConnection(object dbConnection) /// Property value private object GetPropertyValue(string propertyName) { - object propertyValue = null; + object propertyValue; this.properties.TryGetValue(propertyName, out propertyValue); return propertyValue; diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13FileUtility.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13FileUtility.cs index 8f672b3194..bc84e7e690 100644 --- a/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13FileUtility.cs +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13FileUtility.cs @@ -151,8 +151,8 @@ public string FindAndDeployPdb(string destinationFile, string relativeDestinatio return null; } - string pdbDestination = null; - string relativePdbDestination = null; + string pdbDestination; + string relativePdbDestination; try { diff --git a/src/TestFramework/Extension.Desktop/PrivateObject.cs b/src/TestFramework/Extension.Desktop/PrivateObject.cs index a6c656affc..959b551de0 100644 --- a/src/TestFramework/Extension.Desktop/PrivateObject.cs +++ b/src/TestFramework/Extension.Desktop/PrivateObject.cs @@ -837,7 +837,7 @@ private LinkedList GetMethodCandidates(string methodName, Type[] par Debug.Assert(typeArguments != null, "typeArguments should not be null."); LinkedList methodCandidates = new LinkedList(); - LinkedList methods = null; + LinkedList methods; if (!this.GenericMethodCache.TryGetValue(methodName, out methods)) { @@ -849,10 +849,8 @@ private LinkedList GetMethodCandidates(string methodName, Type[] par foreach (MethodInfo candidate in methods) { bool paramMatch = true; - ParameterInfo[] candidateParams = null; + ParameterInfo[] candidateParams; Type[] genericArgs = candidate.GetGenericArguments(); - Type sourceParameterType = null; - if (genericArgs.Length != typeArguments.Length) { continue; @@ -875,8 +873,7 @@ private LinkedList GetMethodCandidates(string methodName, Type[] par foreach (ParameterInfo candidateParam in candidateParams) { - sourceParameterType = parameterTypes[i++]; - + Type sourceParameterType = parameterTypes[i++]; if (candidateParam.ParameterType.ContainsGenericParameters) { // Since we have a generic parameter here, just make sure the IsArray matches. diff --git a/src/TestFramework/Extension.Desktop/RuntimeTypeHelper.cs b/src/TestFramework/Extension.Desktop/RuntimeTypeHelper.cs index 2aa5eee64a..42ba128220 100644 --- a/src/TestFramework/Extension.Desktop/RuntimeTypeHelper.cs +++ b/src/TestFramework/Extension.Desktop/RuntimeTypeHelper.cs @@ -420,7 +420,7 @@ internal static int FindMostSpecific( } else { - return (p1Less) ? 1 : 2; + return p1Less ? 1 : 2; } } diff --git a/src/TestFramework/MSTest.Core/Assertions/Assert.cs b/src/TestFramework/MSTest.Core/Assertions/Assert.cs index c4754169ac..41ceccbbe3 100644 --- a/src/TestFramework/MSTest.Core/Assertions/Assert.cs +++ b/src/TestFramework/MSTest.Core/Assertions/Assert.cs @@ -2088,8 +2088,6 @@ public static T ThrowsException(Func action, string message, params o public static T ThrowsException(Action action, string message, params object[] parameters) where T : Exception { - var finalMessage = string.Empty; - if (action == null) { throw new ArgumentNullException(nameof(action)); @@ -2100,6 +2098,7 @@ public static T ThrowsException(Action action, string message, params object[ throw new ArgumentNullException(nameof(message)); } + string finalMessage; try { action(); @@ -2203,8 +2202,6 @@ public static async Task ThrowsExceptionAsync(Func action, string me public static async Task ThrowsExceptionAsync(Func action, string message, params object[] parameters) where T : Exception { - var finalMessage = string.Empty; - if (action == null) { throw new ArgumentNullException(nameof(action)); @@ -2215,6 +2212,7 @@ public static async Task ThrowsExceptionAsync(Func action, string me throw new ArgumentNullException(nameof(message)); } + string finalMessage; try { await action(); diff --git a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/UnitTestRunnerTests.cs b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/UnitTestRunnerTests.cs index e7795818a5..9924b78ef2 100644 --- a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/UnitTestRunnerTests.cs +++ b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/UnitTestRunnerTests.cs @@ -224,8 +224,8 @@ public void RunSingleTestShouldCallAssemblyInitializeAndClassInitializeMethodsIn It.IsAny())).Returns(true); var validator = 1; - DummyTestClassWithInitializeMethods.AssemblyInitializeMethodBody = () => { validator = validator << 2; }; - DummyTestClassWithInitializeMethods.ClassInitializeMethodBody = () => { validator = validator >> 2; }; + DummyTestClassWithInitializeMethods.AssemblyInitializeMethodBody = () => { validator <<= 2; }; + DummyTestClassWithInitializeMethods.ClassInitializeMethodBody = () => { validator >>= 2; }; this.unitTestRunner.RunSingleTest(testMethod, this.testRunParameters); diff --git a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Extensions/ExceptionExtensionsTests.cs b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Extensions/ExceptionExtensionsTests.cs index 5b4209afa7..20b06fe76b 100644 --- a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Extensions/ExceptionExtensionsTests.cs +++ b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Extensions/ExceptionExtensionsTests.cs @@ -176,9 +176,9 @@ public DummyException(Func message) public void IsUnitTestAssertExceptionReturnsTrueIfExceptionIsAssertException() { var exception = new UTF.AssertInconclusiveException(); - UTF.UnitTestOutcome outcome = UTF.UnitTestOutcome.Unknown; - string exceptionMessage = null; - StackTraceInformation stackTraceInfo = null; + UTF.UnitTestOutcome outcome; + string exceptionMessage; + StackTraceInformation stackTraceInfo; Assert.IsTrue(exception.TryGetUnitTestAssertException(out outcome, out exceptionMessage, out stackTraceInfo)); } @@ -187,9 +187,9 @@ public void IsUnitTestAssertExceptionReturnsTrueIfExceptionIsAssertException() public void IsUnitTestAssertExceptionReturnsFalseIfExceptionIsNotAssertException() { var exception = new NotImplementedException(); - UTF.UnitTestOutcome outcome = UTF.UnitTestOutcome.Unknown; - string exceptionMessage = null; - StackTraceInformation stackTraceInfo = null; + UTF.UnitTestOutcome outcome; + string exceptionMessage; + StackTraceInformation stackTraceInfo; Assert.IsFalse(exception.TryGetUnitTestAssertException(out outcome, out exceptionMessage, out stackTraceInfo)); } @@ -198,9 +198,9 @@ public void IsUnitTestAssertExceptionReturnsFalseIfExceptionIsNotAssertException public void IsUnitTestAssertExceptionSetsOutcomeAsInconclusiveIfAssertInconclusiveException() { var exception = new UTF.AssertInconclusiveException("Dummy Message", new NotImplementedException("notImplementedException")); - UTF.UnitTestOutcome outcome = UTF.UnitTestOutcome.Unknown; - string exceptionMessage = null; - StackTraceInformation stackTraceInfo = null; + UTF.UnitTestOutcome outcome; + string exceptionMessage; + StackTraceInformation stackTraceInfo; exception.TryGetUnitTestAssertException(out outcome, out exceptionMessage, out stackTraceInfo); @@ -212,9 +212,9 @@ public void IsUnitTestAssertExceptionSetsOutcomeAsInconclusiveIfAssertInconclusi public void IsUnitTestAssertExceptionSetsOutcomeAsFailedIfAssertFailedException() { var exception = new UTF.AssertFailedException("Dummy Message", new NotImplementedException("notImplementedException")); - UTF.UnitTestOutcome outcome = UTF.UnitTestOutcome.Unknown; - string exceptionMessage = null; - StackTraceInformation stackTraceInfo = null; + UTF.UnitTestOutcome outcome; + string exceptionMessage; + StackTraceInformation stackTraceInfo; exception.TryGetUnitTestAssertException(out outcome, out exceptionMessage, out stackTraceInfo); diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Utilities/ns10FileUtilityTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Utilities/ns10FileUtilityTests.cs index 9d88b8092a..7ed9f78e43 100644 --- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Utilities/ns10FileUtilityTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Utilities/ns10FileUtilityTests.cs @@ -57,7 +57,7 @@ public void AddFilesInADirectoryShouldReturnAllTopLevelFilesInADirectory() var topLevelFiles = new string[] { "tick.txt", "tock.tick.txt" }; this.fileUtility.Setup(fu => fu.GetFilesInADirectory(It.IsAny())).Returns(topLevelFiles); - this.fileUtility.Setup(fu => fu.GetDirectoriesInADirectory(It.IsAny())).Returns(Array.Empty()); + this.fileUtility.Setup(fu => fu.GetDirectoriesInADirectory(It.IsAny())).Returns(new string[] { }); var files = this.fileUtility.Object.AddFilesFromDirectory("C:\\randomclock", false); From e2e2c67cd081ca43a33bd572673cd134978b502b Mon Sep 17 00:00:00 2001 From: Maximilian Chaplin Date: Thu, 12 Mar 2020 10:02:21 +0100 Subject: [PATCH 12/24] S2971 Drop 'Where' and move the condition into the 'Count'. --- .../PlatformServices.Universal.csproj | 21 ++++++++++++++----- .../PlatformServices.Universal/project.json | 19 ----------------- .../Extension.UWP/Extension.UWP.csproj | 18 +++++++++++----- src/TestFramework/Extension.UWP/project.json | 18 ---------------- .../MSTestDiscovererTests.cs | 8 +++---- 5 files changed, 33 insertions(+), 51 deletions(-) delete mode 100644 src/Adapter/PlatformServices.Universal/project.json delete mode 100644 src/TestFramework/Extension.UWP/project.json diff --git a/src/Adapter/PlatformServices.Universal/PlatformServices.Universal.csproj b/src/Adapter/PlatformServices.Universal/PlatformServices.Universal.csproj index cec9d7b559..c7f86c0d8e 100644 --- a/src/Adapter/PlatformServices.Universal/PlatformServices.Universal.csproj +++ b/src/Adapter/PlatformServices.Universal/PlatformServices.Universal.csproj @@ -2,6 +2,7 @@ ..\..\..\ + win10-arm;win10-arm-aot;win10-x86;win10-x86-aot;win10-x64;win10-x64-aot @@ -12,7 +13,7 @@ Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices en-US UAP - 10.0.14393.0 + 10.0.18362.0 10.0.10240.0 15 {A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} @@ -102,10 +103,6 @@ prompt true - - - - Constants.cs @@ -170,6 +167,20 @@ False + + + 0.2.0 + + + 14.0.0 + + + 5.0.0 + + + 1.0.0 + + 15.0 diff --git a/src/Adapter/PlatformServices.Universal/project.json b/src/Adapter/PlatformServices.Universal/project.json deleted file mode 100644 index 3b2a0c90df..0000000000 --- a/src/Adapter/PlatformServices.Universal/project.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "dependencies": { - "MicroBuild.Core": "0.2.0", - "Microsoft.Internal.TestPlatform.ObjectModel": "14.0.0", - "Microsoft.NETCore.UniversalWindowsPlatform": "5.0.0", - "StyleCop.Analyzers": "1.0.0" - }, - "frameworks": { - "uap10.0": {} - }, - "runtimes": { - "win10-arm": {}, - "win10-arm-aot": {}, - "win10-x86": {}, - "win10-x86-aot": {}, - "win10-x64": {}, - "win10-x64-aot": {} - } -} \ No newline at end of file diff --git a/src/TestFramework/Extension.UWP/Extension.UWP.csproj b/src/TestFramework/Extension.UWP/Extension.UWP.csproj index 443acffef1..b71fa2a535 100644 --- a/src/TestFramework/Extension.UWP/Extension.UWP.csproj +++ b/src/TestFramework/Extension.UWP/Extension.UWP.csproj @@ -2,6 +2,7 @@ ..\..\..\ + win10-arm;win10-arm-aot;win10-x86;win10-x86-aot;win10-x64;win10-x64-aot @@ -12,7 +13,7 @@ Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions en-US UAP - 10.0.14393.0 + 10.0.18362.0 10.0.10240.0 15 512 @@ -99,10 +100,6 @@ $(OutputPath)\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.XML Extensions\UWP - - - - @@ -116,6 +113,17 @@ False + + + 0.2.0 + + + 5.1.0 + + + 1.0.0 + + 15.0 diff --git a/src/TestFramework/Extension.UWP/project.json b/src/TestFramework/Extension.UWP/project.json deleted file mode 100644 index 0c1778281d..0000000000 --- a/src/TestFramework/Extension.UWP/project.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "dependencies": { - "MicroBuild.Core": "0.2.0", - "Microsoft.NETCore.UniversalWindowsPlatform": "5.1.0", - "StyleCop.Analyzers": "1.0.0" - }, - "frameworks": { - "uap10.0": {} - }, - "runtimes": { - "win10-arm": {}, - "win10-arm-aot": {}, - "win10-x86": {}, - "win10-x86-aot": {}, - "win10-x64": {}, - "win10-x64-aot": {} - } -} \ No newline at end of file diff --git a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/MSTestDiscovererTests.cs b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/MSTestDiscovererTests.cs index 395e8c1f84..c910ee5f03 100644 --- a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/MSTestDiscovererTests.cs +++ b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/MSTestDiscovererTests.cs @@ -71,7 +71,7 @@ public void MSTestDiscovererHasXapAsFileExtension() { IEnumerable attributes = typeof(MSTestDiscoverer).GetTypeInfo().GetCustomAttributes(typeof(FileExtensionAttribute)).Cast(); Assert.IsNotNull(attributes); - Assert.AreEqual(1, attributes.Where(attribute => attribute.FileExtension == ".xap").Count()); + Assert.AreEqual(1, attributes.Count(attribute => attribute.FileExtension == ".xap")); } [TestMethod] @@ -79,7 +79,7 @@ public void MSTestDiscovererHasAppxAsFileExtension() { IEnumerable attributes = typeof(MSTestDiscoverer).GetTypeInfo().GetCustomAttributes(typeof(FileExtensionAttribute)).Cast(); Assert.IsNotNull(attributes); - Assert.AreEqual(1, attributes.Where(attribute => attribute.FileExtension == ".appx").Count()); + Assert.AreEqual(1, attributes.Count(attribute => attribute.FileExtension == ".appx")); } [TestMethod] @@ -87,7 +87,7 @@ public void MSTestDiscovererHasDllAsFileExtension() { IEnumerable attributes = typeof(MSTestDiscoverer).GetTypeInfo().GetCustomAttributes(typeof(FileExtensionAttribute)).Cast(); Assert.IsNotNull(attributes); - Assert.AreEqual(1, attributes.Where(attribute => attribute.FileExtension == ".dll").Count()); + Assert.AreEqual(1, attributes.Count(attribute => attribute.FileExtension == ".dll")); } [TestMethod] @@ -95,7 +95,7 @@ public void MSTestDiscovererHasExeAsFileExtension() { IEnumerable attributes = typeof(MSTestDiscoverer).GetTypeInfo().GetCustomAttributes(typeof(FileExtensionAttribute)).Cast(); Assert.IsNotNull(attributes); - Assert.AreEqual(1, attributes.Where(attribute => attribute.FileExtension == ".exe").Count()); + Assert.AreEqual(1, attributes.Count(attribute => attribute.FileExtension == ".exe")); } [TestMethod] From d2b409d37e834abda15ff3ff9f2a24eb1b860098 Mon Sep 17 00:00:00 2001 From: Maximilian Chaplin Date: Thu, 12 Mar 2020 10:03:41 +0100 Subject: [PATCH 13/24] S2971 Drop 'Where' and move the condition into the 'FirstOrDefault'. --- src/Adapter/MSTest.CoreAdapter/Execution/TypeCache.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Adapter/MSTest.CoreAdapter/Execution/TypeCache.cs b/src/Adapter/MSTest.CoreAdapter/Execution/TypeCache.cs index d11c5639d5..6c529a24e2 100644 --- a/src/Adapter/MSTest.CoreAdapter/Execution/TypeCache.cs +++ b/src/Adapter/MSTest.CoreAdapter/Execution/TypeCache.cs @@ -689,9 +689,9 @@ private MethodInfo GetMethodInfoForTestMethod(TestMethod testMethod, TestClassIn { // Only find methods that match the given declaring name. testMethodInfo = - methodsInClass.Where(method => method.Name.Equals(testMethod.Name) + methodsInClass.FirstOrDefault(method => method.Name.Equals(testMethod.Name) && method.DeclaringType.FullName.Equals(testMethod.DeclaringClassFullName) - && method.HasCorrectTestMethodSignature(true)).FirstOrDefault(); + && method.HasCorrectTestMethodSignature(true)); } else { From e744c847f4058674d524e1423685628680ec35c6 Mon Sep 17 00:00:00 2001 From: Maximilian Chaplin Date: Thu, 12 Mar 2020 10:06:12 +0100 Subject: [PATCH 14/24] S2971 Use 'Count' property here instead. --- .../Discovery/AssemblyEnumeratorTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Discovery/AssemblyEnumeratorTests.cs b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Discovery/AssemblyEnumeratorTests.cs index c47182a7e1..b1ca2faba9 100644 --- a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Discovery/AssemblyEnumeratorTests.cs +++ b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Discovery/AssemblyEnumeratorTests.cs @@ -243,7 +243,7 @@ public void EnumerateAssemblyShouldReturnEmptyListWhenNoDeclaredTypes() this.testablePlatformServiceProvider.MockFileOperations.Setup(fo => fo.LoadAssembly("DummyAssembly", false)) .Returns(mockAssembly.Object); - Assert.AreEqual(0, this.assemblyEnumerator.EnumerateAssembly("DummyAssembly", out this.warnings).Count()); + Assert.AreEqual(0, this.assemblyEnumerator.EnumerateAssembly("DummyAssembly", out this.warnings).Count); } [TestMethodV1] @@ -260,7 +260,7 @@ public void EnumerateAssemblyShouldReturnEmptyListWhenNoTestElementsInAType() testableAssemblyEnumerator.MockTypeEnumerator.Setup(te => te.Enumerate(out this.warnings)) .Returns((ICollection)null); - Assert.AreEqual(0, this.assemblyEnumerator.EnumerateAssembly("DummyAssembly", out this.warnings).Count()); + Assert.AreEqual(0, this.assemblyEnumerator.EnumerateAssembly("DummyAssembly", out this.warnings).Count); } [TestMethodV1] From bcb80c2e9b4eb2f52280c96bd8a4238c23fae449 Mon Sep 17 00:00:00 2001 From: Maximilian Chaplin Date: Thu, 12 Mar 2020 10:07:01 +0100 Subject: [PATCH 15/24] Revert "S2971 Drop 'Where' and move the condition into the 'Count'." This reverts commit e2e2c67cd081ca43a33bd572673cd134978b502b. --- .../PlatformServices.Universal.csproj | 21 +++++-------------- .../PlatformServices.Universal/project.json | 19 +++++++++++++++++ .../Extension.UWP/Extension.UWP.csproj | 18 +++++----------- src/TestFramework/Extension.UWP/project.json | 18 ++++++++++++++++ .../MSTestDiscovererTests.cs | 8 +++---- 5 files changed, 51 insertions(+), 33 deletions(-) create mode 100644 src/Adapter/PlatformServices.Universal/project.json create mode 100644 src/TestFramework/Extension.UWP/project.json diff --git a/src/Adapter/PlatformServices.Universal/PlatformServices.Universal.csproj b/src/Adapter/PlatformServices.Universal/PlatformServices.Universal.csproj index c7f86c0d8e..cec9d7b559 100644 --- a/src/Adapter/PlatformServices.Universal/PlatformServices.Universal.csproj +++ b/src/Adapter/PlatformServices.Universal/PlatformServices.Universal.csproj @@ -2,7 +2,6 @@ ..\..\..\ - win10-arm;win10-arm-aot;win10-x86;win10-x86-aot;win10-x64;win10-x64-aot @@ -13,7 +12,7 @@ Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices en-US UAP - 10.0.18362.0 + 10.0.14393.0 10.0.10240.0 15 {A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} @@ -103,6 +102,10 @@ prompt true + + + + Constants.cs @@ -167,20 +170,6 @@ False - - - 0.2.0 - - - 14.0.0 - - - 5.0.0 - - - 1.0.0 - - 15.0 diff --git a/src/Adapter/PlatformServices.Universal/project.json b/src/Adapter/PlatformServices.Universal/project.json new file mode 100644 index 0000000000..3b2a0c90df --- /dev/null +++ b/src/Adapter/PlatformServices.Universal/project.json @@ -0,0 +1,19 @@ +{ + "dependencies": { + "MicroBuild.Core": "0.2.0", + "Microsoft.Internal.TestPlatform.ObjectModel": "14.0.0", + "Microsoft.NETCore.UniversalWindowsPlatform": "5.0.0", + "StyleCop.Analyzers": "1.0.0" + }, + "frameworks": { + "uap10.0": {} + }, + "runtimes": { + "win10-arm": {}, + "win10-arm-aot": {}, + "win10-x86": {}, + "win10-x86-aot": {}, + "win10-x64": {}, + "win10-x64-aot": {} + } +} \ No newline at end of file diff --git a/src/TestFramework/Extension.UWP/Extension.UWP.csproj b/src/TestFramework/Extension.UWP/Extension.UWP.csproj index b71fa2a535..443acffef1 100644 --- a/src/TestFramework/Extension.UWP/Extension.UWP.csproj +++ b/src/TestFramework/Extension.UWP/Extension.UWP.csproj @@ -2,7 +2,6 @@ ..\..\..\ - win10-arm;win10-arm-aot;win10-x86;win10-x86-aot;win10-x64;win10-x64-aot @@ -13,7 +12,7 @@ Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions en-US UAP - 10.0.18362.0 + 10.0.14393.0 10.0.10240.0 15 512 @@ -100,6 +99,10 @@ $(OutputPath)\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.XML Extensions\UWP + + + + @@ -113,17 +116,6 @@ False - - - 0.2.0 - - - 5.1.0 - - - 1.0.0 - - 15.0 diff --git a/src/TestFramework/Extension.UWP/project.json b/src/TestFramework/Extension.UWP/project.json new file mode 100644 index 0000000000..0c1778281d --- /dev/null +++ b/src/TestFramework/Extension.UWP/project.json @@ -0,0 +1,18 @@ +{ + "dependencies": { + "MicroBuild.Core": "0.2.0", + "Microsoft.NETCore.UniversalWindowsPlatform": "5.1.0", + "StyleCop.Analyzers": "1.0.0" + }, + "frameworks": { + "uap10.0": {} + }, + "runtimes": { + "win10-arm": {}, + "win10-arm-aot": {}, + "win10-x86": {}, + "win10-x86-aot": {}, + "win10-x64": {}, + "win10-x64-aot": {} + } +} \ No newline at end of file diff --git a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/MSTestDiscovererTests.cs b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/MSTestDiscovererTests.cs index c910ee5f03..395e8c1f84 100644 --- a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/MSTestDiscovererTests.cs +++ b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/MSTestDiscovererTests.cs @@ -71,7 +71,7 @@ public void MSTestDiscovererHasXapAsFileExtension() { IEnumerable attributes = typeof(MSTestDiscoverer).GetTypeInfo().GetCustomAttributes(typeof(FileExtensionAttribute)).Cast(); Assert.IsNotNull(attributes); - Assert.AreEqual(1, attributes.Count(attribute => attribute.FileExtension == ".xap")); + Assert.AreEqual(1, attributes.Where(attribute => attribute.FileExtension == ".xap").Count()); } [TestMethod] @@ -79,7 +79,7 @@ public void MSTestDiscovererHasAppxAsFileExtension() { IEnumerable attributes = typeof(MSTestDiscoverer).GetTypeInfo().GetCustomAttributes(typeof(FileExtensionAttribute)).Cast(); Assert.IsNotNull(attributes); - Assert.AreEqual(1, attributes.Count(attribute => attribute.FileExtension == ".appx")); + Assert.AreEqual(1, attributes.Where(attribute => attribute.FileExtension == ".appx").Count()); } [TestMethod] @@ -87,7 +87,7 @@ public void MSTestDiscovererHasDllAsFileExtension() { IEnumerable attributes = typeof(MSTestDiscoverer).GetTypeInfo().GetCustomAttributes(typeof(FileExtensionAttribute)).Cast(); Assert.IsNotNull(attributes); - Assert.AreEqual(1, attributes.Count(attribute => attribute.FileExtension == ".dll")); + Assert.AreEqual(1, attributes.Where(attribute => attribute.FileExtension == ".dll").Count()); } [TestMethod] @@ -95,7 +95,7 @@ public void MSTestDiscovererHasExeAsFileExtension() { IEnumerable attributes = typeof(MSTestDiscoverer).GetTypeInfo().GetCustomAttributes(typeof(FileExtensionAttribute)).Cast(); Assert.IsNotNull(attributes); - Assert.AreEqual(1, attributes.Count(attribute => attribute.FileExtension == ".exe")); + Assert.AreEqual(1, attributes.Where(attribute => attribute.FileExtension == ".exe").Count()); } [TestMethod] From 4cc118b1a58b2dcf08860fb6007a5b6bf0aeff5e Mon Sep 17 00:00:00 2001 From: Maximilian Chaplin Date: Thu, 12 Mar 2020 10:15:37 +0100 Subject: [PATCH 16/24] S3415 Make sure these 2 arguments are in the correct order: expected value, actual value. --- .../Execution/UnitTestRunnerTests.cs | 2 +- .../Services/DesktopTestDataSourceTests.cs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/UnitTestRunnerTests.cs b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/UnitTestRunnerTests.cs index 9924b78ef2..ef23905920 100644 --- a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/UnitTestRunnerTests.cs +++ b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/UnitTestRunnerTests.cs @@ -294,7 +294,7 @@ public void RunCleanupShouldReturnCleanupResultsWithDebugTraceLogsSetIfDebugTrac this.unitTestRunner.RunSingleTest(testMethod, this.testRunParameters); var cleanupresult = this.unitTestRunner.RunCleanup(); - Assert.AreEqual(cleanupresult.DebugTrace, "DummyTrace"); + Assert.AreEqual("DummyTrace", cleanupresult.DebugTrace); } [TestMethodV1] diff --git a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestDataSourceTests.cs b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestDataSourceTests.cs index e69e75cbf2..c412c718bf 100644 --- a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestDataSourceTests.cs +++ b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestDataSourceTests.cs @@ -89,15 +89,15 @@ public DesktopTestFrameworkV2.TestContext TestContext [TestFrameworkV2.TestMethod] public void PassingTest() { - Assert.AreEqual(this.testContextInstance.DataRow["adapter"].ToString(), "v1"); - Assert.AreEqual(this.testContextInstance.DataRow["targetPlatform"].ToString(), "x86"); + Assert.AreEqual("v1", this.testContextInstance.DataRow["adapter"].ToString()); + Assert.AreEqual("x86", this.testContextInstance.DataRow["targetPlatform"].ToString()); this.TestContext.AddResultFile("C:\\temp.txt"); } [TestFrameworkV2.TestMethod] public void FailingTest() { - Assert.AreEqual(this.testContextInstance.DataRow["configuration"].ToString(), "Release"); + Assert.AreEqual("Release", this.testContextInstance.DataRow["configuration"].ToString()); } } From cab75c5bd53a896f8e54c21f5eb077b856a90202 Mon Sep 17 00:00:00 2001 From: Maximilian Chaplin Date: Thu, 12 Mar 2020 10:16:44 +0100 Subject: [PATCH 17/24] S2971 Drop 'Where' and move the condition into the 'Count'. --- .../MSTestDiscovererTests.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/MSTestDiscovererTests.cs b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/MSTestDiscovererTests.cs index 395e8c1f84..c910ee5f03 100644 --- a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/MSTestDiscovererTests.cs +++ b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/MSTestDiscovererTests.cs @@ -71,7 +71,7 @@ public void MSTestDiscovererHasXapAsFileExtension() { IEnumerable attributes = typeof(MSTestDiscoverer).GetTypeInfo().GetCustomAttributes(typeof(FileExtensionAttribute)).Cast(); Assert.IsNotNull(attributes); - Assert.AreEqual(1, attributes.Where(attribute => attribute.FileExtension == ".xap").Count()); + Assert.AreEqual(1, attributes.Count(attribute => attribute.FileExtension == ".xap")); } [TestMethod] @@ -79,7 +79,7 @@ public void MSTestDiscovererHasAppxAsFileExtension() { IEnumerable attributes = typeof(MSTestDiscoverer).GetTypeInfo().GetCustomAttributes(typeof(FileExtensionAttribute)).Cast(); Assert.IsNotNull(attributes); - Assert.AreEqual(1, attributes.Where(attribute => attribute.FileExtension == ".appx").Count()); + Assert.AreEqual(1, attributes.Count(attribute => attribute.FileExtension == ".appx")); } [TestMethod] @@ -87,7 +87,7 @@ public void MSTestDiscovererHasDllAsFileExtension() { IEnumerable attributes = typeof(MSTestDiscoverer).GetTypeInfo().GetCustomAttributes(typeof(FileExtensionAttribute)).Cast(); Assert.IsNotNull(attributes); - Assert.AreEqual(1, attributes.Where(attribute => attribute.FileExtension == ".dll").Count()); + Assert.AreEqual(1, attributes.Count(attribute => attribute.FileExtension == ".dll")); } [TestMethod] @@ -95,7 +95,7 @@ public void MSTestDiscovererHasExeAsFileExtension() { IEnumerable attributes = typeof(MSTestDiscoverer).GetTypeInfo().GetCustomAttributes(typeof(FileExtensionAttribute)).Cast(); Assert.IsNotNull(attributes); - Assert.AreEqual(1, attributes.Where(attribute => attribute.FileExtension == ".exe").Count()); + Assert.AreEqual(1, attributes.Count(attribute => attribute.FileExtension == ".exe")); } [TestMethod] From 4a45d1ab7f211357186e8bff604557ad3937eaad Mon Sep 17 00:00:00 2001 From: Maximilian Chaplin Date: Thu, 12 Mar 2020 10:24:04 +0100 Subject: [PATCH 18/24] S1128 Remove this unnecessary 'using'. --- .../E2ETests/TestAssets/DeploymentTestProject/UnitTest1.cs | 3 +-- .../FxExtensibilityTestProject/Properties/AssemblyInfo.cs | 1 - .../ParallelTestClass/Properties/AssemblyInfo.cs | 2 -- .../ParallelTestMethods/Properties/AssemblyInfo.cs | 2 -- .../TimeoutTestProject/SelfTerminatingTestClass.cs | 7 +------ .../TerimnateLongRunningTasksUsingTokenTestClass.cs | 3 --- .../TimeoutTestProjectNetCore/SelfTerminatingTestClass.cs | 7 +------ .../TerimnateLongRunningTasksUsingTokenTestClass.cs | 3 --- 8 files changed, 3 insertions(+), 25 deletions(-) diff --git a/test/E2ETests/TestAssets/DeploymentTestProject/UnitTest1.cs b/test/E2ETests/TestAssets/DeploymentTestProject/UnitTest1.cs index 8109354496..f9a43c0d05 100644 --- a/test/E2ETests/TestAssets/DeploymentTestProject/UnitTest1.cs +++ b/test/E2ETests/TestAssets/DeploymentTestProject/UnitTest1.cs @@ -1,5 +1,4 @@ -using System; -using System.IO; +using System.IO; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace DeploymentTestProject diff --git a/test/E2ETests/TestAssets/FxExtensibilityTestProject/Properties/AssemblyInfo.cs b/test/E2ETests/TestAssets/FxExtensibilityTestProject/Properties/AssemblyInfo.cs index 893dae4a13..da2d4317de 100644 --- a/test/E2ETests/TestAssets/FxExtensibilityTestProject/Properties/AssemblyInfo.cs +++ b/test/E2ETests/TestAssets/FxExtensibilityTestProject/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following diff --git a/test/E2ETests/TestAssets/ParallelTestClass/Properties/AssemblyInfo.cs b/test/E2ETests/TestAssets/ParallelTestClass/Properties/AssemblyInfo.cs index 743ebee94b..4f54c36ef8 100644 --- a/test/E2ETests/TestAssets/ParallelTestClass/Properties/AssemblyInfo.cs +++ b/test/E2ETests/TestAssets/ParallelTestClass/Properties/AssemblyInfo.cs @@ -1,7 +1,5 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using Microsoft.VisualStudio.TestTools.UnitTesting; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information diff --git a/test/E2ETests/TestAssets/ParallelTestMethods/Properties/AssemblyInfo.cs b/test/E2ETests/TestAssets/ParallelTestMethods/Properties/AssemblyInfo.cs index e9bb21ce0c..f805e4b174 100644 --- a/test/E2ETests/TestAssets/ParallelTestMethods/Properties/AssemblyInfo.cs +++ b/test/E2ETests/TestAssets/ParallelTestMethods/Properties/AssemblyInfo.cs @@ -1,7 +1,5 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using Microsoft.VisualStudio.TestTools.UnitTesting; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information diff --git a/test/E2ETests/TestAssets/TimeoutTestProject/SelfTerminatingTestClass.cs b/test/E2ETests/TestAssets/TimeoutTestProject/SelfTerminatingTestClass.cs index 9945962493..24c97b8e2c 100644 --- a/test/E2ETests/TestAssets/TimeoutTestProject/SelfTerminatingTestClass.cs +++ b/test/E2ETests/TestAssets/TimeoutTestProject/SelfTerminatingTestClass.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace TimeoutTestProject { diff --git a/test/E2ETests/TestAssets/TimeoutTestProject/TerimnateLongRunningTasksUsingTokenTestClass.cs b/test/E2ETests/TestAssets/TimeoutTestProject/TerimnateLongRunningTasksUsingTokenTestClass.cs index 808f7af935..3012915e30 100644 --- a/test/E2ETests/TestAssets/TimeoutTestProject/TerimnateLongRunningTasksUsingTokenTestClass.cs +++ b/test/E2ETests/TestAssets/TimeoutTestProject/TerimnateLongRunningTasksUsingTokenTestClass.cs @@ -1,8 +1,5 @@ using System; -using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.VisualStudio.TestTools.UnitTesting; diff --git a/test/E2ETests/TestAssets/TimeoutTestProjectNetCore/SelfTerminatingTestClass.cs b/test/E2ETests/TestAssets/TimeoutTestProjectNetCore/SelfTerminatingTestClass.cs index 9945962493..24c97b8e2c 100644 --- a/test/E2ETests/TestAssets/TimeoutTestProjectNetCore/SelfTerminatingTestClass.cs +++ b/test/E2ETests/TestAssets/TimeoutTestProjectNetCore/SelfTerminatingTestClass.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace TimeoutTestProject { diff --git a/test/E2ETests/TestAssets/TimeoutTestProjectNetCore/TerimnateLongRunningTasksUsingTokenTestClass.cs b/test/E2ETests/TestAssets/TimeoutTestProjectNetCore/TerimnateLongRunningTasksUsingTokenTestClass.cs index 2147c35b66..34cae0b840 100644 --- a/test/E2ETests/TestAssets/TimeoutTestProjectNetCore/TerimnateLongRunningTasksUsingTokenTestClass.cs +++ b/test/E2ETests/TestAssets/TimeoutTestProjectNetCore/TerimnateLongRunningTasksUsingTokenTestClass.cs @@ -1,8 +1,5 @@ using System; -using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.VisualStudio.TestTools.UnitTesting; From 30957fc46a77757bf6ee8b2c8e32ee6c1ca5f5dc Mon Sep 17 00:00:00 2001 From: Maximilian Chaplin Date: Thu, 12 Mar 2020 10:26:31 +0100 Subject: [PATCH 19/24] S1939 'int' should not be explicitly used as the underlying type. --- src/Adapter/MSTest.CoreAdapter/ObjectModel/UnitTestOutcome.cs | 2 +- src/TestFramework/MSTest.Core/UnitTestOutcome.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Adapter/MSTest.CoreAdapter/ObjectModel/UnitTestOutcome.cs b/src/Adapter/MSTest.CoreAdapter/ObjectModel/UnitTestOutcome.cs index eb70a80dff..cabf3c7683 100644 --- a/src/Adapter/MSTest.CoreAdapter/ObjectModel/UnitTestOutcome.cs +++ b/src/Adapter/MSTest.CoreAdapter/ObjectModel/UnitTestOutcome.cs @@ -6,7 +6,7 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel /// /// Outcome of a test /// - public enum UnitTestOutcome : int + public enum UnitTestOutcome { /// /// There was a system error while we were trying to execute a test. diff --git a/src/TestFramework/MSTest.Core/UnitTestOutcome.cs b/src/TestFramework/MSTest.Core/UnitTestOutcome.cs index f90353d4f5..dc94d92e0e 100644 --- a/src/TestFramework/MSTest.Core/UnitTestOutcome.cs +++ b/src/TestFramework/MSTest.Core/UnitTestOutcome.cs @@ -6,7 +6,7 @@ namespace Microsoft.VisualStudio.TestTools.UnitTesting /// /// unit test outcomes /// - public enum UnitTestOutcome : int + public enum UnitTestOutcome { /// /// Test was executed, but there were issues. From 0068609e0c0afbf51834a9d00eb0ceeb4ae2118b Mon Sep 17 00:00:00 2001 From: Maximilian Chaplin Date: Thu, 12 Mar 2020 10:27:51 +0100 Subject: [PATCH 20/24] S1155 Use '.Any()' to test whether this 'IEnumerable' is empty or not. --- .../Services/DesktopTestContextImplementation.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestContextImplementation.cs b/src/Adapter/PlatformServices.Desktop/Services/DesktopTestContextImplementation.cs index 146cc7225f..373058fb6d 100644 --- a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestContextImplementation.cs +++ b/src/Adapter/PlatformServices.Desktop/Services/DesktopTestContextImplementation.cs @@ -407,7 +407,7 @@ public void AddProperty(string propertyName, string propertyValue) /// Results files generated in run. public IList GetResultFiles() { - if (this.testResultFiles.Count() == 0) + if (this.testResultFiles.Any()) { return null; } From a3cd16b819b531a29e1e5c4dad7b0e6a05519ab8 Mon Sep 17 00:00:00 2001 From: Maximilian Chaplin Date: Thu, 12 Mar 2020 11:00:42 +0100 Subject: [PATCH 21/24] Fix Using thats only used for not for NETSTANDARD1_5 --- .../netstandard1.3/Services/ns13TestDeployment.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13TestDeployment.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13TestDeployment.cs index 6a66d03ddc..fbfd7f669b 100644 --- a/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13TestDeployment.cs +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13TestDeployment.cs @@ -15,7 +15,9 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; +#if !NETSTANDARD1_5 using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; +#endif /// /// The test deployment. From 442afc120f030ef1693e973414ead1ee0d922aae Mon Sep 17 00:00:00 2001 From: Maximilian Chaplin Date: Thu, 12 Mar 2020 13:23:23 +0100 Subject: [PATCH 22/24] CA1813 Avoid unsealed attributes. --- src/TestFramework/Extension.UWP/UITestMethodAttribute.cs | 2 +- src/TestFramework/MSTest.Core/Attributes/DataRowAttribute.cs | 2 +- .../MSTest.Core/Attributes/DoNotParallelizeAttribute.cs | 2 +- .../MSTest.Core/Attributes/ParallelizeAttribute.cs | 2 +- src/TestFramework/MSTest.Core/Attributes/VSTestAttributes.cs | 2 +- .../FxExtensibilityTestProject/CustomTestExTests.cs | 4 ++-- .../FxExtensibilityTestProject/TestDataSourceExTests.cs | 2 +- .../Attributes/ExpectedExceptionBaseAttributeTests.cs | 2 +- .../Execution/TestClassInfoTests.cs | 2 +- .../Execution/TestExecutionManagerTests.cs | 2 +- .../Execution/TestMethodFilterTests.cs | 2 +- .../Execution/TestMethodInfoTests.cs | 2 +- .../MSTest.CoreAdapter.Unit.Tests/Execution/TypeCacheTests.cs | 4 ++-- .../Execution/UnitTestRunnerTests.cs | 2 +- .../Helpers/ReflectHelperTests.cs | 2 +- .../Utilities/DesktopReflectionUtilityTests.cs | 2 +- .../netstandard1.0/ns10ReflectionOperationsTests.cs | 4 ++-- .../netstandard1.3/Utilities/ns13ReflectionUtilityTests.cs | 2 +- 18 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/TestFramework/Extension.UWP/UITestMethodAttribute.cs b/src/TestFramework/Extension.UWP/UITestMethodAttribute.cs index 06a1d0565e..13e4f504fe 100644 --- a/src/TestFramework/Extension.UWP/UITestMethodAttribute.cs +++ b/src/TestFramework/Extension.UWP/UITestMethodAttribute.cs @@ -9,7 +9,7 @@ namespace Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer /// /// Execute test code in UI thread for Windows store apps. /// - public class UITestMethodAttribute : TestMethodAttribute + public sealed class UITestMethodAttribute : TestMethodAttribute { /// /// Executes the test method on the UI Thread. diff --git a/src/TestFramework/MSTest.Core/Attributes/DataRowAttribute.cs b/src/TestFramework/MSTest.Core/Attributes/DataRowAttribute.cs index c8c641e461..009e8123b0 100644 --- a/src/TestFramework/MSTest.Core/Attributes/DataRowAttribute.cs +++ b/src/TestFramework/MSTest.Core/Attributes/DataRowAttribute.cs @@ -13,7 +13,7 @@ namespace Microsoft.VisualStudio.TestTools.UnitTesting /// Attribute to define in-line data for a test method. /// [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] - public class DataRowAttribute : Attribute, ITestDataSource + public sealed class DataRowAttribute : Attribute, ITestDataSource { /// /// Initializes a new instance of the class. diff --git a/src/TestFramework/MSTest.Core/Attributes/DoNotParallelizeAttribute.cs b/src/TestFramework/MSTest.Core/Attributes/DoNotParallelizeAttribute.cs index 14c6d101fa..d47b562d0e 100644 --- a/src/TestFramework/MSTest.Core/Attributes/DoNotParallelizeAttribute.cs +++ b/src/TestFramework/MSTest.Core/Attributes/DoNotParallelizeAttribute.cs @@ -9,7 +9,7 @@ namespace Microsoft.VisualStudio.TestTools.UnitTesting /// Specification to disable parallelization. /// [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false)] - public class DoNotParallelizeAttribute : Attribute + public sealed class DoNotParallelizeAttribute : Attribute { } } \ No newline at end of file diff --git a/src/TestFramework/MSTest.Core/Attributes/ParallelizeAttribute.cs b/src/TestFramework/MSTest.Core/Attributes/ParallelizeAttribute.cs index 9564002619..9f0b67070a 100644 --- a/src/TestFramework/MSTest.Core/Attributes/ParallelizeAttribute.cs +++ b/src/TestFramework/MSTest.Core/Attributes/ParallelizeAttribute.cs @@ -9,7 +9,7 @@ namespace Microsoft.VisualStudio.TestTools.UnitTesting /// Specification for parallelization level for a test run. /// [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false)] - public class ParallelizeAttribute : Attribute + public sealed class ParallelizeAttribute : Attribute { private const int DefaultParallelWorkers = 0; diff --git a/src/TestFramework/MSTest.Core/Attributes/VSTestAttributes.cs b/src/TestFramework/MSTest.Core/Attributes/VSTestAttributes.cs index a87c0bd61a..8256a9eb99 100644 --- a/src/TestFramework/MSTest.Core/Attributes/VSTestAttributes.cs +++ b/src/TestFramework/MSTest.Core/Attributes/VSTestAttributes.cs @@ -107,7 +107,7 @@ public virtual TestResult[] Execute(ITestMethod testMethod) /// Attribute for data driven test where data can be specified in-line. /// [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] - public class DataTestMethodAttribute : TestMethodAttribute + public sealed class DataTestMethodAttribute : TestMethodAttribute { } diff --git a/test/E2ETests/TestAssets/FxExtensibilityTestProject/CustomTestExTests.cs b/test/E2ETests/TestAssets/FxExtensibilityTestProject/CustomTestExTests.cs index c42be4a431..0e5b968f3a 100644 --- a/test/E2ETests/TestAssets/FxExtensibilityTestProject/CustomTestExTests.cs +++ b/test/E2ETests/TestAssets/FxExtensibilityTestProject/CustomTestExTests.cs @@ -32,7 +32,7 @@ public void CustomTestClass1() } } - public class IterativeTestMethodAttribute : TestMethodAttribute + public sealed class IterativeTestMethodAttribute : TestMethodAttribute { private readonly int stabilityThreshold; @@ -58,7 +58,7 @@ public override TestResult[] Execute(ITestMethod testMethod) } } - public class IterativeTestClassAttribute : TestClassAttribute + public sealed class IterativeTestClassAttribute : TestClassAttribute { private readonly int stabilityThreshold; diff --git a/test/E2ETests/TestAssets/FxExtensibilityTestProject/TestDataSourceExTests.cs b/test/E2ETests/TestAssets/FxExtensibilityTestProject/TestDataSourceExTests.cs index 022a471851..0f151f56dd 100644 --- a/test/E2ETests/TestAssets/FxExtensibilityTestProject/TestDataSourceExTests.cs +++ b/test/E2ETests/TestAssets/FxExtensibilityTestProject/TestDataSourceExTests.cs @@ -21,7 +21,7 @@ public void CustomTestDataSourceTestMethod1(int a, int b, int c) } [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] - public class CustomTestDataSourceAttribute : Attribute, ITestDataSource + public sealed class CustomTestDataSourceAttribute : Attribute, ITestDataSource { public IEnumerable GetData(MethodInfo methodInfo) { diff --git a/test/UnitTests/MSTest.Core.Unit.Tests/Attributes/ExpectedExceptionBaseAttributeTests.cs b/test/UnitTests/MSTest.Core.Unit.Tests/Attributes/ExpectedExceptionBaseAttributeTests.cs index e74692a706..7002380490 100644 --- a/test/UnitTests/MSTest.Core.Unit.Tests/Attributes/ExpectedExceptionBaseAttributeTests.cs +++ b/test/UnitTests/MSTest.Core.Unit.Tests/Attributes/ExpectedExceptionBaseAttributeTests.cs @@ -76,7 +76,7 @@ public void VerifyEmptytMessageIsGettingSetInVariablenoExceptionMessage() /// /// Dummy class derived from Exception /// - public class TestableExpectedExceptionBaseAttributeClass : TestFrameworkV2.ExpectedExceptionBaseAttribute + public sealed class TestableExpectedExceptionBaseAttributeClass : TestFrameworkV2.ExpectedExceptionBaseAttribute { public TestableExpectedExceptionBaseAttributeClass() : base() diff --git a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TestClassInfoTests.cs b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TestClassInfoTests.cs index 90deb1ad64..b8190198ee 100644 --- a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TestClassInfoTests.cs +++ b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TestClassInfoTests.cs @@ -600,7 +600,7 @@ public static void ClassCleanupMethod() } } - private class DummyTestClassAttribute : UTF.TestClassAttribute + private sealed class DummyTestClassAttribute : UTF.TestClassAttribute { } } diff --git a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TestExecutionManagerTests.cs b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TestExecutionManagerTests.cs index 3b0962ac8d..db8159a788 100644 --- a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TestExecutionManagerTests.cs +++ b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TestExecutionManagerTests.cs @@ -1106,7 +1106,7 @@ public void TestMethod4() } } - private class DummyTestClassAttribute : UTF.TestClassAttribute + private sealed class DummyTestClassAttribute : UTF.TestClassAttribute { } diff --git a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TestMethodFilterTests.cs b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TestMethodFilterTests.cs index 3759a38a9f..314cab9228 100644 --- a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TestMethodFilterTests.cs +++ b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TestMethodFilterTests.cs @@ -283,7 +283,7 @@ public bool MatchTestCase(TestCase testCase, Func propertyValueP } } - private class DummyTestClassAttribute : UTF.TestClassAttribute + private sealed class DummyTestClassAttribute : UTF.TestClassAttribute { } } diff --git a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TestMethodInfoTests.cs b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TestMethodInfoTests.cs index d63ed42dd6..bc41b94b2b 100644 --- a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TestMethodInfoTests.cs +++ b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TestMethodInfoTests.cs @@ -1605,7 +1605,7 @@ protected override void Verify(Exception exception) /// /// Custom Expected exception attribute which overrides the Verify method. /// - public class DerivedCustomExpectedExceptionAttribute : CustomExpectedExceptionAttribute + public sealed class DerivedCustomExpectedExceptionAttribute : CustomExpectedExceptionAttribute { public DerivedCustomExpectedExceptionAttribute(Type expectionType, string noExceptionMessage) : base(expectionType, noExceptionMessage) diff --git a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TypeCacheTests.cs b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TypeCacheTests.cs index 07c3b8f841..4c0f575317 100644 --- a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TypeCacheTests.cs +++ b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TypeCacheTests.cs @@ -1693,11 +1693,11 @@ public static void TestMethod() } } - private class DerivedTestMethodAttribute : UTF.TestMethodAttribute + private sealed class DerivedTestMethodAttribute : UTF.TestMethodAttribute { } - private class DummyTestClassAttribute : UTF.TestClassAttribute + private sealed class DummyTestClassAttribute : UTF.TestClassAttribute { } diff --git a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/UnitTestRunnerTests.cs b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/UnitTestRunnerTests.cs index ef23905920..7ab3ae04c9 100644 --- a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/UnitTestRunnerTests.cs +++ b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/UnitTestRunnerTests.cs @@ -412,7 +412,7 @@ public void TestMethod() } } - private class DummyTestClassAttribute : UTF.TestClassAttribute + private sealed class DummyTestClassAttribute : UTF.TestClassAttribute { } diff --git a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Helpers/ReflectHelperTests.cs b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Helpers/ReflectHelperTests.cs index 49bb940e5f..d4798c0b45 100644 --- a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Helpers/ReflectHelperTests.cs +++ b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Helpers/ReflectHelperTests.cs @@ -317,7 +317,7 @@ public void HasAttributeDerivedFromShouldReturnTrueQueryingProvidedAttributesExi #region Dummy Implmentations - public class TestableExtendedTestMethod : UTF.TestMethodAttribute + public sealed class TestableExtendedTestMethod : UTF.TestMethodAttribute { } diff --git a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Utilities/DesktopReflectionUtilityTests.cs b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Utilities/DesktopReflectionUtilityTests.cs index 3986db4ebf..9ecddb5763 100644 --- a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Utilities/DesktopReflectionUtilityTests.cs +++ b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Utilities/DesktopReflectionUtilityTests.cs @@ -103,7 +103,7 @@ public DummyAAttribute(string foo) } [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = false)] - public class DummySingleAAttribute : Attribute + public sealed class DummySingleAAttribute : Attribute { public DummySingleAAttribute(string foo) { diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10ReflectionOperationsTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10ReflectionOperationsTests.cs index 4c9bdd038c..e519882055 100644 --- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10ReflectionOperationsTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10ReflectionOperationsTests.cs @@ -233,7 +233,7 @@ private string[] GetAttributeValuePairs(object[] attributes) } [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true)] - public class DummyAAttribute : Attribute + public sealed class DummyAAttribute : Attribute { public DummyAAttribute(string foo) { @@ -244,7 +244,7 @@ public DummyAAttribute(string foo) } [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = false)] - public class DummySingleAAttribute : Attribute + public sealed class DummySingleAAttribute : Attribute { public DummySingleAAttribute(string foo) { diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Utilities/ns13ReflectionUtilityTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Utilities/ns13ReflectionUtilityTests.cs index 918214b735..bde4a52cef 100644 --- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Utilities/ns13ReflectionUtilityTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Utilities/ns13ReflectionUtilityTests.cs @@ -261,7 +261,7 @@ public DummyAAttribute(string foo) } [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = false)] - public class DummySingleAAttribute : Attribute + public sealed class DummySingleAAttribute : Attribute { public DummySingleAAttribute(string foo) { From bcec9b52bb69e0a72533a6599d1cfc954bea8fd2 Mon Sep 17 00:00:00 2001 From: Maximilian Chaplin Date: Thu, 12 Mar 2020 16:21:19 +0100 Subject: [PATCH 23/24] Revert "IDE0034 'default' expression can be simplified." This reverts commit 862549c593cda61ba8bbf6b95c0dcfd9bbea72b2. --- .../Execution/TcmTestPropertiesProvider.cs | 32 +++++++++---------- .../Execution/ThreadSafeStringWriter.cs | 2 +- .../Helpers/RunSettingsUtilities.cs | 2 +- .../Execution/TestExecutionManagerTests.cs | 2 +- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/Adapter/MSTest.CoreAdapter/Execution/TcmTestPropertiesProvider.cs b/src/Adapter/MSTest.CoreAdapter/Execution/TcmTestPropertiesProvider.cs index 6448b75cae..7973da7a8c 100644 --- a/src/Adapter/MSTest.CoreAdapter/Execution/TcmTestPropertiesProvider.cs +++ b/src/Adapter/MSTest.CoreAdapter/Execution/TcmTestPropertiesProvider.cs @@ -22,29 +22,29 @@ internal static class TcmTestPropertiesProvider // Return empty properties when testCase is null or when test case id is zero. if (testCase == null || - testCase.GetPropertyValue(Constants.TestCaseIdProperty, default) == 0) + testCase.GetPropertyValue(Constants.TestCaseIdProperty, default(int)) == 0) { return tcmProperties; } // Step 1: Add common properties. - tcmProperties[Constants.TestRunIdProperty] = testCase.GetPropertyValue(Constants.TestRunIdProperty, default); - tcmProperties[Constants.TestPlanIdProperty] = testCase.GetPropertyValue(Constants.TestPlanIdProperty, default); - tcmProperties[Constants.BuildConfigurationIdProperty] = testCase.GetPropertyValue(Constants.BuildConfigurationIdProperty, default); - tcmProperties[Constants.BuildDirectoryProperty] = testCase.GetPropertyValue(Constants.BuildDirectoryProperty, default); - tcmProperties[Constants.BuildFlavorProperty] = testCase.GetPropertyValue(Constants.BuildFlavorProperty, default); - tcmProperties[Constants.BuildNumberProperty] = testCase.GetPropertyValue(Constants.BuildNumberProperty, default); - tcmProperties[Constants.BuildPlatformProperty] = testCase.GetPropertyValue(Constants.BuildPlatformProperty, default); - tcmProperties[Constants.BuildUriProperty] = testCase.GetPropertyValue(Constants.BuildUriProperty, default); - tcmProperties[Constants.TfsServerCollectionUrlProperty] = testCase.GetPropertyValue(Constants.TfsServerCollectionUrlProperty, default); - tcmProperties[Constants.TfsTeamProjectProperty] = testCase.GetPropertyValue(Constants.TfsTeamProjectProperty, default); - tcmProperties[Constants.IsInLabEnvironmentProperty] = testCase.GetPropertyValue(Constants.IsInLabEnvironmentProperty, default); + tcmProperties[Constants.TestRunIdProperty] = testCase.GetPropertyValue(Constants.TestRunIdProperty, default(int)); + tcmProperties[Constants.TestPlanIdProperty] = testCase.GetPropertyValue(Constants.TestPlanIdProperty, default(int)); + tcmProperties[Constants.BuildConfigurationIdProperty] = testCase.GetPropertyValue(Constants.BuildConfigurationIdProperty, default(int)); + tcmProperties[Constants.BuildDirectoryProperty] = testCase.GetPropertyValue(Constants.BuildDirectoryProperty, default(string)); + tcmProperties[Constants.BuildFlavorProperty] = testCase.GetPropertyValue(Constants.BuildFlavorProperty, default(string)); + tcmProperties[Constants.BuildNumberProperty] = testCase.GetPropertyValue(Constants.BuildNumberProperty, default(string)); + tcmProperties[Constants.BuildPlatformProperty] = testCase.GetPropertyValue(Constants.BuildPlatformProperty, default(string)); + tcmProperties[Constants.BuildUriProperty] = testCase.GetPropertyValue(Constants.BuildUriProperty, default(string)); + tcmProperties[Constants.TfsServerCollectionUrlProperty] = testCase.GetPropertyValue(Constants.TfsServerCollectionUrlProperty, default(string)); + tcmProperties[Constants.TfsTeamProjectProperty] = testCase.GetPropertyValue(Constants.TfsTeamProjectProperty, default(string)); + tcmProperties[Constants.IsInLabEnvironmentProperty] = testCase.GetPropertyValue(Constants.IsInLabEnvironmentProperty, default(bool)); // Step 2: Add test case specific properties. - tcmProperties[Constants.TestCaseIdProperty] = testCase.GetPropertyValue(Constants.TestCaseIdProperty, default); - tcmProperties[Constants.TestConfigurationIdProperty] = testCase.GetPropertyValue(Constants.TestConfigurationIdProperty, default); - tcmProperties[Constants.TestConfigurationNameProperty] = testCase.GetPropertyValue(Constants.TestConfigurationNameProperty, default); - tcmProperties[Constants.TestPointIdProperty] = testCase.GetPropertyValue(Constants.TestPointIdProperty, default); + tcmProperties[Constants.TestCaseIdProperty] = testCase.GetPropertyValue(Constants.TestCaseIdProperty, default(int)); + tcmProperties[Constants.TestConfigurationIdProperty] = testCase.GetPropertyValue(Constants.TestConfigurationIdProperty, default(int)); + tcmProperties[Constants.TestConfigurationNameProperty] = testCase.GetPropertyValue(Constants.TestConfigurationNameProperty, default(string)); + tcmProperties[Constants.TestPointIdProperty] = testCase.GetPropertyValue(Constants.TestPointIdProperty, default(int)); return tcmProperties; } diff --git a/src/Adapter/MSTest.CoreAdapter/Execution/ThreadSafeStringWriter.cs b/src/Adapter/MSTest.CoreAdapter/Execution/ThreadSafeStringWriter.cs index 1f88f79efd..cf170daf29 100644 --- a/src/Adapter/MSTest.CoreAdapter/Execution/ThreadSafeStringWriter.cs +++ b/src/Adapter/MSTest.CoreAdapter/Execution/ThreadSafeStringWriter.cs @@ -35,7 +35,7 @@ public override string ToString() } catch (ObjectDisposedException) { - return default; + return default(string); } } } diff --git a/src/Adapter/MSTest.CoreAdapter/Helpers/RunSettingsUtilities.cs b/src/Adapter/MSTest.CoreAdapter/Helpers/RunSettingsUtilities.cs index d7e0b2ddee..d059726135 100644 --- a/src/Adapter/MSTest.CoreAdapter/Helpers/RunSettingsUtilities.cs +++ b/src/Adapter/MSTest.CoreAdapter/Helpers/RunSettingsUtilities.cs @@ -97,7 +97,7 @@ private static T GetNodeValue(string settingsXml, string nodeName, Func Date: Fri, 13 Mar 2020 11:28:09 +0100 Subject: [PATCH 24/24] fix GetResultFiles() --- .../Services/DesktopTestContextImplementation.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestContextImplementation.cs b/src/Adapter/PlatformServices.Desktop/Services/DesktopTestContextImplementation.cs index 373058fb6d..9593f72f2e 100644 --- a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestContextImplementation.cs +++ b/src/Adapter/PlatformServices.Desktop/Services/DesktopTestContextImplementation.cs @@ -407,7 +407,7 @@ public void AddProperty(string propertyName, string propertyValue) /// Results files generated in run. public IList GetResultFiles() { - if (this.testResultFiles.Any()) + if (!this.testResultFiles.Any()) { return null; }