diff --git a/test/Microsoft.TestPlatform.ObjectModel.PlatformTests/DiaSessionTests.cs b/test/Microsoft.TestPlatform.ObjectModel.PlatformTests/DiaSessionTests.cs index 4925635fe3..552a9c0541 100644 --- a/test/Microsoft.TestPlatform.ObjectModel.PlatformTests/DiaSessionTests.cs +++ b/test/Microsoft.TestPlatform.ObjectModel.PlatformTests/DiaSessionTests.cs @@ -8,17 +8,18 @@ using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.ObjectModel.PlatformTests; [TestClass] public class DiaSessionTests : IntegrationTestBase { +#if NETFRAMEWORK private const string NET451 = "net451"; +#else private const string NETCOREAPP21 = "netcoreapp2.1"; +#endif - public static string GetAndSetTargetFrameWork(IntegrationTestEnvironment testEnvironment) + public static string? GetAndSetTargetFrameWork(IntegrationTestEnvironment testEnvironment) { var currentTargetFrameWork = testEnvironment.TargetFramework; testEnvironment.TargetFramework = @@ -125,7 +126,7 @@ public void DiaSessionPerfTest() _testEnvironment.TargetFramework = currentTargetFrameWork; } - private void ValidateLineNumbers(int min, int max) + private static void ValidateLineNumbers(int min, int max) { // Release builds optimize code, hence min line numbers are different. if (IntegrationTestEnvironment.BuildConfiguration.StartsWith("release", StringComparison.OrdinalIgnoreCase)) @@ -149,7 +150,7 @@ private void ValidateLineNumbers(int min, int max) } } - private void ValidateMinLineNumber(int expected, int actual) + private static void ValidateMinLineNumber(int expected, int actual) { // Release builds optimize code, hence min line numbers are different. if (IntegrationTestEnvironment.BuildConfiguration.StartsWith("release", StringComparison.OrdinalIgnoreCase)) diff --git a/test/Microsoft.TestPlatform.ObjectModel.UnitTests/Client/BaseTestRunCriteriaTests.cs b/test/Microsoft.TestPlatform.ObjectModel.UnitTests/Client/BaseTestRunCriteriaTests.cs index 23f2a4f189..cead712f27 100644 --- a/test/Microsoft.TestPlatform.ObjectModel.UnitTests/Client/BaseTestRunCriteriaTests.cs +++ b/test/Microsoft.TestPlatform.ObjectModel.UnitTests/Client/BaseTestRunCriteriaTests.cs @@ -6,8 +6,6 @@ using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.ObjectModel.UnitTests.Client; [TestClass] diff --git a/test/Microsoft.TestPlatform.ObjectModel.UnitTests/Client/DiscoveryCriteriaTests.cs b/test/Microsoft.TestPlatform.ObjectModel.UnitTests/Client/DiscoveryCriteriaTests.cs index 61aeb4febb..513fbd21b2 100644 --- a/test/Microsoft.TestPlatform.ObjectModel.UnitTests/Client/DiscoveryCriteriaTests.cs +++ b/test/Microsoft.TestPlatform.ObjectModel.UnitTests/Client/DiscoveryCriteriaTests.cs @@ -9,8 +9,6 @@ using Newtonsoft.Json; -#nullable disable - namespace Microsoft.TestPlatform.ObjectModel.UnitTests.Client; [TestClass] diff --git a/test/Microsoft.TestPlatform.ObjectModel.UnitTests/Client/TestRunCriteriaTests.cs b/test/Microsoft.TestPlatform.ObjectModel.UnitTests/Client/TestRunCriteriaTests.cs index 04b8b45770..6d480646ce 100644 --- a/test/Microsoft.TestPlatform.ObjectModel.UnitTests/Client/TestRunCriteriaTests.cs +++ b/test/Microsoft.TestPlatform.ObjectModel.UnitTests/Client/TestRunCriteriaTests.cs @@ -9,8 +9,6 @@ using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.ObjectModel.UnitTests; [TestClass] diff --git a/test/Microsoft.TestPlatform.ObjectModel.UnitTests/CustomKeyValueConverterTests.cs b/test/Microsoft.TestPlatform.ObjectModel.UnitTests/CustomKeyValueConverterTests.cs index 2ad372f125..804cf98ce2 100644 --- a/test/Microsoft.TestPlatform.ObjectModel.UnitTests/CustomKeyValueConverterTests.cs +++ b/test/Microsoft.TestPlatform.ObjectModel.UnitTests/CustomKeyValueConverterTests.cs @@ -8,8 +8,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.ObjectModel.UnitTests; [TestClass] @@ -68,6 +66,7 @@ public void CustomKeyValueConverterShouldDeserializeEmptyKeyOrValue() var data = _customKeyValueConverter.ConvertFrom(null, CultureInfo.InvariantCulture, json) as KeyValuePair[]; + Assert.IsNotNull(data); Assert.AreEqual(1, data.Length); Assert.AreEqual(string.Empty, data[0].Key); Assert.AreEqual(string.Empty, data[0].Value); diff --git a/test/Microsoft.TestPlatform.ObjectModel.UnitTests/CustomStringArrayConverterTests.cs b/test/Microsoft.TestPlatform.ObjectModel.UnitTests/CustomStringArrayConverterTests.cs index 1ffd6b4a8e..3e235f3792 100644 --- a/test/Microsoft.TestPlatform.ObjectModel.UnitTests/CustomStringArrayConverterTests.cs +++ b/test/Microsoft.TestPlatform.ObjectModel.UnitTests/CustomStringArrayConverterTests.cs @@ -7,8 +7,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.ObjectModel.UnitTests; [TestClass] @@ -51,6 +49,7 @@ public void CustomStringArrayConverterShouldDeserializeNullKeyOrValue() var data = _customStringArrayConverter.ConvertFrom(null, CultureInfo.InvariantCulture, json) as string[]; + Assert.IsNotNull(data); Assert.AreEqual(2, data.Length); Assert.IsNull(data[0]); Assert.AreEqual("val", data[1]); @@ -63,6 +62,7 @@ public void CustomStringArrayConverterShouldDeserializeEmptyKeyOrValue() var data = _customStringArrayConverter.ConvertFrom(null, CultureInfo.InvariantCulture, json) as string[]; + Assert.IsNotNull(data); Assert.AreEqual(2, data.Length); Assert.AreEqual(string.Empty, data[0]); Assert.AreEqual(string.Empty, data[1]); diff --git a/test/Microsoft.TestPlatform.ObjectModel.UnitTests/DataCollector/Events/SessionEventsTests.cs b/test/Microsoft.TestPlatform.ObjectModel.UnitTests/DataCollector/Events/SessionEventsTests.cs index dd0f5b6a9f..6f239fd489 100644 --- a/test/Microsoft.TestPlatform.ObjectModel.UnitTests/DataCollector/Events/SessionEventsTests.cs +++ b/test/Microsoft.TestPlatform.ObjectModel.UnitTests/DataCollector/Events/SessionEventsTests.cs @@ -6,8 +6,6 @@ using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection; using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.ObjectModel.UnitTests; [TestClass] diff --git a/test/Microsoft.TestPlatform.ObjectModel.UnitTests/FrameworkTests.cs b/test/Microsoft.TestPlatform.ObjectModel.UnitTests/FrameworkTests.cs index 84a71688ea..f5ecd13f21 100644 --- a/test/Microsoft.TestPlatform.ObjectModel.UnitTests/FrameworkTests.cs +++ b/test/Microsoft.TestPlatform.ObjectModel.UnitTests/FrameworkTests.cs @@ -5,8 +5,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.ObjectModel.UnitTests; [TestClass] diff --git a/test/Microsoft.TestPlatform.ObjectModel.UnitTests/Hosting/TestRunnerConnectionInfoExtensionsTests.cs b/test/Microsoft.TestPlatform.ObjectModel.UnitTests/Hosting/TestRunnerConnectionInfoExtensionsTests.cs index 19e4bffd53..abdc716457 100644 --- a/test/Microsoft.TestPlatform.ObjectModel.UnitTests/Hosting/TestRunnerConnectionInfoExtensionsTests.cs +++ b/test/Microsoft.TestPlatform.ObjectModel.UnitTests/Hosting/TestRunnerConnectionInfoExtensionsTests.cs @@ -6,8 +6,6 @@ using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace TestPlatform.TestHostProvider.UnitTests.Hosting; [TestClass] diff --git a/test/Microsoft.TestPlatform.ObjectModel.UnitTests/RunSettings/RunConfigurationTests.cs b/test/Microsoft.TestPlatform.ObjectModel.UnitTests/RunSettings/RunConfigurationTests.cs index 12f1a1d1ae..6a8b472c36 100644 --- a/test/Microsoft.TestPlatform.ObjectModel.UnitTests/RunSettings/RunConfigurationTests.cs +++ b/test/Microsoft.TestPlatform.ObjectModel.UnitTests/RunSettings/RunConfigurationTests.cs @@ -10,8 +10,6 @@ using MSTest.TestFramework.AssertExtensions; -#nullable disable - namespace Microsoft.TestPlatform.ObjectModel.UnitTests; [TestClass] diff --git a/test/Microsoft.TestPlatform.ObjectModel.UnitTests/RunSettings/RunSettingsTests.cs b/test/Microsoft.TestPlatform.ObjectModel.UnitTests/RunSettings/RunSettingsTests.cs index 55cb173a87..bdb1deae21 100644 --- a/test/Microsoft.TestPlatform.ObjectModel.UnitTests/RunSettings/RunSettingsTests.cs +++ b/test/Microsoft.TestPlatform.ObjectModel.UnitTests/RunSettings/RunSettingsTests.cs @@ -7,8 +7,6 @@ using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.ObjectModel.UnitTests; [TestClass] @@ -28,10 +26,10 @@ public ChildRunSettings() : base("SomeName") { } - public override XmlElement ToXml() + public override XmlElement? ToXml() { var document = new XmlDocument(); - using (XmlWriter writer = document.CreateNavigator().AppendChild()) + using (XmlWriter writer = document.CreateNavigator()!.AppendChild()) { new XmlSerializer(typeof(ChildRunSettings)).Serialize(writer, this); } diff --git a/test/Microsoft.TestPlatform.ObjectModel.UnitTests/TestCaseTests.cs b/test/Microsoft.TestPlatform.ObjectModel.UnitTests/TestCaseTests.cs index c220e8b009..3d6140bdb5 100644 --- a/test/Microsoft.TestPlatform.ObjectModel.UnitTests/TestCaseTests.cs +++ b/test/Microsoft.TestPlatform.ObjectModel.UnitTests/TestCaseTests.cs @@ -7,17 +7,14 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.ObjectModel.UnitTests; [TestClass] public class TestCaseTests { - private TestCase _testCase; + private readonly TestCase _testCase; - [TestInitialize] - public void TestInit() + public TestCaseTests() { _testCase = new TestCase("sampleTestClass.sampleTestCase", new Uri("executor://sampleTestExecutor"), "sampleTest.dll"); } diff --git a/test/Microsoft.TestPlatform.ObjectModel.UnitTests/TestObjectTests.cs b/test/Microsoft.TestPlatform.ObjectModel.UnitTests/TestObjectTests.cs index 42f0c8269d..2af3bc89a3 100644 --- a/test/Microsoft.TestPlatform.ObjectModel.UnitTests/TestObjectTests.cs +++ b/test/Microsoft.TestPlatform.ObjectModel.UnitTests/TestObjectTests.cs @@ -8,8 +8,6 @@ using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.ObjectModel.UnitTests; [TestClass] diff --git a/test/Microsoft.TestPlatform.ObjectModel.UnitTests/TestResultTests.cs b/test/Microsoft.TestPlatform.ObjectModel.UnitTests/TestResultTests.cs index 1c1478475c..a6219cc386 100644 --- a/test/Microsoft.TestPlatform.ObjectModel.UnitTests/TestResultTests.cs +++ b/test/Microsoft.TestPlatform.ObjectModel.UnitTests/TestResultTests.cs @@ -8,8 +8,6 @@ using TestResult = Microsoft.VisualStudio.TestPlatform.ObjectModel.TestResult; -#nullable disable - namespace Microsoft.TestPlatform.ObjectModel.UnitTests; [TestClass] diff --git a/test/Microsoft.TestPlatform.ObjectModel.UnitTests/Utilities/AssemblyHelperTests.cs b/test/Microsoft.TestPlatform.ObjectModel.UnitTests/Utilities/AssemblyHelperTests.cs index 2a9a7e6438..f2a0334d54 100644 --- a/test/Microsoft.TestPlatform.ObjectModel.UnitTests/Utilities/AssemblyHelperTests.cs +++ b/test/Microsoft.TestPlatform.ObjectModel.UnitTests/Utilities/AssemblyHelperTests.cs @@ -11,8 +11,6 @@ using Moq; -#nullable disable - namespace Microsoft.TestPlatform.ObjectModel.UnitTests.Utilities; [TestClass] diff --git a/test/Microsoft.TestPlatform.ObjectModel.UnitTests/Utilities/FilterHelperTests.cs b/test/Microsoft.TestPlatform.ObjectModel.UnitTests/Utilities/FilterHelperTests.cs index 819411f7f6..217ca2b934 100644 --- a/test/Microsoft.TestPlatform.ObjectModel.UnitTests/Utilities/FilterHelperTests.cs +++ b/test/Microsoft.TestPlatform.ObjectModel.UnitTests/Utilities/FilterHelperTests.cs @@ -9,8 +9,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.ObjectModel.UnitTests.Utilities; [TestClass] diff --git a/test/Microsoft.TestPlatform.ObjectModel.UnitTests/Utilities/XmlRunSettingsUtilitiesTests.cs b/test/Microsoft.TestPlatform.ObjectModel.UnitTests/Utilities/XmlRunSettingsUtilitiesTests.cs index ab2f59d219..43087eab09 100644 --- a/test/Microsoft.TestPlatform.ObjectModel.UnitTests/Utilities/XmlRunSettingsUtilitiesTests.cs +++ b/test/Microsoft.TestPlatform.ObjectModel.UnitTests/Utilities/XmlRunSettingsUtilitiesTests.cs @@ -11,8 +11,6 @@ using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; using Microsoft.VisualStudio.TestTools.UnitTesting; -#nullable disable - namespace Microsoft.TestPlatform.ObjectModel.UnitTests.Utilities; [TestClass] @@ -292,7 +290,7 @@ public void GetInProcDataCollectionRunSettingsThrowsExceptionWhenXmlNotValid() [TestMethod] public void CreateDefaultRunSettingsShouldReturnABasicRunSettings() { - var defaultRunSettings = XmlRunSettingsUtilities.CreateDefaultRunSettings().CreateNavigator().OuterXml; + var defaultRunSettings = XmlRunSettingsUtilities.CreateDefaultRunSettings().CreateNavigator()!.OuterXml; var expectedRunSettings = string.Join(Environment.NewLine, "", " ", @@ -1195,7 +1193,7 @@ public void GetDataCollectorsFriendlyNameShouldReturnListOfFriendlyName() CollectionAssert.AreEqual(friendlyNameList, new List { "DummyDataCollector1", "DummyDataCollector2" }); } - private string ConvertOutOfProcDataCollectionSettingsToInProcDataCollectionSettings(string settings) + private static string ConvertOutOfProcDataCollectionSettingsToInProcDataCollectionSettings(string settings) { return settings.Replace("DataCollectionRunSettings", "InProcDataCollectionRunSettings")