diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/AcceptanceTestBase.cs b/test/Microsoft.TestPlatform.AcceptanceTests/AcceptanceTestBase.cs index df3e032d98..7bacc1b8ac 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/AcceptanceTestBase.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/AcceptanceTestBase.cs @@ -7,8 +7,6 @@ using Microsoft.TestPlatform.TestUtilities; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests; public class AcceptanceTestBase : IntegrationTestBase @@ -76,10 +74,10 @@ protected static void SetTestEnvironment(IntegrationTestEnvironment testEnvironm { testEnvironment.VSTestConsoleInfo = runnerInfo.VSTestConsoleInfo; // The order here matters, it changes how the resulting path is built when we resolve test dlls and other assets. - testEnvironment.DllInfos = new[] { runnerInfo.AdapterInfo, runnerInfo.TestHostInfo }.Where(d => d != null).ToList(); + testEnvironment.DllInfos = new[] { runnerInfo.AdapterInfo, runnerInfo.TestHostInfo }.Where(d => d != null).Select(x => x!).ToList(); testEnvironment.DebugInfo = runnerInfo.DebugInfo; - testEnvironment.RunnerFramework = runnerInfo.RunnerFramework; + testEnvironment.RunnerFramework = runnerInfo.RunnerFramework!; testEnvironment.TargetFramework = runnerInfo.TargetFramework; testEnvironment.InIsolationValue = runnerInfo.InIsolationValue; } diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/AppDomainTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/AppDomainTests.cs index 17e8f88423..0a19709466 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/AppDomainTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/AppDomainTests.cs @@ -6,16 +6,12 @@ using System.IO; #if !NETFRAMEWORK using System.Runtime.Loader; - #else using System.Reflection; - #endif using Microsoft.TestPlatform.TestUtilities; using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests; [TestClass] @@ -46,7 +42,7 @@ public void RunTestExecutionWithDisableAppDomain(RunnerInfo runnerInfo) TempDirectory.Path); // Sets the environment variables used by the test project and test data collector. - var env = new Dictionary + var env = new Dictionary { ["TEST_ASSET_APPDOMAIN_TEST_PATH"] = testAppDomainDetailFileName, ["TEST_ASSET_APPDOMAIN_COLLECTOR_PATH"] = dataCollectorAppDomainDetailFileName, diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/ArgumentProcessorTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/ArgumentProcessorTests.cs index 44a4a39dbd..ad0641ea10 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/ArgumentProcessorTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/ArgumentProcessorTests.cs @@ -3,8 +3,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests; [TestClass] diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/BlameDataCollectorTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/BlameDataCollectorTests.cs index f740998847..9c3ff9b08d 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/BlameDataCollectorTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/BlameDataCollectorTests.cs @@ -12,8 +12,6 @@ using Microsoft.TestPlatform.TestUtilities; using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests; [TestClass] @@ -70,7 +68,7 @@ public void BlameDataCollectorShouldOutputDumpFile(RunnerInfo runnerInfo) arguments = string.Concat(arguments, $" /ResultsDirectory:{TempDirectory.Path}"); arguments = string.Concat(arguments, " /testcasefilter:ExitWithStackoverFlow"); - var env = new Dictionary + var env = new Dictionary { ["PROCDUMP_PATH"] = _procDumpPath, }; @@ -95,7 +93,7 @@ public void BlameDataCollectorShouldNotOutputDumpFileWhenNoCrashOccurs(RunnerInf arguments = string.Concat(arguments, $" /ResultsDirectory:{TempDirectory.Path}"); arguments = string.Concat(arguments, " /testcasefilter:PassingTest"); - var env = new Dictionary + var env = new Dictionary { ["PROCDUMP_PATH"] = _procDumpPath }; @@ -120,7 +118,7 @@ public void BlameDataCollectorShouldOutputDumpFileWhenNoCrashOccursButCollectAlw arguments = string.Concat(arguments, $" /ResultsDirectory:{TempDirectory.Path}"); arguments = string.Concat(arguments, " /testcasefilter:PassingTest"); - var env = new Dictionary + var env = new Dictionary { ["PROCDUMP_PATH"] = _procDumpPath }; @@ -142,7 +140,7 @@ public void HangDumpOnTimeout(RunnerInfo runnerInfo) arguments = string.Concat(arguments, $" /ResultsDirectory:{TempDirectory.Path}"); arguments = string.Concat(arguments, $@" /Blame:""CollectHangDump;HangDumpType=full;TestTimeout=3s"""); - var env = new Dictionary + var env = new Dictionary { ["PROCDUMP_PATH"] = _procDumpPath }; @@ -166,7 +164,7 @@ public void CrashDumpWhenThereIsNoTimeout(RunnerInfo runnerInfo) arguments = string.Concat(arguments, $" /ResultsDirectory:{TempDirectory.Path}"); arguments = string.Concat(arguments, $@" /Blame:""CollectDump;DumpType=full;CollectAlways=true;CollectHangDump"""); - var env = new Dictionary + var env = new Dictionary { ["PROCDUMP_PATH"] = _procDumpPath }; @@ -190,7 +188,7 @@ public void CrashDumpOnExit(RunnerInfo runnerInfo) arguments = string.Concat(arguments, $" /ResultsDirectory:{TempDirectory.Path}"); arguments = string.Concat(arguments, $@" /Blame:""CollectDump;DumpType=full;CollectAlways=true"""); - var env = new Dictionary + var env = new Dictionary { ["PROCDUMP_PATH"] = _procDumpPath }; @@ -212,7 +210,7 @@ public void CrashDumpOnStackOverflow(RunnerInfo runnerInfo) arguments = string.Concat(arguments, $" /ResultsDirectory:{TempDirectory.Path}"); arguments = string.Concat(arguments, $@" /Blame:""CollectDump;DumpType=full"""); - var env = new Dictionary + var env = new Dictionary { ["PROCDUMP_PATH"] = _procDumpPath }; diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/CUITTest.cs b/test/Microsoft.TestPlatform.AcceptanceTests/CUITTest.cs index 682ac1812a..87e23f5397 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/CUITTest.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/CUITTest.cs @@ -4,8 +4,6 @@ using Microsoft.TestPlatform.TestUtilities; using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests; [TestClass] diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/CodeCoverageAcceptanceTestBase.cs b/test/Microsoft.TestPlatform.AcceptanceTests/CodeCoverageAcceptanceTestBase.cs index 2081de653b..acae8026dc 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/CodeCoverageAcceptanceTestBase.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/CodeCoverageAcceptanceTestBase.cs @@ -10,8 +10,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests; public class CodeCoverageAcceptanceTestBase : AcceptanceTestBase @@ -37,7 +35,7 @@ protected string GetCodeCoverageExePath() return Path.Combine(GetNetStandardAdapterPath(), "CodeCoverage", "CodeCoverage.exe"); } - protected XmlNode GetModuleNode(XmlNode node, string name) + protected XmlNode? GetModuleNode(XmlNode node, string name) { var moduleNode = GetNode(node, "module", name); @@ -54,7 +52,7 @@ protected XmlNode GetModuleNode(XmlNode node, string name) return moduleNode; } - protected XmlNode GetNode(XmlNode node, string type, string name) + protected XmlNode? GetNode(XmlNode node, string type, string name) { return node.SelectSingleNode($"//{type}[@name='{name}']") ?? node.SelectSingleNode($"//{type}[@name='{name.ToLower()}']"); } @@ -84,7 +82,7 @@ protected XmlDocument GetXmlCoverage(string coverageResult, TempDirectory tempDi UseShellExecute = false }); - string analysisOutput = analyze.StandardOutput.ReadToEnd(); + string analysisOutput = analyze!.StandardOutput.ReadToEnd(); analyze.WaitForExit(); watch.Stop(); @@ -98,11 +96,11 @@ protected XmlDocument GetXmlCoverage(string coverageResult, TempDirectory tempDi protected void AssertCoverage(XmlNode node, double expectedCoverage) { - var coverage = node.Attributes["block_coverage"] != null - ? double.Parse(node.Attributes["block_coverage"].Value) - : double.Parse(node.Attributes["line-rate"].Value) * 100; - Console.WriteLine($"Checking coverage for {node.Name} {node.Attributes["name"].Value}. Expected at least: {expectedCoverage}. Result: {coverage}"); - Assert.IsTrue(coverage > expectedCoverage, $"Coverage check failed for {node.Name} {node.Attributes["name"].Value}. Expected at least: {expectedCoverage}. Found: {coverage}"); + var coverage = node.Attributes!["block_coverage"] != null + ? double.Parse(node.Attributes!["block_coverage"]!.Value) + : double.Parse(node.Attributes!["line-rate"]!.Value) * 100; + Console.WriteLine($"Checking coverage for {node.Name} {node.Attributes!["name"]!.Value}. Expected at least: {expectedCoverage}. Result: {coverage}"); + Assert.IsTrue(coverage > expectedCoverage, $"Coverage check failed for {node.Name} {node.Attributes!["name"]!.Value}. Expected at least: {expectedCoverage}. Found: {coverage}"); } protected static string GetCoverageFileNameFromTrx(string trxFilePath, string resultsDirectory) @@ -114,18 +112,18 @@ protected static string GetCoverageFileNameFromTrx(string trxFilePath, string re var deploymentElements = doc.GetElementsByTagName("Deployment"); Assert.IsTrue(deploymentElements.Count == 1, "None or more than one Deployment tags found in trx file:{0}", trxFilePath); - var deploymentDir = deploymentElements[0].Attributes.GetNamedItem("runDeploymentRoot")?.Value; + var deploymentDir = deploymentElements[0]!.Attributes!.GetNamedItem("runDeploymentRoot")?.Value; Assert.IsTrue(string.IsNullOrEmpty(deploymentDir) == false, "runDeploymentRoot attribute not found in trx file:{0}", trxFilePath); var collectors = doc.GetElementsByTagName("Collector"); - string fileName = string.Empty; + string? fileName = string.Empty; for (int i = 0; i < collectors.Count; i++) { - if (string.Equals(collectors[i].Attributes.GetNamedItem("collectorDisplayName").Value, + if (string.Equals(collectors[i]!.Attributes!.GetNamedItem("collectorDisplayName")!.Value, "Code Coverage", StringComparison.OrdinalIgnoreCase)) { - fileName = collectors[i].FirstChild?.FirstChild?.FirstChild?.Attributes.GetNamedItem("href") + fileName = collectors[i]?.FirstChild?.FirstChild?.FirstChild?.Attributes?.GetNamedItem("href") ?.Value; } } diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/CodeCoverageTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/CodeCoverageTests.cs index b426fc7fd1..19468e57ba 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/CodeCoverageTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/CodeCoverageTests.cs @@ -9,8 +9,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests; internal struct TestParameters @@ -305,19 +303,19 @@ private string CreateArguments( private void AssertSkippedMethod(XmlDocument document) { - var module = GetModuleNode(document.DocumentElement, "codecoveragetest.dll"); + var module = GetModuleNode(document.DocumentElement!, "codecoveragetest.dll"); Assert.IsNotNull(module); - var coverage = double.Parse(module.Attributes["block_coverage"].Value); + var coverage = double.Parse(module.Attributes!["block_coverage"]!.Value); Assert.IsTrue(coverage > ExpectedMinimalModuleCoverage); var testSignFunction = GetNode(module, "skipped_function", "TestSign()"); Assert.IsNotNull(testSignFunction); - Assert.AreEqual("name_excluded", testSignFunction.Attributes["reason"].Value); + Assert.AreEqual("name_excluded", testSignFunction.Attributes!["reason"]!.Value); var skippedTestMethod = GetNode(module, "skipped_function", "__CxxPureMSILEntry_Test()"); Assert.IsNotNull(skippedTestMethod); - Assert.AreEqual("name_excluded", skippedTestMethod.Attributes["reason"].Value); + Assert.AreEqual("name_excluded", skippedTestMethod.Attributes!["reason"]!.Value); var testAbsFunction = GetNode(module, "function", "TestAbs()"); Assert.IsNotNull(testAbsFunction); @@ -325,11 +323,11 @@ private void AssertSkippedMethod(XmlDocument document) private void ValidateCoverageData(XmlDocument document, string moduleName, bool validateSourceFileNames) { - var module = GetModuleNode(document.DocumentElement, moduleName.ToLower()); + var module = GetModuleNode(document.DocumentElement!, moduleName.ToLower()); if (module == null) { - module = GetModuleNode(document.DocumentElement, moduleName); + module = GetModuleNode(document.DocumentElement!, moduleName); } Assert.IsNotNull(module); @@ -348,9 +346,9 @@ private void AssertSourceFileName(XmlNode module) var found = false; var sourcesNode = module.SelectSingleNode("./source_files"); - foreach (XmlNode node in sourcesNode.ChildNodes) + foreach (XmlNode node in sourcesNode!.ChildNodes) { - if (node.Attributes["path"].Value.Contains(expectedFileName)) + if (node.Attributes!["path"]!.Value.Contains(expectedFileName)) { found = true; break; diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/DataCollectionTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/DataCollectionTests.cs index a600a7bf0c..35e314a2b5 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/DataCollectionTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/DataCollectionTests.cs @@ -14,8 +14,6 @@ using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers; using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests; [TestClass] @@ -40,7 +38,7 @@ public void ExecuteTestsWithDataCollection(RunnerInfo runnerInfo) var arguments = PrepareArguments(assemblyPaths, null, runSettings, FrameworkArgValue, runnerInfo.InIsolationValue, resultsDirectory: TempDirectory.Path); arguments = string.Concat(arguments, $" /Diag:{diagFileName}", $" /TestAdapterPath:{extensionsPath}"); - var env = new Dictionary + var env = new Dictionary { ["TEST_ASSET_SAMPLE_COLLECTOR_PATH"] = TempDirectory.Path, }; @@ -70,7 +68,7 @@ public void ExecuteTestsWithDataCollectionUsingCollectArgument(RunnerInfo runner var arguments = PrepareArguments(assemblyPaths, null, null, FrameworkArgValue, runnerInfo.InIsolationValue, TempDirectory.Path); arguments = string.Concat(arguments, $" /Diag:{diagFileName}", $" /Collect:SampleDataCollector", $" /TestAdapterPath:{extensionsPath}"); - var env = new Dictionary + var env = new Dictionary { ["TEST_ASSET_SAMPLE_COLLECTOR_PATH"] = TempDirectory.Path, }; @@ -135,13 +133,13 @@ public void DataCollectorAttachmentProcessor(RunnerInfo runnerInfo) runSettingsXml.Add(new XElement("RunConfiguration", new XElement("MaxCpuCount", 2))); // Set datacollector parameters - runSettingsXml.Element("DataCollectionRunSettings") - .Element("DataCollectors") - .Element("DataCollector") + runSettingsXml.Element("DataCollectionRunSettings")! + .Element("DataCollectors")! + .Element("DataCollector")! .Add(new XElement("Configuration", new XElement("MergeFile", "MergedFile.txt"))); runSettingsXml.Save(runSettings); - var env = new Dictionary + var env = new Dictionary { ["SampleDataCollectorTempPath"] = TempDirectory.Path, }; @@ -156,8 +154,8 @@ public void DataCollectorAttachmentProcessor(RunnerInfo runnerInfo) { while (!streamReader.EndOfStream) { - string line = streamReader.ReadLine(); - Assert.IsTrue(line.StartsWith("SessionEnded_Handler_")); + string? line = streamReader.ReadLine(); + Assert.IsTrue(line!.StartsWith("SessionEnded_Handler_")); fileContent.Add(line); } } diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/DebugAssertTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/DebugAssertTests.cs index a03280f37c..7db7ead909 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/DebugAssertTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/DebugAssertTests.cs @@ -4,8 +4,6 @@ using Microsoft.TestPlatform.TestUtilities; using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests; [TestClass] diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/DeprecateExtensionsPathWarningTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/DeprecateExtensionsPathWarningTests.cs index 4c10549775..f64f6cf1d5 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/DeprecateExtensionsPathWarningTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/DeprecateExtensionsPathWarningTests.cs @@ -9,16 +9,14 @@ using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions; using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests; [TestClass] [TestCategory("Windows-Review")] public class DeprecateExtensionsPathWarningTests : AcceptanceTestBase { - private IList _adapterDependencies; - private IList _copiedFiles; + private readonly IList _adapterDependencies; + private readonly IList _copiedFiles; [TestCleanup] public void Cleanup() @@ -36,11 +34,10 @@ public void Cleanup() } } - [TestInitialize] - public void CopyAdapterToExtensions() + public DeprecateExtensionsPathWarningTests() { _copiedFiles = new List(); - var extensionsDir = Path.Combine(Path.GetDirectoryName(GetConsoleRunnerPath()), "Extensions"); + var extensionsDir = Path.Combine(Path.GetDirectoryName(GetConsoleRunnerPath())!, "Extensions"); _adapterDependencies = Directory.GetFiles(GetTestAdapterPath(), "*.dll", SearchOption.TopDirectoryOnly); try @@ -69,7 +66,7 @@ public void VerifyDeprecatedWarningIsThrownWhenAdaptersPickedFromExtensionDirect public override string GetConsoleRunnerPath() { - DirectoryInfo currentDirectory = new DirectoryInfo(typeof(DeprecateExtensionsPathWarningTests).GetTypeInfo().Assembly.GetAssemblyLocation()).Parent.Parent.Parent.Parent.Parent.Parent; + DirectoryInfo currentDirectory = new DirectoryInfo(typeof(DeprecateExtensionsPathWarningTests).GetTypeInfo().Assembly.GetAssemblyLocation()).Parent!.Parent!.Parent!.Parent!.Parent!.Parent!; return Path.Combine(currentDirectory.FullName, "artifacts", BuildConfiguration, "net451", "win7-x64", "vstest.console.exe"); } diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/DifferentTestFrameworkSimpleTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/DifferentTestFrameworkSimpleTests.cs index 70de29e59c..2a543b508b 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/DifferentTestFrameworkSimpleTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/DifferentTestFrameworkSimpleTests.cs @@ -7,8 +7,6 @@ using Microsoft.TestPlatform.TestUtilities; using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests; [TestClass] diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/DisableAppdomainTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/DisableAppdomainTests.cs index 4136000193..d2b585137f 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/DisableAppdomainTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/DisableAppdomainTests.cs @@ -8,8 +8,6 @@ using Microsoft.TestPlatform.TestUtilities; using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests; [TestClass] diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/DiscoveryTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/DiscoveryTests.cs index fa9bb8627b..d36cc8594e 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/DiscoveryTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/DiscoveryTests.cs @@ -11,8 +11,6 @@ using Microsoft.VisualStudio.TestPlatform.Common.Utilities; using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests; [TestClass] diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/DotnetArchitectureSwitchTests.Windows.cs b/test/Microsoft.TestPlatform.AcceptanceTests/DotnetArchitectureSwitchTests.Windows.cs index fdaa3a45b7..5151f2ef0c 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/DotnetArchitectureSwitchTests.Windows.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/DotnetArchitectureSwitchTests.Windows.cs @@ -11,8 +11,6 @@ using Newtonsoft.Json.Linq; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests; [TestClass] @@ -29,7 +27,7 @@ public void Use_EnvironmentVariables(string architectureFrom, string architectur string dotnetPathTo = GetDownloadedDotnetMuxerFromTools(architectureTo); var vstestConsolePath = GetDotnetRunnerPath(); var dotnetRunnerPath = TempDirectory.CreateDirectory("dotnetrunner"); - TempDirectory.CopyDirectory(new DirectoryInfo(Path.GetDirectoryName(vstestConsolePath)), dotnetRunnerPath); + TempDirectory.CopyDirectory(new DirectoryInfo(Path.GetDirectoryName(vstestConsolePath)!), dotnetRunnerPath); // Patch the runner string sdkVersion = GetLatestSdkVersion(dotnetPath); @@ -38,10 +36,10 @@ public void Use_EnvironmentVariables(string architectureFrom, string architectur patchRuntimeConfig["runtimeOptions"]["framework"]["version"] = sdkVersion; File.WriteAllText(runtimeConfigFile, patchRuntimeConfig.ToString()); - var environmentVariables = new Dictionary + var environmentVariables = new Dictionary { ["DOTNET_MULTILEVEL_LOOKUP"] = "0", - [$"DOTNET_ROOT_{architectureTo}"] = Path.GetDirectoryName(dotnetPathTo), + [$"DOTNET_ROOT_{architectureTo}"] = Path.GetDirectoryName(dotnetPathTo)!, ["ExpectedArchitecture"] = architectureTo }; ExecuteApplication(dotnetPath, "new mstest", out _, out string _, out _, environmentVariables, TempDirectory.Path); @@ -69,7 +67,7 @@ public void TestMethod1() ExecuteApplication(dotnetPath, $"test -p:VsTestConsolePath=\"{Path.Combine(dotnetRunnerPath.FullName, Path.GetFileName(vstestConsolePath))}\" --arch {architectureTo.ToLower()} --diag:log.txt", out string stdOut, out _, out int exitCode, environmentVariables, TempDirectory.Path); Assert.AreEqual(0, exitCode, stdOut); - environmentVariables = new Dictionary + environmentVariables = new Dictionary { ["DOTNET_MULTILEVEL_LOOKUP"] = "0", ["DOTNET_ROOT"] = Path.GetDirectoryName(dotnetPathTo), @@ -78,7 +76,7 @@ public void TestMethod1() ExecuteApplication(dotnetPath, $"test -p:VsTestConsolePath=\"{Path.Combine(dotnetRunnerPath.FullName, Path.GetFileName(vstestConsolePath))}\" --arch {architectureTo.ToLower()} --diag:log.txt", out stdOut, out _, out exitCode, environmentVariables, TempDirectory.Path); Assert.AreEqual(0, exitCode, stdOut); - environmentVariables = new Dictionary + environmentVariables = new Dictionary { ["DOTNET_MULTILEVEL_LOOKUP"] = "0", [$"DOTNET_ROOT_{architectureTo}"] = Path.GetDirectoryName(dotnetPathTo), @@ -90,7 +88,7 @@ public void TestMethod1() } private string GetLatestSdkVersion(string dotnetPath) - => Path.GetFileName(Directory.GetDirectories(Path.Combine(Path.GetDirectoryName(dotnetPath), @"shared/Microsoft.NETCore.App")).OrderByDescending(x => x).First()); + => Path.GetFileName(Directory.GetDirectories(Path.Combine(Path.GetDirectoryName(dotnetPath)!, @"shared/Microsoft.NETCore.App")).OrderByDescending(x => x).First()); } #endif diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/DotnetArchitectureSwitchTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/DotnetArchitectureSwitchTests.cs index 5ff96f6cd2..a27ac574ba 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/DotnetArchitectureSwitchTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/DotnetArchitectureSwitchTests.cs @@ -12,8 +12,6 @@ using Microsoft.TestPlatform.TestUtilities; using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests; // This tests need specific sdks to be installed on arm machine // >= ARM 6.0.2xx @@ -25,7 +23,7 @@ namespace Microsoft.TestPlatform.AcceptanceTests; [Ignore("Manual tests(for now). Tests in this class need some .NET SDK global installations")] public class DotnetArchitectureSwitchTests : AcceptanceTestBase { - private static string s_privateX64Installation; + private static string s_privateX64Installation = string.Empty; [ClassInitialize] public static void ClassInitialize(TestContext _) @@ -38,7 +36,7 @@ public static void ClassInitialize(TestContext _) public static void ClassCleanup() { // Remove one level up because we are targeting a sub-folder of the temp directory. - TempDirectory.TryRemoveDirectory(new DirectoryInfo(s_privateX64Installation).Parent.FullName); + TempDirectory.TryRemoveDirectory(new DirectoryInfo(s_privateX64Installation).Parent!.FullName); } [TestMethod] @@ -53,7 +51,7 @@ public void GlobalInstallation() var projectPath = GetProjectFullPath(projectName); var projectDirectory = Path.GetDirectoryName(projectPath); - var env = new Dictionary + var env = new Dictionary { { "DOTNET_ROOT", null }, { "DOTNET_MULTILEVEL_LOOKUP", "0" } @@ -107,7 +105,7 @@ public void DOTNET_ROOTS_EnvironmentVariables(bool dotnetRoot, bool dotnetRootX6 return; } - var env = new Dictionary + var env = new Dictionary { ["DOTNET_ROOT"] = null, ["DOTNET_MULTILEVEL_LOOKUP"] = "0" @@ -170,7 +168,7 @@ public void PrivateX64BuildToGlobalArmInstallation() return; } - var env = new Dictionary + var env = new Dictionary { ["DOTNET_ROOT"] = null, ["DOTNET_MULTILEVEL_LOOKUP"] = "0" @@ -214,7 +212,7 @@ public void PrivateX64BuildToDOTNET_ROOTS_EnvironmentVariables(bool dotnetRoot, return; } - var env = new Dictionary + var env = new Dictionary { ["DOTNET_ROOT"] = null, ["DOTNET_MULTILEVEL_LOOKUP"] = "0" @@ -275,7 +273,7 @@ public void SilentlyForceX64() var projectPath = GetProjectFullPath(projectName); var projectDirectory = Path.GetDirectoryName(projectPath); - var env = new Dictionary + var env = new Dictionary { ["DOTNET_ROOT"] = null, ["DOTNET_MULTILEVEL_LOOKUP"] = "0" diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/EventLogCollectorTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/EventLogCollectorTests.cs index 12cee6580a..5f3e4313ad 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/EventLogCollectorTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/EventLogCollectorTests.cs @@ -9,8 +9,6 @@ using Microsoft.TestPlatform.TestUtilities; using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests; [TestClass] diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/ExecutionTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/ExecutionTests.cs index 01cbe7a8c2..0732a5115f 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/ExecutionTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/ExecutionTests.cs @@ -10,8 +10,6 @@ using TestPlatform.TestUtilities; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests; [TestClass] diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/ExecutionThreadApartmentStateTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/ExecutionThreadApartmentStateTests.cs index 7548f73d3f..c60abaa780 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/ExecutionThreadApartmentStateTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/ExecutionThreadApartmentStateTests.cs @@ -4,8 +4,6 @@ using Microsoft.TestPlatform.TestUtilities; using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests; [TestClass] diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/Extension/NetCoreRunner.cs b/test/Microsoft.TestPlatform.AcceptanceTests/Extension/NetCoreRunner.cs index 477715e581..013ccc1be0 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/Extension/NetCoreRunner.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/Extension/NetCoreRunner.cs @@ -11,13 +11,11 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests; /// /// Runs tests using the dotnet vstest.console.dll built against .NET Core 2.1. -/// Provide a list of target frameworks to run the tests from given as a ';' separated list, or using a constant containing that range such as +/// Provide a list of target frameworks to run the tests from given as a ';' separated list, or using a constant containing that range such as /// AcceptanceTestBase.NETFX452_NET50 = "net452;net472;net48;netcoreapp2.1;netcoreapp3.1;net5.0" to determine which target framework of the project /// to test. The target project must list those TFMs in the TargetFrameworks property in csproj. /// diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/Extension/NetCoreTargetFrameworkDataSource.cs b/test/Microsoft.TestPlatform.AcceptanceTests/Extension/NetCoreTargetFrameworkDataSource.cs index a5b51cc79b..dc274c9172 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/Extension/NetCoreTargetFrameworkDataSource.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/Extension/NetCoreTargetFrameworkDataSource.cs @@ -10,8 +10,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests; /// @@ -34,7 +32,7 @@ public class NetCoreTargetFrameworkDataSource : Attribute, ITestDataSource /// To run tests with core runner(dotnet vstest.console.dll) public NetCoreTargetFrameworkDataSource( bool useDesktopRunner = true, - // adding another runner is not necessary until we need to start building against another + // adding another runner is not necessary until we need to start building against another // sdk, because the netcoreapp2.1 executable is forward compatible bool useCoreRunner = true, bool useNetCore21Target = true, diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/Extension/NetFrameworkRunner.cs b/test/Microsoft.TestPlatform.AcceptanceTests/Extension/NetFrameworkRunner.cs index 2d5ceb82a5..aebc4ba3e9 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/Extension/NetFrameworkRunner.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/Extension/NetFrameworkRunner.cs @@ -10,13 +10,11 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests; /// /// Runs tests using the dotnet vstest.console.dll built against .NET Core 2.1. -/// Provide a list of target frameworks to run the tests from given as a ';' separated list, or using a constant containing that range such as +/// Provide a list of target frameworks to run the tests from given as a ';' separated list, or using a constant containing that range such as /// AcceptanceTestBase.NETFX452_NET50 = "net452;net472;net48;netcoreapp2.1;netcoreapp3.1;net5.0" to determine which target framework of the project /// to test. The target project must list those TFMs in the TargetFrameworks property in csproj. /// diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/Extension/NetFullTargetFrameworkDataSource.cs b/test/Microsoft.TestPlatform.AcceptanceTests/Extension/NetFullTargetFrameworkDataSource.cs index c756619ba5..808b48a1aa 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/Extension/NetFullTargetFrameworkDataSource.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/Extension/NetFullTargetFrameworkDataSource.cs @@ -10,8 +10,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests; /// diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/Extension/RunnnerInfo.cs b/test/Microsoft.TestPlatform.AcceptanceTests/Extension/RunnnerInfo.cs index f55cbc80fb..a13fbf2274 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/Extension/RunnnerInfo.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/Extension/RunnnerInfo.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; +using System.Diagnostics.CodeAnalysis; using System.Linq; using Microsoft.TestPlatform.TestUtilities; @@ -18,8 +19,10 @@ namespace Microsoft.TestPlatform.AcceptanceTests; public class RunnerInfo { public int Index { get; set; } + [NotNull] // Marking as NotNull because normal usage ensure this is not null and this helps avoiding bangs everywhere in the tests public string? RunnerFramework { get; set; } public VSTestConsoleInfo? VSTestConsoleInfo { get; set; } + [NotNull] // Marking as NotNull because normal usage ensure this is not null and this helps avoiding bangs everywhere in the tests public string? TargetFramework { get; set; } public string? InIsolationValue { get; set; } public DebugInfo? DebugInfo { get; set; } diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/FilePatternParserTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/FilePatternParserTests.cs index 3d8f36218b..04ba1df6eb 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/FilePatternParserTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/FilePatternParserTests.cs @@ -6,8 +6,6 @@ using Microsoft.TestPlatform.TestUtilities; using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests; [TestClass] @@ -44,7 +42,7 @@ public void WildCardPatternShouldCorrectlyWorkOnArbitraryDepthDirectories(Runner // Add one more directory to the temp path, so we can substitute it with ** // and copy then whole directory there. - TempDirectory.CopyDirectory(Path.GetDirectoryName(testAssembly), Path.Combine(TempDirectory.Path, "dir1")); + TempDirectory.CopyDirectory(Path.GetDirectoryName(testAssembly)!, Path.Combine(TempDirectory.Path, "dir1")); // The path will end up looking like \**\"*TestProj*.dll". var wildcardedPath = Path.Combine(TempDirectory.Path, "**", "*TestProj*.dll"); diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/FrameworkTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/FrameworkTests.cs index 452c60510b..ae90d73121 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/FrameworkTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/FrameworkTests.cs @@ -4,8 +4,6 @@ using Microsoft.TestPlatform.TestUtilities; using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests; [TestClass] diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/ListExtensionsTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/ListExtensionsTests.cs index 1db83bff4b..2b03d2126a 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/ListExtensionsTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/ListExtensionsTests.cs @@ -3,8 +3,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests; [TestClass] diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/LoggerTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/LoggerTests.cs index f48ba219a2..02d4d89780 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/LoggerTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/LoggerTests.cs @@ -9,8 +9,6 @@ using Microsoft.TestPlatform.TestUtilities; using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests; [TestClass] @@ -137,7 +135,7 @@ public void TrxLoggerResultSummaryOutcomeValueShouldBeFailedIfNoTestsExecutedAnd InvokeVsTest(arguments); - string outcomeValue = GetElementAtributeValueFromTrx(trxFilePath, "ResultSummary", "outcome"); + string? outcomeValue = GetElementAtributeValueFromTrx(trxFilePath, "ResultSummary", "outcome"); Assert.AreEqual("Failed", outcomeValue); } @@ -160,7 +158,7 @@ public void TrxLoggerResultSummaryOutcomeValueShouldNotChangeIfNoTestsExecutedAn InvokeVsTest(arguments); - string outcomeValue = GetElementAtributeValueFromTrx(trxFilePath, "ResultSummary", "outcome"); + string? outcomeValue = GetElementAtributeValueFromTrx(trxFilePath, "ResultSummary", "outcome"); Assert.AreEqual("Completed", outcomeValue); } @@ -199,7 +197,7 @@ private static void IsFileAndContentEqual(string filePath) } } - private static string GetElementAtributeValueFromTrx(string trxFileName, string fieldName, string attributeName) + private static string? GetElementAtributeValueFromTrx(string trxFileName, string fieldName, string attributeName) { using (FileStream file = File.OpenRead(trxFileName)) using (XmlReader reader = XmlReader.Create(file)) diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/MultitargetingTestHostTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/MultitargetingTestHostTests.cs index 70a132de3a..ee16733189 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/MultitargetingTestHostTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/MultitargetingTestHostTests.cs @@ -6,8 +6,6 @@ using Microsoft.TestPlatform.TestUtilities; using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests; [TestClass] @@ -28,7 +26,7 @@ public void TestRunInATesthostThatTargetsTheirChosenNETFramework(RunnerInfo runn // Tell the test project which target framework we are expecting it to run as. // It has this value conditionally compiled, so it can compare it. - var env = new Dictionary + var env = new Dictionary { ["EXPECTED_TARGET_FRAMEWORK"] = runnerInfo.TargetFramework }; diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/PlatformTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/PlatformTests.cs index b149fa2994..ce0d229720 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/PlatformTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/PlatformTests.cs @@ -4,8 +4,6 @@ using Microsoft.TestPlatform.TestUtilities; using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests; [TestClass] diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/PortableNugetPackageTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/PortableNugetPackageTests.cs index d5f227fccf..c43fe60ba4 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/PortableNugetPackageTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/PortableNugetPackageTests.cs @@ -8,14 +8,12 @@ using Microsoft.TestPlatform.TestUtilities; using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests; [TestClass] public class PortableNugetPackageTests : AcceptanceTestBase { - private static string s_portablePackageFolder; + private static string s_portablePackageFolder = string.Empty; [ClassInitialize] public static void ClassInit(TestContext _) diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/SelfContainedAppTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/SelfContainedAppTests.cs index ed5e10fc8b..daf371507c 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/SelfContainedAppTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/SelfContainedAppTests.cs @@ -6,8 +6,6 @@ using Microsoft.TestPlatform.TestUtilities; using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests; [TestClass] diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TelemetryTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TelemetryTests.cs index fdf49097ce..e6d8a0a17b 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TelemetryTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TelemetryTests.cs @@ -10,8 +10,6 @@ using Microsoft.VisualStudio.TestPlatform.Common.Telemetry; using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests; [TestClass] @@ -51,7 +49,7 @@ private void RunTests(RunnerInfo runnerInfo) var assemblyPaths = GetAssetFullPath("SimpleTestProject2.dll"); - var env = new Dictionary + var env = new Dictionary { [LOG_TELEMETRY_PATH] = TempDirectory.Path, [TELEMETRY_OPTEDIN] = "1", @@ -72,7 +70,7 @@ private void DiscoverTests(RunnerInfo runnerInfo) var assemblyPaths = GetAssetFullPath("SimpleTestProject2.dll"); - var env = new Dictionary + var env = new Dictionary { [LOG_TELEMETRY_PATH] = TempDirectory.Path, [TELEMETRY_OPTEDIN] = "1", diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TestCaseFilterTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TestCaseFilterTests.cs index c4363cf825..5175b1b24b 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TestCaseFilterTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TestCaseFilterTests.cs @@ -6,8 +6,6 @@ using Microsoft.TestPlatform.TestUtilities; using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests; [TestClass] @@ -209,7 +207,7 @@ public void DiscoverTmiTestsWithOnlyPropertyValue(RunnerInfo runnerInfo) GetTestAdapterPath(), string.Empty, FrameworkArgValue, runnerInfo.InIsolationValue, resultsDirectory: TempDirectory.Path); - string testSettingsPath = Path.Combine(Path.GetDirectoryName(testAssemblyPath), "MstestV1UnitTestProjectTestSettings.testsettings"); + string testSettingsPath = Path.Combine(Path.GetDirectoryName(testAssemblyPath)!, "MstestV1UnitTestProjectTestSettings.testsettings"); arguments = string.Concat(arguments, " /listtests /TestCaseFilter:PassingTest /settings:", testSettingsPath); InvokeVsTest(arguments); diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TestPlatformNugetPackageTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TestPlatformNugetPackageTests.cs index d3304c795d..e0aac0c9e0 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TestPlatformNugetPackageTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TestPlatformNugetPackageTests.cs @@ -9,22 +9,19 @@ using Microsoft.TestPlatform.TestUtilities; using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests; [TestClass] public class TestPlatformNugetPackageTests : CodeCoverageAcceptanceTestBase { - private static string s_nugetPackageFolder; - private TempDirectory _resultsDirectory; + private static string s_nugetPackageFolder = string.Empty; [ClassInitialize] public static void ClassInit(TestContext _) { var packageLocation = Path.Combine(IntegrationTestEnvironment.TestPlatformRootDirectory, "artifacts", IntegrationTestEnvironment.BuildConfiguration, "packages"); - var nugetPackage = Directory.EnumerateFiles(packageLocation, "Microsoft.TestPlatform.*.nupkg").OrderBy(a => a).FirstOrDefault(); - s_nugetPackageFolder = Path.Combine(new TempDirectory().Path, Path.GetFileNameWithoutExtension(nugetPackage)); + var nugetPackage = Directory.EnumerateFiles(packageLocation, "Microsoft.TestPlatform.*.nupkg").OrderBy(a => a).First(); + s_nugetPackageFolder = Path.Combine(new TempDirectory().Path, Path.GetFileNameWithoutExtension(nugetPackage)!); ZipFile.ExtractToDirectory(nugetPackage, s_nugetPackageFolder); TryMoveDirectory( @@ -44,18 +41,6 @@ public static void ClassCleanup() Directory.Delete(s_nugetPackageFolder, true); } - [TestInitialize] - public void SetUp() - { - _resultsDirectory = TempDirectory; - } - - [TestCleanup] - public void CleanUp() - { - _resultsDirectory.Dispose(); - } - [TestMethod] [TestCategory("Windows-Review")] [NetFullTargetFrameworkDataSource(useCoreRunner: false)] @@ -71,8 +56,8 @@ public void RunMultipleTestAssembliesWithCodeCoverage(RunnerInfo runnerInfo) ExitCodeEquals(1); // failing tests - var actualCoverageFile = GetCoverageFileNameFromTrx(trxFilePath, _resultsDirectory.Path); - Console.WriteLine($@"Coverage file: {actualCoverageFile} Results directory: {_resultsDirectory} trxfile: {trxFilePath}"); + var actualCoverageFile = GetCoverageFileNameFromTrx(trxFilePath, TempDirectory.Path); + Console.WriteLine($@"Coverage file: {actualCoverageFile} Results directory: {TempDirectory} trxfile: {trxFilePath}"); Assert.IsTrue(File.Exists(actualCoverageFile), "Coverage file not found: {0}", actualCoverageFile); } @@ -94,14 +79,14 @@ private string CreateCodeCoverageArguments( string assemblyPaths, out string trxFilePath) { - string diagFileName = Path.Combine(_resultsDirectory.Path, "diaglog.txt"); + string diagFileName = Path.Combine(TempDirectory.Path, "diaglog.txt"); var arguments = PrepareArguments(assemblyPaths, GetTestAdapterPath(), string.Empty, - FrameworkArgValue, runnerInfo.InIsolationValue, resultsDirectory: _resultsDirectory.Path); + FrameworkArgValue, runnerInfo.InIsolationValue, resultsDirectory: TempDirectory.Path); arguments = string.Concat(arguments, $" /Diag:{diagFileName}", $" /EnableCodeCoverage"); - trxFilePath = Path.Combine(_resultsDirectory.Path, Guid.NewGuid() + ".trx"); + trxFilePath = Path.Combine(TempDirectory.Path, Guid.NewGuid() + ".trx"); arguments = string.Concat(arguments, " /logger:trx;logfilename=" + trxFilePath); return arguments; diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs index 0b56578e3f..bf19a566b2 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; using System.Text.RegularExpressions; @@ -17,8 +18,6 @@ using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests.TranslationLayerTests; [TestClass] @@ -26,10 +25,11 @@ namespace Microsoft.TestPlatform.AcceptanceTests.TranslationLayerTests; [TestCategory("Windows-Review")] public class CodeCoverageTests : CodeCoverageAcceptanceTestBase { - private IVsTestConsoleWrapper _vstestConsoleWrapper; - private RunEventHandler _runEventHandler; - private TestRunAttachmentsProcessingEventHandler _testRunAttachmentsProcessingEventHandler; + private IVsTestConsoleWrapper? _vstestConsoleWrapper; + private RunEventHandler? _runEventHandler; + private TestRunAttachmentsProcessingEventHandler? _testRunAttachmentsProcessingEventHandler; + [MemberNotNull(nameof(_vstestConsoleWrapper), nameof(_testRunAttachmentsProcessingEventHandler), nameof(_runEventHandler))] private void Setup() { _vstestConsoleWrapper = GetVsTestConsoleWrapper(); @@ -63,7 +63,7 @@ public void TestRunWithCodeCoverage(RunnerInfo runnerInfo) AssertCoverageResults(_runEventHandler.Attachments); - Assert.AreEqual("324f817a-7420-4e6d-b3c1-143fbed6d855", _runEventHandler.Metrics["VS.TestPlatform.DataCollector.CorProfiler.datacollector://microsoft/CodeCoverage/2.0"]); + Assert.AreEqual("324f817a-7420-4e6d-b3c1-143fbed6d855", _runEventHandler.Metrics!["VS.TestPlatform.DataCollector.CorProfiler.datacollector://microsoft/CodeCoverage/2.0"]); Assert.AreEqual("324f817a-7420-4e6d-b3c1-143fbed6d855", _runEventHandler.Metrics["VS.TestPlatform.DataCollector.CoreClrProfiler.datacollector://microsoft/CodeCoverage/2.0"]); } @@ -87,7 +87,7 @@ public void TestRunWithCodeCoverageUsingClrIe(RunnerInfo runnerInfo) AssertCoverageResults(_runEventHandler.Attachments); - Assert.AreEqual("324f817a-7420-4e6d-b3c1-143fbed6d855", _runEventHandler.Metrics["VS.TestPlatform.DataCollector.CorProfiler.datacollector://microsoft/CodeCoverage/2.0"]); + Assert.AreEqual("324f817a-7420-4e6d-b3c1-143fbed6d855", _runEventHandler.Metrics!["VS.TestPlatform.DataCollector.CorProfiler.datacollector://microsoft/CodeCoverage/2.0"]); Assert.AreEqual("324f817a-7420-4e6d-b3c1-143fbed6d855", _runEventHandler.Metrics["VS.TestPlatform.DataCollector.CoreClrProfiler.datacollector://microsoft/CodeCoverage/2.0"]); } @@ -109,7 +109,7 @@ public void TestRunWithCodeCoverageParallel(RunnerInfo runnerInfo) AssertCoverageResults(_runEventHandler.Attachments); - Assert.AreEqual("324f817a-7420-4e6d-b3c1-143fbed6d855", _runEventHandler.Metrics["VS.TestPlatform.DataCollector.CorProfiler.datacollector://microsoft/CodeCoverage/2.0"]); + Assert.AreEqual("324f817a-7420-4e6d-b3c1-143fbed6d855", _runEventHandler.Metrics!["VS.TestPlatform.DataCollector.CorProfiler.datacollector://microsoft/CodeCoverage/2.0"]); Assert.AreEqual("324f817a-7420-4e6d-b3c1-143fbed6d855", _runEventHandler.Metrics["VS.TestPlatform.DataCollector.CoreClrProfiler.datacollector://microsoft/CodeCoverage/2.0"]); } @@ -153,7 +153,7 @@ await _vstestConsoleWrapper.ProcessTestRunAttachmentsAsync( AssertCoverageResults(_testRunAttachmentsProcessingEventHandler.Attachments); - Assert.IsFalse(_testRunAttachmentsProcessingEventHandler.CompleteArgs.IsCanceled); + Assert.IsFalse(_testRunAttachmentsProcessingEventHandler.CompleteArgs!.IsCanceled); Assert.IsNull(_testRunAttachmentsProcessingEventHandler.CompleteArgs.Error); for (int i = 0; i < _testRunAttachmentsProcessingEventHandler.ProgressArgs.Count; i++) @@ -209,7 +209,7 @@ public async Task TestRunWithCodeCoverageAndAttachmentsProcessingNoMetrics(Runne AssertCoverageResults(_testRunAttachmentsProcessingEventHandler.Attachments); - Assert.IsFalse(_testRunAttachmentsProcessingEventHandler.CompleteArgs.IsCanceled); + Assert.IsFalse(_testRunAttachmentsProcessingEventHandler.CompleteArgs!.IsCanceled); Assert.IsNull(_testRunAttachmentsProcessingEventHandler.CompleteArgs.Error); for (int i = 0; i < _testRunAttachmentsProcessingEventHandler.ProgressArgs.Count; i++) @@ -262,7 +262,7 @@ public async Task TestRunWithCodeCoverageAndAttachmentsProcessingModuleDuplicate AssertCoverageResults(_testRunAttachmentsProcessingEventHandler.Attachments); - Assert.IsFalse(_testRunAttachmentsProcessingEventHandler.CompleteArgs.IsCanceled); + Assert.IsFalse(_testRunAttachmentsProcessingEventHandler.CompleteArgs!.IsCanceled); Assert.IsNull(_testRunAttachmentsProcessingEventHandler.CompleteArgs.Error); for (int i = 0; i < _testRunAttachmentsProcessingEventHandler.ProgressArgs.Count; i++) @@ -319,7 +319,7 @@ public async Task TestRunWithCodeCoverageAndAttachmentsProcessingSameReportForma AssertCoverageResults(_testRunAttachmentsProcessingEventHandler.Attachments); - Assert.IsFalse(_testRunAttachmentsProcessingEventHandler.CompleteArgs.IsCanceled); + Assert.IsFalse(_testRunAttachmentsProcessingEventHandler.CompleteArgs!.IsCanceled); Assert.IsNull(_testRunAttachmentsProcessingEventHandler.CompleteArgs.Error); for (int i = 0; i < _testRunAttachmentsProcessingEventHandler.ProgressArgs.Count; i++) @@ -380,7 +380,7 @@ public async Task TestRunWithCodeCoverageAndAttachmentsProcessingDifferentReport AssertCoverageResults(_testRunAttachmentsProcessingEventHandler.Attachments); - Assert.IsFalse(_testRunAttachmentsProcessingEventHandler.CompleteArgs.IsCanceled); + Assert.IsFalse(_testRunAttachmentsProcessingEventHandler.CompleteArgs!.IsCanceled); Assert.IsNull(_testRunAttachmentsProcessingEventHandler.CompleteArgs.Error); for (int i = 0; i < _testRunAttachmentsProcessingEventHandler.ProgressArgs.Count; i++) @@ -496,7 +496,7 @@ private void AssertCoverageResults(IList attachments) foreach (var project in GetProjects()) { - var moduleNode = GetModuleNode(xmlCoverage.DocumentElement, project); + var moduleNode = GetModuleNode(xmlCoverage.DocumentElement!, project)!; AssertCoverage(moduleNode, ExpectedMinimalModuleCoverage); } } diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CustomTestHostTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CustomTestHostTests.cs index cf1c70891d..d711ef7964 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CustomTestHostTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CustomTestHostTests.cs @@ -13,8 +13,6 @@ using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces; using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests.TranslationLayerTests; /// @@ -23,7 +21,7 @@ namespace Microsoft.TestPlatform.AcceptanceTests.TranslationLayerTests; [TestClass] public class CustomTestHostTests : AcceptanceTestBase { - private IVsTestConsoleWrapper _vstestConsoleWrapper; + private IVsTestConsoleWrapper? _vstestConsoleWrapper; [TestCleanup] public void Cleanup() diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/DifferentTestFrameworkSimpleTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/DifferentTestFrameworkSimpleTests.cs index cfae534f62..cac61c83d7 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/DifferentTestFrameworkSimpleTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/DifferentTestFrameworkSimpleTests.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; @@ -11,8 +12,6 @@ using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests.TranslationLayerTests; /// @@ -21,9 +20,10 @@ namespace Microsoft.TestPlatform.AcceptanceTests.TranslationLayerTests; [TestClass] public class DifferentTestFrameworkSimpleTests : AcceptanceTestBase { - private IVsTestConsoleWrapper _vstestConsoleWrapper; - private RunEventHandler _runEventHandler; + private IVsTestConsoleWrapper? _vstestConsoleWrapper; + private RunEventHandler? _runEventHandler; + [MemberNotNull(nameof(_vstestConsoleWrapper), nameof(_runEventHandler))] private void Setup() { _vstestConsoleWrapper = GetVsTestConsoleWrapper(); @@ -66,11 +66,11 @@ public void RunTestsWithNunitAdapter(RunnerInfo runnerInfo) // Release builds optimize code, hence line numbers are different. if (IntegrationTestEnvironment.BuildConfiguration.StartsWith("release", StringComparison.OrdinalIgnoreCase)) { - Assert.AreEqual(14, testCase.FirstOrDefault().TestCase.LineNumber); + Assert.AreEqual(14, testCase.First().TestCase.LineNumber); } else { - Assert.AreEqual(13, testCase.FirstOrDefault().TestCase.LineNumber); + Assert.AreEqual(13, testCase.First().TestCase.LineNumber); } } @@ -90,7 +90,7 @@ public void RunTestsWithXunitAdapter(RunnerInfo runnerInfo) : _testEnvironment.GetTestAsset("XUTestProject.dll"); var sources = new List { testAssemblyPath }; var testAdapterPath = Directory.EnumerateFiles(GetTestAdapterPath(UnitTestFramework.XUnit), "*.TestAdapter.dll").ToList(); - _vstestConsoleWrapper.InitializeExtensions(new List() { testAdapterPath.FirstOrDefault() }); + _vstestConsoleWrapper.InitializeExtensions(new List() { testAdapterPath.FirstOrDefault() }); _vstestConsoleWrapper.RunTests( sources, @@ -108,11 +108,11 @@ public void RunTestsWithXunitAdapter(RunnerInfo runnerInfo) // Release builds optimize code, hence line numbers are different. if (IntegrationTestEnvironment.BuildConfiguration.StartsWith("release", StringComparison.OrdinalIgnoreCase)) { - Assert.AreEqual(15, testCase.FirstOrDefault().TestCase.LineNumber); + Assert.AreEqual(15, testCase.First().TestCase.LineNumber); } else { - Assert.AreEqual(14, testCase.FirstOrDefault().TestCase.LineNumber); + Assert.AreEqual(14, testCase.First().TestCase.LineNumber); } } @@ -133,7 +133,7 @@ public void RunTestsWithChutzpahAdapter(RunnerInfo runnerInfo) var jsInTemp = TempDirectory.CopyFile(jsSource); var testAdapterPath = Directory.EnumerateFiles(GetTestAdapterPath(UnitTestFramework.Chutzpah), "*.TestAdapter.dll").ToList(); - _vstestConsoleWrapper.InitializeExtensions(new List() { testAdapterPath.FirstOrDefault() }); + _vstestConsoleWrapper.InitializeExtensions(new List() { testAdapterPath.FirstOrDefault() }); _vstestConsoleWrapper.RunTests( new[] { jsInTemp }, @@ -146,6 +146,6 @@ public void RunTestsWithChutzpahAdapter(RunnerInfo runnerInfo) Assert.AreEqual(2, _runEventHandler.TestResults.Count); Assert.AreEqual(1, _runEventHandler.TestResults.Count(t => t.Outcome == TestOutcome.Passed)); Assert.AreEqual(1, _runEventHandler.TestResults.Count(t => t.Outcome == TestOutcome.Failed)); - Assert.AreEqual(1, testCase.FirstOrDefault().TestCase.LineNumber); + Assert.AreEqual(1, testCase.First().TestCase.LineNumber); } } diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/DiscoverTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/DiscoverTests.cs index 3364c3dc9f..0d7902df00 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/DiscoverTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/DiscoverTests.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Threading.Tasks; @@ -18,17 +19,16 @@ using Moq; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests.TranslationLayerTests; [TestClass] public class DiscoverTests : AcceptanceTestBase { - private IVsTestConsoleWrapper _vstestConsoleWrapper; - private DiscoveryEventHandler _discoveryEventHandler; - private DiscoveryEventHandler2 _discoveryEventHandler2; + private IVsTestConsoleWrapper? _vstestConsoleWrapper; + private DiscoveryEventHandler? _discoveryEventHandler; + private DiscoveryEventHandler2? _discoveryEventHandler2; + [MemberNotNull(nameof(_vstestConsoleWrapper), nameof(_discoveryEventHandler), nameof(_discoveryEventHandler2))] public void Setup() { _vstestConsoleWrapper = GetVsTestConsoleWrapper(); @@ -80,7 +80,7 @@ public void DiscoverTestsUsingDiscoveryEventHandler2AndTelemetryOptedOut(RunnerI // Assert. Assert.AreEqual(6, _discoveryEventHandler2.DiscoveredTestCases.Count); - Assert.AreEqual(0, _discoveryEventHandler2.Metrics.Count); + Assert.AreEqual(0, _discoveryEventHandler2.Metrics!.Count); } [TestMethod] @@ -95,7 +95,7 @@ public void DiscoverTestsUsingDiscoveryEventHandler2AndTelemetryOptedIn(RunnerIn // Assert. Assert.AreEqual(6, _discoveryEventHandler2.DiscoveredTestCases.Count); - Assert.IsTrue(_discoveryEventHandler2.Metrics.ContainsKey(TelemetryDataConstants.TargetDevice)); + Assert.IsTrue(_discoveryEventHandler2.Metrics!.ContainsKey(TelemetryDataConstants.TargetDevice)); Assert.IsTrue(_discoveryEventHandler2.Metrics.ContainsKey(TelemetryDataConstants.NumberOfAdapterUsedToDiscoverTests)); Assert.IsTrue(_discoveryEventHandler2.Metrics.ContainsKey(TelemetryDataConstants.TimeTakenInSecByAllAdapters)); Assert.IsTrue(_discoveryEventHandler2.Metrics.ContainsKey(TelemetryDataConstants.TimeTakenInSecForDiscovery)); @@ -178,7 +178,7 @@ public void DisoverTestUsingEventHandler2ShouldContainAllSourcesAsFullyDiscovere eventHandler2); // Assert. - Assert.AreEqual(2, eventHandler2.FullyDiscoveredSources.Count); + Assert.AreEqual(2, eventHandler2.FullyDiscoveredSources!.Count); } [TestMethod] @@ -201,11 +201,11 @@ public void DiscoverTestsUsingSourceNavigation(RunnerInfo runnerInfo) // Release builds optimize code, hence line numbers are different. if (IntegrationTestEnvironment.BuildConfiguration.StartsWith("release", StringComparison.OrdinalIgnoreCase)) { - Assert.AreEqual(25, testCase.FirstOrDefault().LineNumber); + Assert.AreEqual(25, testCase.First().LineNumber); } else { - Assert.AreEqual(24, testCase.FirstOrDefault().LineNumber); + Assert.AreEqual(24, testCase.First().LineNumber); } } diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/DiscoveryEventHandler.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/DiscoveryEventHandler.cs index 5f7b825de2..62e21775d3 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/DiscoveryEventHandler.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/DiscoveryEventHandler.cs @@ -9,8 +9,6 @@ using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests.TranslationLayerTests; /// @@ -73,16 +71,16 @@ public class DiscoveryEventHandler2 : ITestDiscoveryEventsHandler2 /// public List DiscoveredTestCases { get; } - public IList FullyDiscoveredSources { get; private set; } - public IList PartiallyDiscoveredSources { get; private set; } - public IList NotDiscoveredSources { get; private set; } + public IList? FullyDiscoveredSources { get; private set; } + public IList? PartiallyDiscoveredSources { get; private set; } + public IList? NotDiscoveredSources { get; private set; } public List TestMessages; /// /// Gets the metrics. /// - public IDictionary Metrics { get; private set; } + public IDictionary? Metrics { get; private set; } public DiscoveryEventHandler2() { diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/RunEventHandler.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/RunEventHandler.cs index b96f448bfc..c23a89f294 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/RunEventHandler.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/RunEventHandler.cs @@ -9,8 +9,6 @@ using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests.TranslationLayerTests; /// @@ -34,12 +32,12 @@ public class RunEventHandler : ITestRunEventsHandler /// /// Gets the metrics. /// - public IDictionary Metrics { get; private set; } + public IDictionary? Metrics { get; private set; } /// /// Gets the log message. /// - public string LogMessage { get; private set; } + public string? LogMessage { get; private set; } public List Errors { get; set; } diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/TestRunAttachmentsProcessingEventHandler.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/TestRunAttachmentsProcessingEventHandler.cs index 0c6c885f53..bb5fe8e374 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/TestRunAttachmentsProcessingEventHandler.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/TestRunAttachmentsProcessingEventHandler.cs @@ -9,8 +9,6 @@ using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests.TranslationLayerTests; /// @@ -18,14 +16,14 @@ public class TestRunAttachmentsProcessingEventHandler : ITestRunAttachmentsProce { public List Attachments { get; private set; } - public TestRunAttachmentsProcessingCompleteEventArgs CompleteArgs { get; private set; } + public TestRunAttachmentsProcessingCompleteEventArgs? CompleteArgs { get; private set; } public List ProgressArgs { get; private set; } /// /// Gets the log message. /// - public string LogMessage { get; private set; } + public string? LogMessage { get; private set; } public List Errors { get; set; } diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/LiveUnitTestingTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/LiveUnitTestingTests.cs index 0beac2e85c..e7e1d5cd40 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/LiveUnitTestingTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/LiveUnitTestingTests.cs @@ -2,23 +2,23 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests.TranslationLayerTests; [TestClass] public class LiveUnitTestingTests : AcceptanceTestBase { - private IVsTestConsoleWrapper _vstestConsoleWrapper; - private DiscoveryEventHandler _discoveryEventHandler; - private RunEventHandler _runEventHandler; + private IVsTestConsoleWrapper? _vstestConsoleWrapper; + private DiscoveryEventHandler? _discoveryEventHandler; + private RunEventHandler? _runEventHandler; + [MemberNotNull(nameof(_vstestConsoleWrapper), nameof(_discoveryEventHandler), nameof(_runEventHandler))] public void Setup() { _vstestConsoleWrapper = GetVsTestConsoleWrapper(); diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/RunSelectedTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/RunSelectedTests.cs index 73b07981b6..0ac08c4827 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/RunSelectedTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/RunSelectedTests.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces; @@ -10,17 +11,16 @@ using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests.TranslationLayerTests; [TestClass] public class RunSelectedTests : AcceptanceTestBase { - private IVsTestConsoleWrapper _vstestConsoleWrapper; - private RunEventHandler _runEventHandler; - private DiscoveryEventHandler _discoveryEventHandler; + private IVsTestConsoleWrapper? _vstestConsoleWrapper; + private RunEventHandler? _runEventHandler; + private DiscoveryEventHandler? _discoveryEventHandler; + [MemberNotNull(nameof(_vstestConsoleWrapper), nameof(_runEventHandler), nameof(_discoveryEventHandler))] private void Setup() { _vstestConsoleWrapper = GetVsTestConsoleWrapper(); @@ -73,7 +73,7 @@ public void RunSelectedTestsWithTestPlatformOptions(RunnerInfo runnerInfo) // Assert Assert.AreEqual(6, _runEventHandler.TestResults.Count); - Assert.IsTrue(_runEventHandler.Metrics.ContainsKey(TelemetryDataConstants.TargetDevice)); + Assert.IsTrue(_runEventHandler.Metrics!.ContainsKey(TelemetryDataConstants.TargetDevice)); Assert.IsTrue(_runEventHandler.Metrics.ContainsKey(TelemetryDataConstants.TargetFramework)); Assert.IsTrue(_runEventHandler.Metrics.ContainsKey(TelemetryDataConstants.TargetOS)); Assert.IsTrue(_runEventHandler.Metrics.ContainsKey(TelemetryDataConstants.TimeTakenInSecForRun)); diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/RunTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/RunTests.cs index e31da3df04..7210608c65 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/RunTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/RunTests.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Threading; @@ -18,8 +19,6 @@ using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests.TranslationLayerTests; /// @@ -28,9 +27,10 @@ namespace Microsoft.TestPlatform.AcceptanceTests.TranslationLayerTests; [TestClass] public class RunTests : AcceptanceTestBase { - private IVsTestConsoleWrapper _vstestConsoleWrapper; - private RunEventHandler _runEventHandler; + private IVsTestConsoleWrapper? _vstestConsoleWrapper; + private RunEventHandler? _runEventHandler; + [MemberNotNull(nameof(_vstestConsoleWrapper), nameof(_runEventHandler))] private void Setup() { _vstestConsoleWrapper = GetVsTestConsoleWrapper(); @@ -146,7 +146,7 @@ public void RunTestsWithTelemetryOptedIn(RunnerInfo runnerInfo) // Assert Assert.AreEqual(6, _runEventHandler.TestResults.Count); - Assert.IsTrue(_runEventHandler.Metrics.ContainsKey(TelemetryDataConstants.TargetDevice)); + Assert.IsTrue(_runEventHandler.Metrics!.ContainsKey(TelemetryDataConstants.TargetDevice)); Assert.IsTrue(_runEventHandler.Metrics.ContainsKey(TelemetryDataConstants.TargetFramework)); Assert.IsTrue(_runEventHandler.Metrics.ContainsKey(TelemetryDataConstants.TargetOS)); Assert.IsTrue(_runEventHandler.Metrics.ContainsKey(TelemetryDataConstants.TimeTakenInSecForRun)); @@ -170,7 +170,7 @@ public void RunTestsWithTelemetryOptedOut(RunnerInfo runnerInfo) // Assert Assert.AreEqual(6, _runEventHandler.TestResults.Count); - Assert.AreEqual(0, _runEventHandler.Metrics.Count); + Assert.AreEqual(0, _runEventHandler.Metrics!.Count); } [TestMethod] diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/RunTestsWithDifferentConfigurationTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/RunTestsWithDifferentConfigurationTests.cs index 4f6e641fb2..f5c2c04ae4 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/RunTestsWithDifferentConfigurationTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/RunTestsWithDifferentConfigurationTests.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; using System.Text; @@ -12,8 +13,6 @@ using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests.TranslationLayerTests; /// @@ -25,10 +24,11 @@ public class RunTestsWithDifferentConfigurationTests : AcceptanceTestBase private const string Netcoreapp = "netcoreapp"; private const string Message = "VsTestConsoleWrapper does not support .Net Core Runner"; - private IVsTestConsoleWrapper _vstestConsoleWrapper; - private TempDirectory _logsDir; - private RunEventHandler _runEventHandler; + private IVsTestConsoleWrapper? _vstestConsoleWrapper; + private TempDirectory? _logsDir; + private RunEventHandler? _runEventHandler; + [MemberNotNull(nameof(_vstestConsoleWrapper), nameof(_logsDir), nameof(_runEventHandler))] private void Setup() { _vstestConsoleWrapper = GetVsTestConsoleWrapper(); @@ -52,7 +52,7 @@ public void RunTestsWithTestAdapterPath(RunnerInfo runnerInfo) Setup(); var testAdapterPath = Directory.EnumerateFiles(GetTestAdapterPath(), "*.TestAdapter.dll").ToList(); - _vstestConsoleWrapper.InitializeExtensions(new List() { testAdapterPath.FirstOrDefault() }); + _vstestConsoleWrapper.InitializeExtensions(new List() { testAdapterPath.FirstOrDefault() }); _vstestConsoleWrapper.RunTests( GetTestAssemblies(), diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/RunTestsWithFilterTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/RunTestsWithFilterTests.cs index 162ed10bde..152419a681 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/RunTestsWithFilterTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/RunTestsWithFilterTests.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces; @@ -9,8 +10,6 @@ using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.AcceptanceTests.TranslationLayerTests; /// @@ -19,9 +18,10 @@ namespace Microsoft.TestPlatform.AcceptanceTests.TranslationLayerTests; [TestClass] public class RunTestsWithFilterTests : AcceptanceTestBase { - private IVsTestConsoleWrapper _vstestConsoleWrapper; - private RunEventHandler _runEventHandler; + private IVsTestConsoleWrapper? _vstestConsoleWrapper; + private RunEventHandler? _runEventHandler; + [MemberNotNull(nameof(_vstestConsoleWrapper), nameof(_runEventHandler))] private void Setup() { _vstestConsoleWrapper = GetVsTestConsoleWrapper(); @@ -55,7 +55,7 @@ public void RunTestsWithTestCaseFilter(RunnerInfo runnerInfo) // Assert Assert.AreEqual(1, _runEventHandler.TestResults.Count); - Assert.AreEqual(TestOutcome.Passed, _runEventHandler.TestResults.FirstOrDefault().Outcome); + Assert.AreEqual(TestOutcome.Passed, _runEventHandler.TestResults.First().Outcome); } [TestMethod] diff --git a/test/Microsoft.TestPlatform.SmokeTests/DotnetHostArchitectureVerifierTests.cs b/test/Microsoft.TestPlatform.SmokeTests/DotnetHostArchitectureVerifierTests.cs index 5eab5995cc..0e8518fd9c 100644 --- a/test/Microsoft.TestPlatform.SmokeTests/DotnetHostArchitectureVerifierTests.cs +++ b/test/Microsoft.TestPlatform.SmokeTests/DotnetHostArchitectureVerifierTests.cs @@ -35,7 +35,7 @@ public void VerifyHostArchitecture(string architecture) patchRuntimeConfig["runtimeOptions"]["framework"]["version"] = sdkVersion; File.WriteAllText(runtimeConfigFile, patchRuntimeConfig.ToString()); - var environmentVariables = new Dictionary + var environmentVariables = new Dictionary { ["DOTNET_MULTILEVEL_LOOKUP"] = "0", ["ExpectedArchitecture"] = architecture diff --git a/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestBase.cs b/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestBase.cs index bfde968231..4ebe8bc18b 100644 --- a/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestBase.cs +++ b/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestBase.cs @@ -39,7 +39,7 @@ public class IntegrationTestBase private string _standardTestError = string.Empty; private int _runnerExitCode = -1; - private string _arguments = string.Empty; + private string? _arguments = string.Empty; protected readonly IntegrationTestEnvironment _testEnvironment; @@ -103,7 +103,7 @@ public void TempDirectoryCleanup() /// /// /// Command line arguments string. - public static string PrepareArguments(string[] testAssemblies, string testAdapterPath, string runSettings, + public static string PrepareArguments(string[] testAssemblies, string? testAdapterPath, string? runSettings, string framework, string? inIsolation = "", string? resultsDirectory = null) { var arguments = ""; @@ -172,7 +172,7 @@ public static string PrepareArguments(string[] testAssemblies, string testAdapte /// /// /// Command line arguments string. - public static string PrepareArguments(string testAssembly, string testAdapterPath, string runSettings, + public static string PrepareArguments(string testAssembly, string? testAdapterPath, string? runSettings, string framework, string? inIsolation = "", string? resultsDirectory = null) => PrepareArguments(new string[] { testAssembly }, testAdapterPath, runSettings, framework, inIsolation, resultsDirectory); @@ -181,7 +181,7 @@ public static string PrepareArguments(string testAssembly, string testAdapterPat /// Invokes vstest.console with specified arguments. /// /// Arguments provided to vstest.console.exe - public void InvokeVsTest(string arguments, Dictionary? environmentVariables = null) + public void InvokeVsTest(string? arguments, Dictionary? environmentVariables = null) { var debugEnvironmentVariables = AddDebugEnvironmentVariables(environmentVariables); ExecuteVsTestConsole(arguments, out _standardTestOutput, out _standardTestError, out _runnerExitCode, debugEnvironmentVariables); @@ -192,7 +192,7 @@ public void InvokeVsTest(string arguments, Dictionary? environme /// Invokes our local copy of dotnet that is patched with artifacts from the build with specified arguments. /// /// Arguments provided to vstest.console.exe - public void InvokeDotnetTest(string arguments, Dictionary? environmentVariables = null, bool useDotnetFromTools = false, string? workingDirectory = null) + public void InvokeDotnetTest(string arguments, Dictionary? environmentVariables = null, bool useDotnetFromTools = false, string? workingDirectory = null) { var debugEnvironmentVariables = AddDebugEnvironmentVariables(environmentVariables); @@ -219,18 +219,18 @@ public void InvokeDotnetTest(string arguments, Dictionary? envir /// Dotnet Framework of test assembly. /// Run settings for execution. public void InvokeVsTestForExecution(string testAssembly, - string testAdapterPath, + string? testAdapterPath, string framework, - string runSettings = "", - Dictionary? environmentVariables = null) + string? runSettings = "", + Dictionary? environmentVariables = null) { var arguments = PrepareArguments(testAssembly, testAdapterPath, runSettings, framework, _testEnvironment.InIsolationValue, resultsDirectory: TempDirectory.Path); InvokeVsTest(arguments, environmentVariables); } - private Dictionary AddDebugEnvironmentVariables(Dictionary? environmentVariables) + private Dictionary AddDebugEnvironmentVariables(Dictionary? environmentVariables) { - environmentVariables ??= new Dictionary(); + environmentVariables ??= new(); if (_testEnvironment.DebugInfo != null) { @@ -265,7 +265,7 @@ private Dictionary AddDebugEnvironmentVariables(DictionaryPath to test adapters. /// Run settings for execution. public void InvokeVsTestForDiscovery(string testAssembly, string testAdapterPath, string runSettings = "", string targetFramework = "", - Dictionary? environmentVariables = null) + Dictionary? environmentVariables = null) { var arguments = PrepareArguments(testAssembly, testAdapterPath, runSettings, targetFramework, _testEnvironment.InIsolationValue!, resultsDirectory: TempDirectory.Path); arguments = string.Concat(arguments, " /listtests"); @@ -635,7 +635,7 @@ public virtual string GetConsoleRunnerPath() return consoleRunnerPath; } - protected virtual string SetVSTestConsoleDLLPathInArgs(string args) + protected virtual string SetVSTestConsoleDLLPathInArgs(string? args) { var vstestConsoleDll = GetDotnetRunnerPath(); vstestConsoleDll = vstestConsoleDll.AddDoubleQuote(); @@ -698,7 +698,7 @@ public IVsTestConsoleWrapper GetVsTestConsoleWrapper(Dictionary // TODO: This is scheduled to be fixed in 17.3, where it will start working normally. We will just add those // variables, unless we explicitly say to clean them. https://github.com/microsoft/vstest/pull/3433 // Remove this code later, and just pass the variables you want to add. - var debugEnvironmentVariables = AddDebugEnvironmentVariables(new Dictionary()); + var debugEnvironmentVariables = AddDebugEnvironmentVariables(new()); environmentVariables ??= new(); if (debugEnvironmentVariables.Count > 0) { @@ -739,7 +739,7 @@ private static string GetTestMethodName(string testFullName) return testMethodName; } - protected void ExecuteVsTestConsole(string args, out string stdOut, out string stdError, out int exitCode, Dictionary? environmentVariables = null) + protected void ExecuteVsTestConsole(string? args, out string stdOut, out string stdError, out int exitCode, Dictionary? environmentVariables = null) { if (IsNetCoreRunner()) { @@ -761,11 +761,11 @@ protected void ExecuteVsTestConsole(string args, out string stdOut, out string s /// /// private void ExecutePatchedDotnet(string command, string args, out string stdOut, out string stdError, out int exitCode, - Dictionary? environmentVariables = null, bool useDotnetFromTools = false, string? workingDirectory = null) + Dictionary? environmentVariables = null, bool useDotnetFromTools = false, string? workingDirectory = null) { if (environmentVariables is null) { - environmentVariables = new Dictionary(); + environmentVariables = new(); } environmentVariables["DOTNET_MULTILEVEL_LOOKUP"] = "0"; @@ -775,8 +775,8 @@ private void ExecutePatchedDotnet(string command, string args, out string stdOut ExecuteApplication(patchedDotnetPath, string.Join(" ", command, args), out stdOut, out stdError, out exitCode, environmentVariables, workingDirectory); } - protected static void ExecuteApplication(string path, string args, out string stdOut, out string stdError, out int exitCode, - Dictionary? environmentVariables = null, string? workingDirectory = null) + protected static void ExecuteApplication(string path, string? args, out string stdOut, out string stdError, out int exitCode, + Dictionary? environmentVariables = null, string? workingDirectory = null) { if (path.IsNullOrWhiteSpace()) { diff --git a/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestEnvironment.cs b/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestEnvironment.cs index 4bf3e6d7a7..ed4fc46801 100644 --- a/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestEnvironment.cs +++ b/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestEnvironment.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.IO; using System.Xml; @@ -106,6 +107,7 @@ public string PublishDirectory /// Gets the target framework. /// Supported values = net451, netcoreapp1.0. /// + [NotNull] public string? TargetFramework { get; set; } ///