Skip to content

Commit 5e233e4

Browse files
committed
Refactor Current, TestExecutionDirectory, and TestAssetsDirectory for null safety based on PR feedback
1 parent 1a475e9 commit 5e233e4

34 files changed

+114
-82
lines changed

test/Common/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ private static int ShowSdkInfo()
6666
{
6767
var log = new StringTestLogger();
6868
var command = new DotnetCommand(log, "--info");
69-
var testDirectory = TestDirectory.Create(Path.Combine(TestContext.Current?.TestExecutionDirectory!, "sdkinfo"));
69+
var testDirectory = TestDirectory.Create(Path.Combine(TestContext.Current.TestExecutionDirectory, "sdkinfo"));
7070

7171
command.WorkingDirectory = testDirectory.Path;
7272

test/Microsoft.NET.Build.Containers.IntegrationTests/EndToEndTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ public async Task EndToEnd_NoAPI_ProjectType(string projectType, bool addPackage
324324

325325
if (addPackageReference)
326326
{
327-
File.Copy(Path.Combine(TestContext.Current?.TestExecutionDirectory!, "NuGet.config"), Path.Combine(newProjectDir.FullName, "NuGet.config"));
327+
File.Copy(Path.Combine(TestContext.Current.TestExecutionDirectory, "NuGet.config"), Path.Combine(newProjectDir.FullName, "NuGet.config"));
328328

329329
(string? packagePath, string? packageVersion) = ToolsetUtils.GetContainersPackagePath();
330330

@@ -495,7 +495,7 @@ public void EndToEnd_NoAPI_Console()
495495
.Execute()
496496
.Should().Pass();
497497

498-
File.Copy(Path.Combine(TestContext.Current?.TestExecutionDirectory!, "NuGet.config"), Path.Combine(newProjectDir.FullName, "NuGet.config"));
498+
File.Copy(Path.Combine(TestContext.Current.TestExecutionDirectory, "NuGet.config"), Path.Combine(newProjectDir.FullName, "NuGet.config"));
499499

500500
(string? packagePath, string? packageVersion) = ToolsetUtils.GetContainersPackagePath();
501501

test/Microsoft.NET.Build.Containers.IntegrationTests/FullFramework/CreateNewImageToolTaskTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,6 @@ public void GenerateCommandLineCommands_LabelGeneration()
596596

597597
private static string GetPathToContainerize()
598598
{
599-
return Path.Combine(TestContext.Current?.TestExecutionDirectory!, "Container", "containerize");
599+
return Path.Combine(TestContext.Current.TestExecutionDirectory, "Container", "containerize");
600600
}
601601
}

test/Microsoft.NET.Build.Containers.IntegrationTests/PackageTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public void SanityTest_ContainerizeDependencies()
2323
"..\\..\\Cli\\Microsoft.DotNet.Cli.Utils\\Microsoft.DotNet.Cli.Utils.csproj"
2424
};
2525

26-
string projectFilePath = Path.Combine(TestContext.Current?.TestExecutionDirectory!, "Container", "ProjectFiles", "containerize.csproj");
26+
string projectFilePath = Path.Combine(TestContext.Current.TestExecutionDirectory, "Container", "ProjectFiles", "containerize.csproj");
2727
XDocument project = XDocument.Load(projectFilePath);
2828
XNamespace ns = project.Root?.Name.Namespace ?? throw new InvalidOperationException("Project file is empty");
2929

@@ -52,7 +52,7 @@ public void SanityTest_NET_Build_ContainersDependencies()
5252
"..\\..\\Cli\\Microsoft.DotNet.Cli.Utils\\Microsoft.DotNet.Cli.Utils.csproj"
5353
};
5454

55-
string projectFilePath = Path.Combine(TestContext.Current?.TestExecutionDirectory!, "Container", "ProjectFiles", "Microsoft.NET.Build.Containers.csproj");
55+
string projectFilePath = Path.Combine(TestContext.Current.TestExecutionDirectory, "Container", "ProjectFiles", "Microsoft.NET.Build.Containers.csproj");
5656
XDocument project = XDocument.Load(projectFilePath);
5757
XNamespace ns = project.Root?.Name.Namespace ?? throw new InvalidOperationException("Project file is empty");
5858

test/Microsoft.NET.Build.Containers.IntegrationTests/ProjectInitializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public sealed class ProjectInitializer
1414

