Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable nullable on ObjectModel tests #3502

Merged
merged 2 commits into from Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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";
Evangelink marked this conversation as resolved.
Show resolved Hide resolved
#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
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
Expand Up @@ -9,8 +9,6 @@

using Newtonsoft.Json;

#nullable disable

namespace Microsoft.TestPlatform.ObjectModel.UnitTests.Client;

[TestClass]
Expand Down
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
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
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
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
Expand Up @@ -5,8 +5,6 @@

using Microsoft.VisualStudio.TestTools.UnitTesting;

#nullable disable

namespace Microsoft.TestPlatform.ObjectModel.UnitTests;

[TestClass]
Expand Down
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
Expand Up @@ -10,8 +10,6 @@

using MSTest.TestFramework.AssertExtensions;

#nullable disable

namespace Microsoft.TestPlatform.ObjectModel.UnitTests;

[TestClass]
Expand Down
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
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
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
Expand Up @@ -8,8 +8,6 @@

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

#nullable disable

namespace Microsoft.TestPlatform.ObjectModel.UnitTests;

[TestClass]
Expand Down
Expand Up @@ -11,8 +11,6 @@

using Moq;

#nullable disable

namespace Microsoft.TestPlatform.ObjectModel.UnitTests.Utilities;

[TestClass]
Expand Down
Expand Up @@ -9,8 +9,6 @@

using Microsoft.VisualStudio.TestTools.UnitTesting;

#nullable disable

namespace Microsoft.TestPlatform.ObjectModel.UnitTests.Utilities;

[TestClass]
Expand Down
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