Skip to content

Commit

Permalink
Enable nullable on ObjectModel tests (#3502)
Browse files Browse the repository at this point in the history
  • Loading branch information
Evangelink committed Mar 31, 2022
1 parent 7924286 commit 7648527
Show file tree
Hide file tree
Showing 17 changed files with 15 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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))
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using Microsoft.VisualStudio.TestTools.UnitTesting;

#nullable disable

namespace Microsoft.TestPlatform.ObjectModel.UnitTests.Client;

[TestClass]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

using Newtonsoft.Json;

#nullable disable

namespace Microsoft.TestPlatform.ObjectModel.UnitTests.Client;

[TestClass]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using Microsoft.VisualStudio.TestTools.UnitTesting;

#nullable disable

namespace Microsoft.TestPlatform.ObjectModel.UnitTests;

[TestClass]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

using Microsoft.VisualStudio.TestTools.UnitTesting;

#nullable disable

namespace Microsoft.TestPlatform.ObjectModel.UnitTests;

[TestClass]
Expand Down Expand Up @@ -68,6 +66,7 @@ public void CustomKeyValueConverterShouldDeserializeEmptyKeyOrValue()

var data = _customKeyValueConverter.ConvertFrom(null, CultureInfo.InvariantCulture, json) as KeyValuePair<string, string>[];

Assert.IsNotNull(data);
Assert.AreEqual(1, data.Length);
Assert.AreEqual(string.Empty, data[0].Key);
Assert.AreEqual(string.Empty, data[0].Value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

using Microsoft.VisualStudio.TestTools.UnitTesting;

#nullable disable

namespace Microsoft.TestPlatform.ObjectModel.UnitTests;

[TestClass]
Expand Down Expand Up @@ -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]);
Expand All @@ -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]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection;
using Microsoft.VisualStudio.TestTools.UnitTesting;

#nullable disable

namespace Microsoft.TestPlatform.ObjectModel.UnitTests;

[TestClass]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

using Microsoft.VisualStudio.TestTools.UnitTesting;

#nullable disable

namespace Microsoft.TestPlatform.ObjectModel.UnitTests;

[TestClass]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestTools.UnitTesting;

#nullable disable

namespace TestPlatform.TestHostProvider.UnitTests.Hosting;

[TestClass]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

using MSTest.TestFramework.AssertExtensions;

#nullable disable

namespace Microsoft.TestPlatform.ObjectModel.UnitTests;

[TestClass]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestTools.UnitTesting;

#nullable disable

namespace Microsoft.TestPlatform.ObjectModel.UnitTests;

[TestClass]
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestTools.UnitTesting;

#nullable disable

namespace Microsoft.TestPlatform.ObjectModel.UnitTests;

[TestClass]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

using TestResult = Microsoft.VisualStudio.TestPlatform.ObjectModel.TestResult;

#nullable disable

namespace Microsoft.TestPlatform.ObjectModel.UnitTests;

[TestClass]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

using Moq;

#nullable disable

namespace Microsoft.TestPlatform.ObjectModel.UnitTests.Utilities;

[TestClass]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

using Microsoft.VisualStudio.TestTools.UnitTesting;

#nullable disable

namespace Microsoft.TestPlatform.ObjectModel.UnitTests.Utilities;

[TestClass]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities;
using Microsoft.VisualStudio.TestTools.UnitTesting;

#nullable disable

namespace Microsoft.TestPlatform.ObjectModel.UnitTests.Utilities;

[TestClass]
Expand Down Expand Up @@ -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,
"<RunSettings>",
" <DataCollectionRunSettings>",
Expand Down Expand Up @@ -1195,7 +1193,7 @@ public void GetDataCollectorsFriendlyNameShouldReturnListOfFriendlyName()
CollectionAssert.AreEqual(friendlyNameList, new List<string> { "DummyDataCollector1", "DummyDataCollector2" });
}

private string ConvertOutOfProcDataCollectionSettingsToInProcDataCollectionSettings(string settings)
private static string ConvertOutOfProcDataCollectionSettingsToInProcDataCollectionSettings(string settings)
{
return
settings.Replace("DataCollectionRunSettings", "InProcDataCollectionRunSettings")
Expand Down

0 comments on commit 7648527

Please sign in to comment.