Skip to content

Commit

Permalink
More info in MsBuildResolver tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JanKrivanek committed Aug 18, 2022
1 parent e2d68c9 commit a903560
Showing 1 changed file with 28 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Microsoft.NET.TestFramework;
using System.Linq;
using Microsoft.DotNet.DotNetSdkResolver;
using System.Diagnostics;

[assembly: CollectionBehavior(DisableTestParallelization = true)]

Expand Down Expand Up @@ -74,7 +75,7 @@ public void ItFindsTheVersionSpecifiedInGlobalJson()
new MockContext { ProjectFileDirectory = environment.TestDirectory },
new MockFactory());

result.Success.Should().BeTrue(string.Join(Environment.NewLine, result.Errors));
result.Success.Should().BeTrue($"No error expected. Error encountered: {string.Join(Environment.NewLine, result.Errors)}. Current Process Path: {Process.GetCurrentProcess().MainModule.FileName}. Mocked Path: {environment.PathEnvironmentVariable}");
result.Path.Should().Be(expected.FullName);
result.AdditionalPaths.Should().BeNull();
result.Version.Should().Be("99.99.98");
Expand All @@ -99,7 +100,7 @@ public void ItUsesProjectDirectoryIfSolutionFilePathIsNullOrWhitespace(string so
new MockContext { ProjectFileDirectory = environment.TestDirectory, SolutionFilePath = solutionFilePath },
new MockFactory());

result.Success.Should().BeTrue(string.Join(Environment.NewLine, result.Errors));
result.Success.Should().BeTrue($"No error expected. Error encountered: {string.Join(Environment.NewLine, result.Errors)}. Current Process Path: {Process.GetCurrentProcess().MainModule.FileName}. Mocked Path: {environment.PathEnvironmentVariable}");
result.Path.Should().StartWith(environment.TestDirectory.FullName);
result.AdditionalPaths.Should().BeNull();
result.Version.Should().Be(version);
Expand All @@ -126,7 +127,7 @@ public void ItUsesCurrentDirectoryIfSolutionFilePathAndProjectFilePathIsNullOrWh
new MockContext { ProjectFilePath = projectFilePath, SolutionFilePath = solutionFilePath },
new MockFactory());

result.Success.Should().BeTrue(string.Join(Environment.NewLine, result.Errors));
result.Success.Should().BeTrue($"No error expected. Error encountered: {string.Join(Environment.NewLine, result.Errors)}. Current Process Path: {Process.GetCurrentProcess().MainModule.FileName}. Mocked Path: {environment.PathEnvironmentVariable}");
result.Path.Should().StartWith(environment.TestDirectory.FullName);
result.AdditionalPaths.Should().BeNull();
result.Version.Should().Be(version);
Expand Down Expand Up @@ -207,7 +208,7 @@ public void ItReturnsHighestSdkAvailableThatIsCompatibleWithMSBuild(bool disallo
},
new MockFactory());

result.Success.Should().BeTrue(string.Join(Environment.NewLine, result.Errors));
result.Success.Should().BeTrue($"No error expected. Error encountered: {string.Join(Environment.NewLine, result.Errors)}. Current Process Path: {Process.GetCurrentProcess().MainModule.FileName}. Mocked Path: {environment.PathEnvironmentVariable}");
result.Path.Should().Be((disallowPreviews ? compatibleRtm : compatiblePreview).FullName);
result.AdditionalPaths.Should().BeNull();
result.PropertiesToAdd.Should().BeNull();
Expand Down Expand Up @@ -281,7 +282,7 @@ public void ItReturnsHighestSdkAvailableThatIsCompatibleWithMSBuildWhenVersionIn
},
new MockFactory());

result.Success.Should().BeTrue(string.Join(Environment.NewLine, result.Errors));
result.Success.Should().BeTrue($"No error expected. Error encountered: {string.Join(Environment.NewLine, result.Errors)}. Current Process Path: {Process.GetCurrentProcess().MainModule.FileName}. Mocked Path: {environment.PathEnvironmentVariable}");
result.Path.Should().Be((disallowPreviews ? compatibleRtm : compatiblePreview).FullName);
result.AdditionalPaths.Should().BeNull();
result.PropertiesToAdd.Count.Should().Be(2);
Expand Down Expand Up @@ -352,7 +353,7 @@ public void ItReturnsTheVersionIfItIsEqualToTheMinVersionAndTheVSDefinedMinVersi
new MockContext { ProjectFileDirectory = environment.TestDirectory },
new MockFactory());

result.Success.Should().BeTrue(string.Join(Environment.NewLine, result.Errors));
result.Success.Should().BeTrue($"No error expected. Error encountered: {string.Join(Environment.NewLine, result.Errors)}. Current Process Path: {Process.GetCurrentProcess().MainModule.FileName}. Mocked Path: {environment.PathEnvironmentVariable}");
result.Path.Should().Be(expected.FullName);
result.AdditionalPaths.Should().BeNull();
result.Version.Should().Be("99.99.99");
Expand All @@ -374,7 +375,7 @@ public void ItReturnsTheVersionIfItIsHigherThanTheMinVersionAndTheVSDefinedMinVe
new MockContext { ProjectFileDirectory = environment.TestDirectory },
new MockFactory());

result.Success.Should().BeTrue(string.Join(Environment.NewLine, result.Errors));
result.Success.Should().BeTrue($"No error expected. Error encountered: {string.Join(Environment.NewLine, result.Errors)}. Current Process Path: {Process.GetCurrentProcess().MainModule.FileName}. Mocked Path: {environment.PathEnvironmentVariable}");
result.Path.Should().Be(expected.FullName);
result.AdditionalPaths.Should().BeNull();
result.Version.Should().Be("999.99.99");
Expand All @@ -401,7 +402,7 @@ public void ItDisallowsPreviewsBasedOnDefault(bool disallowPreviewsByDefault)
new MockContext { ProjectFileDirectory = environment.TestDirectory },
new MockFactory());