1515
static ProjectInitializer()
1616
{
17-
var artifactPackagingDirectory = Path.Combine(TestContext.Current?.TestExecutionDirectory!, "Container", "packaging");
17+
var artifactPackagingDirectory = Path.Combine(TestContext.Current.TestExecutionDirectory, "Container", "packaging");
1818
var targetsFile = Path.Combine(artifactPackagingDirectory, "Microsoft.NET.Build.Containers.targets");
1919
var propsFile = Path.ChangeExtension(targetsFile, ".props");
2020
_combinedTargetsLocation = CombineFiles(propsFile, targetsFile);

test/Microsoft.NET.Build.Containers.IntegrationTests/TestSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ internal static string? TestArtifactsDirectory
2323
{
2424
if (_testArtifactsDir == null)
2525
{
26-
string tmpDir = Path.Combine(TestContext.Current?.TestExecutionDirectory!, "ContainersTests", DateTime.Now.ToString("yyyyMMddHHmmssfff", CultureInfo.InvariantCulture));
26+
string tmpDir = Path.Combine(TestContext.Current.TestExecutionDirectory, "ContainersTests", DateTime.Now.ToString("yyyyMMddHHmmssfff", CultureInfo.InvariantCulture));
2727
if (!Directory.Exists(tmpDir))
2828
{
2929
Directory.CreateDirectory(tmpDir);

test/Microsoft.NET.Build.Containers.IntegrationTests/ToolsetUtils.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ internal static string GetRuntimeGraphFilePath()
2222
/// <returns></returns>
2323
internal static (string PackagePath, string PackageVersion) GetContainersPackagePath()
2424
{
25-
string packageDir = Path.Combine(TestContext.Current?.TestExecutionDirectory!, "Container", "package");
25+
string packageDir = Path.Combine(TestContext.Current.TestExecutionDirectory, "Container", "package");
2626

2727
//until the package is stabilized, the package version matches TestContext.Current.ToolsetUnderTest.SdkVersion
2828
//after the package is stabilized, the package version doesn't have -prefix (-dev, -ci) anymore
2929
//so one of those is expected
30-
string[] expectedPackageVersions = new[] { TestContext.Current?.ToolsetUnderTest?.SdkVersion, TestContext.Current?.ToolsetUnderTest?.SdkVersion?.Split('-')[0] }!;
30+
string[] expectedPackageVersions = new[] { TestContext.Current.ToolsetUnderTest?.SdkVersion, TestContext.Current.ToolsetUnderTest?.SdkVersion?.Split('-')[0] }!;
3131

3232
foreach (string expectedVersion in expectedPackageVersions)
3333
{

test/Microsoft.NET.Sdk.WorkloadManifestReader.Tests/WorkloadPackGroupTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public void TestGetPackGroups()
8282
public void TestGetManifestFeatureBands()
8383
{
8484
var manifestProvider = CreateManifestProvider();
85-
var workloadResolver = WorkloadResolver.CreateForTests(manifestProvider, TestContext.Current?.ToolsetUnderTest?.DotNetRoot!);
85+
var workloadResolver = WorkloadResolver.CreateForTests(manifestProvider, TestContext.Current.ToolsetUnderTest?.DotNetRoot!);
8686

8787
foreach (var manifestInfo in workloadResolver.GetInstalledManifests())
8888
{
@@ -93,7 +93,7 @@ public void TestGetManifestFeatureBands()
9393

9494
SdkDirectoryWorkloadManifestProvider CreateManifestProvider()
9595
{
96-
return new(TestContext.Current?.ToolsetUnderTest?.DotNetRoot!, TestContext.Current?.ToolsetUnderTest?.SdkVersion!, userProfileDir: null, globalJsonPath: null);
96+
return new(TestContext.Current.ToolsetUnderTest?.DotNetRoot!, TestContext.Current.ToolsetUnderTest?.SdkVersion!, userProfileDir: null, globalJsonPath: null);
9797
}
9898

9999
public IEnumerable<WorkloadManifest> GetManifests(SdkDirectoryWorkloadManifestProvider? manifestProvider = null)
@@ -149,7 +149,7 @@ List<WorkloadPackGroup> GetPackGroups()
149149

150150
var manifestProvider = CreateManifestProvider();
151151
var manifests = GetManifests(manifestProvider);
152-
var workloadResolver = WorkloadResolver.CreateForTests(manifestProvider, TestContext.Current?.ToolsetUnderTest?.DotNetRoot!);
152+
var workloadResolver = WorkloadResolver.CreateForTests(manifestProvider, TestContext.Current.ToolsetUnderTest?.DotNetRoot!);
153153

154154
foreach (var manifest in manifests)
155155
{

test/Microsoft.NET.TestFramework/Attributes/CoreMSBuildAndWindowsOnlyFactAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class CoreMSBuildAndWindowsOnlyFactAttribute : FactAttribute
77
{
88
public CoreMSBuildAndWindowsOnlyFactAttribute()
99
{
10-
if (TestContext.Current?.ToolsetUnderTest != null && TestContext.Current.ToolsetUnderTest.ShouldUseFullFrameworkMSBuild || !RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
10+
if (TestContext.Current.ToolsetUnderTest != null && TestContext.Current.ToolsetUnderTest.ShouldUseFullFrameworkMSBuild || !RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
1111
{
1212
Skip = "This test requires Core MSBuild and Windows to run";
1313
}

test/Microsoft.NET.TestFramework/Attributes/CoreMSBuildAndWindowsOnlyTheoryAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class CoreMSBuildAndWindowsOnlyTheoryAttribute : TheoryAttribute
77
{
88
public CoreMSBuildAndWindowsOnlyTheoryAttribute()
99
{
10-
if (TestContext.Current?.ToolsetUnderTest != null && TestContext.Current.ToolsetUnderTest.ShouldUseFullFrameworkMSBuild || !RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
10+
if (TestContext.Current.ToolsetUnderTest != null && TestContext.Current.ToolsetUnderTest.ShouldUseFullFrameworkMSBuild || !RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
1111
{
1212
Skip = "This test requires Core MSBuild and Windows to run";
1313
}

0 commit comments

Comments
 (0)