result.Success.Should().BeTrue(string.Join(Environment.NewLine, result.Errors));
result.Success.Should().BeTrue($"No error expected. Error encountered: {string.Join(Environment.NewLine, result.Errors)}. Current Process Path: {Process.GetCurrentProcess().MainModule.FileName}. Mocked Path: {environment.PathEnvironmentVariable}");
result.Path.Should().Be(expected.FullName);
result.AdditionalPaths.Should().BeNull();
result.Version.Should().Be(disallowPreviewsByDefault ? "10.0.0" : "11.0.0-preview1");
Expand Down Expand Up @@ -429,7 +430,7 @@ public void ItDisallowsPreviewsBasedOnFile(bool disallowPreviews)
new MockContext { ProjectFileDirectory = environment.TestDirectory },
new MockFactory());

result.Success.Should().BeTrue(string.Join(Environment.NewLine, result.Errors));
result.Success.Should().BeTrue($"No error expected. Error encountered: {string.Join(Environment.NewLine, result.Errors)}. Current Process Path: {Process.GetCurrentProcess().MainModule.FileName}. Mocked Path: {environment.PathEnvironmentVariable}");
result.Path.Should().Be(expected.FullName);
result.AdditionalPaths.Should().BeNull();
result.Version.Should().Be(disallowPreviews ? "10.0.0" : "11.0.0-preview1");
Expand Down Expand Up @@ -503,7 +504,7 @@ public void ItAllowsPreviewWhenGlobalJsonHasPreviewIrrespectiveOfSetting()
new MockContext { ProjectFileDirectory = environment.TestDirectory },
new MockFactory());

result.Success.Should().BeTrue(string.Join(Environment.NewLine, result.Errors));
result.Success.Should().BeTrue($"No error expected. Error encountered: {string.Join(Environment.NewLine, result.Errors)}. Current Process Path: {Process.GetCurrentProcess().MainModule.FileName}. Mocked Path: {environment.PathEnvironmentVariable}");
result.Path.Should().Be(preview.FullName);
result.AdditionalPaths.Should().BeNull();
result.Version.Should().Be("11.0.0-preview1");
Expand Down Expand Up @@ -532,7 +533,7 @@ public void ItRespectsAmbientVSSettings()
new MockContext { ProjectFileDirectory = environment.TestDirectory },
new MockFactory());

result.Success.Should().BeTrue(string.Join(Environment.NewLine, result.Errors));
result.Success.Should().BeTrue($"No error expected. Error encountered: {string.Join(Environment.NewLine, result.Errors)}. Current Process Path: {Process.GetCurrentProcess().MainModule.FileName}. Mocked Path: {environment.PathEnvironmentVariable}");
result.Path.Should().Be(expected.FullName);
result.AdditionalPaths.Should().BeNull();
result.Version.Should().Be(vsSettings.DisallowPrerelease() ? "10.0.0" : "11.0.0-preview1");
Expand Down Expand Up @@ -582,8 +583,7 @@ public TestEnvironment(TestAssetsManager testAssets, string identifier = "", [Ca

DeleteMinimumVSDefinedSDKVersionFile();

string dotnetRootUnderTest = TestContext.Current.ToolsetUnderTest.DotNetRoot;
PathEnvironmentVariable = dotnetRootUnderTest;
PathEnvironmentVariable = string.Empty;
}

public SdkResolver CreateResolver(bool useAmbientSettings = false)
Expand All @@ -593,11 +593,14 @@ public SdkResolver CreateResolver(bool useAmbientSettings = false)
? VSSettings.Ambient
: new VSSettings(VSSettingsFile?.FullName, DisallowPrereleaseByDefault));

public DirectoryInfo GetSdkDirectory(ProgramFiles programFiles, string sdkName, string sdkVersion)
public string GetDotnetExeDirectory(ProgramFiles programFiles) => Path.Combine(
TestDirectory.FullName,
GetProgramFilesDirectory(programFiles).FullName,
"dotnet");

public DirectoryInfo GetSdkDirectory(string dotnetExeDirectory, string sdkName, string sdkVersion)
=> new DirectoryInfo(Path.Combine(
TestDirectory.FullName,
GetProgramFilesDirectory(programFiles).FullName,
"dotnet",
dotnetExeDirectory,
"sdk",
sdkVersion,
"Sdks",
Expand All @@ -613,7 +616,14 @@ public DirectoryInfo CreateSdkDirectory(
string sdkVersion,
Version minimumMSBuildVersion = null)
{
var dir = GetSdkDirectory(programFiles, sdkName, sdkVersion);
string dotnetExeDirectory = GetDotnetExeDirectory(programFiles);
// in order for EnvironemntProvider to pick this dir - it need to be in path and dotnet executable needs to be located in it
PathEnvironmentVariable = $"{dotnetExeDirectory}{Path.PathSeparator}{PathEnvironmentVariable}";
new FileInfo(Path.Combine(
dotnetExeDirectory,
Microsoft.DotNet.NativeWrapper.Constants.DotNet + Microsoft.DotNet.NativeWrapper.Constants.ExeSuffix)
).Create();
var dir = GetSdkDirectory(dotnetExeDirectory, sdkName, sdkVersion);
dir.Create();

if (minimumMSBuildVersion != null)
Expand Down

0 comments on commit a903560

Please sign in to comment.