Skip to content

Commit d243d39

Browse files
committed
Got several more test source files working. The ItRollsForward tests I added as the supporting code was there. But they don't pass, so I'll remove them next commit. Put the utilities classes in the Utilities namespace.
1 parent 885c9bd commit d243d39

6 files changed

+92
-77
lines changed

test/EndToEnd.Tests/GivenFrameworkDependentApps.cs

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
// Copyright (c) .NET Foundation and contributors. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4+
using EndToEnd.Tests.Utilities;
45
using NuGet.ProjectModel;
56
using NuGet.Versioning;
6-
using RestoreCommand = Microsoft.DotNet.Tools.Test.Utilities.RestoreCommand;
7-
using TestBase = Microsoft.DotNet.Tools.Test.Utilities.TestBase;
8-
using static Microsoft.DotNet.Tools.Test.Utilities.TestCommandExtensions;
97

10-
namespace EndToEnd
8+
namespace EndToEnd.Tests
119
{
12-
public class GivenFrameworkDependentApps : TestBase
10+
public class GivenFrameworkDependentApps(ITestOutputHelper log) : SdkTest(log)
1311
{
1412
[Theory]
1513
[ClassData(typeof(SupportedNetCoreAppVersions))]
@@ -42,42 +40,37 @@ public void ItDoesNotRollForwardToTheLatestVersionOfAspNetCoreApp(string minorVe
4240
internal void ItDoesNotRollForwardToTheLatestVersion(string packageName, string minorVersion)
4341
{
4442
// https://github.com/NuGet/Home/issues/8571
45-
#if LINUX_PORTABLE
43+
#if LINUX_PORTABLE
4644
return;
47-
#else
48-
var testProjectCreator = new TestProjectCreator()
49-
{
50-
PackageName = packageName,
51-
MinorVersion = minorVersion,
52-
};
53-
54-
var _testInstance = testProjectCreator.Create();
55-
56-
string projectDirectory = _testInstance.Root.FullName;
45+
#else
46+
var testProjectCreator = new TestProjectCreator()
47+
{
48+
PackageName = packageName,
49+
MinorVersion = minorVersion,
50+
};
5751

58-
string projectPath = Path.Combine(projectDirectory, "TestAppSimple.csproj");
52+
var _testInstance = testProjectCreator.Create(_testAssetsManager);
5953

60-
// Get the resolved version of .NET Core
61-
new RestoreCommand()
62-
.WithWorkingDirectory(projectDirectory)
63-
.Execute().Should().Pass();
54+
// Get the resolved version of .NET Core
55+
new RestoreCommand(_testInstance)
56+
.Execute().Should().Pass();
6457

65-
string assetsFilePath = Path.Combine(projectDirectory, "obj", "project.assets.json");
66-
var assetsFile = new LockFileFormat().Read(assetsFilePath);
58+
string assetsFilePath = Path.Combine(_testInstance.TestRoot, "obj", "project.assets.json");
59+
var assetsFile = new LockFileFormat().Read(assetsFilePath);
6760

68-
var versionInAssertsJson = GetPackageVersion(assetsFile, packageName);
69-
versionInAssertsJson.Should().NotBeNull();
61+
var versionInAssertsJson = GetPackageVersion(assetsFile, packageName);
62+
versionInAssertsJson.Should().NotBeNull();
7063

71-
if (versionInAssertsJson.IsPrerelease && versionInAssertsJson.Patch == 0)
72-
{
73-
// if the bundled version is, for example, a prerelease of
74-
// .NET Core 2.1.1, that we don't roll forward to that prerelease
75-
// version for framework-dependent deployments.
76-
return;
77-
}
64+
if (versionInAssertsJson.IsPrerelease && versionInAssertsJson.Patch == 0)
65+
{
66+
// if the bundled version is, for example, a prerelease of
67+
// .NET Core 2.1.1, that we don't roll forward to that prerelease
68+
// version for framework-dependent deployments.
69+
return;
70+
}
7871

79-
versionInAssertsJson.ToNormalizedString().Should().BeEquivalentTo(GetExpectedVersion(packageName, minorVersion));
80-
#endif
72+
versionInAssertsJson.ToNormalizedString().Should().BeEquivalentTo(GetExpectedVersion(packageName, minorVersion));
73+
#endif
8174
}
8275

8376
private static NuGetVersion GetPackageVersion(LockFile lockFile, string packageName) => lockFile?.Targets?.SingleOrDefault(t => t.RuntimeIdentifier == null)

test/EndToEnd.Tests/GivenSelfContainedAppsRollForward.cs

Lines changed: 53 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,44 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using Microsoft.DotNet.TestFramework;
4+
//using Microsoft.DotNet.TestFramework;
5+
using EndToEnd.Tests.Utilities;
56
using NuGet.ProjectModel;
67
using NuGet.Versioning;
7-
using RestoreCommand = Microsoft.DotNet.Tools.Test.Utilities.RestoreCommand;
8-
using NewCommandShim = Microsoft.DotNet.Tools.Test.Utilities.NewCommandShim;
9-
using TestBase = Microsoft.DotNet.Tools.Test.Utilities.TestBase;
10-
using static Microsoft.DotNet.Tools.Test.Utilities.TestCommandExtensions;
8+
//using RestoreCommand = Microsoft.DotNet.Tools.Test.Utilities.RestoreCommand;
9+
//using NewCommandShim = Microsoft.DotNet.Tools.Test.Utilities.NewCommandShim;
10+
//using TestBase = Microsoft.DotNet.Tools.Test.Utilities.TestBase;
11+
//using static Microsoft.DotNet.Tools.Test.Utilities.TestCommandExtensions;
1112

12-
namespace EndToEnd
13+
namespace EndToEnd.Tests
1314
{
14-
public partial class GivenSelfContainedAppsRollForward : TestBase
15+
public partial class GivenSelfContainedAppsRollForward(ITestOutputHelper log) : SdkTest(log)
1516
{
17+
public const string NETCorePackageName = "Microsoft.NETCore.App";
18+
public const string AspNetCoreAppPackageName = "Microsoft.AspNetCore.App";
19+
public const string AspNetCoreAllPackageName = "Microsoft.AspNetCore.All";
20+
21+
[Theory]
22+
[ClassData(typeof(SupportedNetCoreAppVersions))]
23+
public void ItRollsForwardToTheLatestNetCoreVersion(string minorVersion)
24+
{
25+
ItRollsForwardToTheLatestVersion(NETCorePackageName, minorVersion);
26+
}
27+
28+
[Theory]
29+
[ClassData(typeof(SupportedAspNetCoreVersions))]
30+
public void ItRollsForwardToTheLatestAspNetCoreAppVersion(string minorVersion)
31+
{
32+
ItRollsForwardToTheLatestVersion(AspNetCoreAppPackageName, minorVersion);
33+
}
34+
35+
[Theory]
36+
[ClassData(typeof(SupportedAspNetCoreVersions))]
37+
public void ItRollsForwardToTheLatestAspNetCoreAllVersion(string minorVersion)
38+
{
39+
ItRollsForwardToTheLatestVersion(AspNetCoreAllPackageName, minorVersion);
40+
}
41+
1642
internal void ItRollsForwardToTheLatestVersion(string packageName, string minorVersion)
1743
{
1844
var testProjectCreator = new TestProjectCreator()
@@ -23,16 +49,13 @@ internal void ItRollsForwardToTheLatestVersion(string packageName, string minorV
2349
RuntimeIdentifier = RuntimeInformation.RuntimeIdentifier
2450
};
2551

26-
var testInstance = testProjectCreator.Create();
27-
28-
string projectDirectory = testInstance.Root.FullName;
52+
var testInstance = testProjectCreator.Create(_testAssetsManager);
2953

3054
// Get the version rolled forward to
31-
new RestoreCommand()
32-
.WithWorkingDirectory(projectDirectory)
33-
.Execute().Should().Pass();
55+
new RestoreCommand(testInstance)
56+
.Execute().Should().Pass();
3457

35-
string assetsFilePath = Path.Combine(projectDirectory, "obj", "project.assets.json");
58+
string assetsFilePath = Path.Combine(testInstance.TestRoot, "obj", "project.assets.json");
3659
var assetsFile = new LockFileFormat().Read(assetsFilePath);
3760

3861
var rolledForwardVersion = GetPackageVersion(assetsFile, packageName);
@@ -49,14 +72,13 @@ internal void ItRollsForwardToTheLatestVersion(string packageName, string minorV
4972

5073
testProjectCreator.Identifier = "floating";
5174

52-
var floatingProjectInstance = testProjectCreator.Create();
75+
var floatingProjectInstance = testProjectCreator.Create(_testAssetsManager);
5376

54-
var floatingProjectPath = Path.Combine(floatingProjectInstance.Root.FullName, "TestAppSimple.csproj");
77+
var floatingProjectPath = Path.Combine(floatingProjectInstance.TestRoot, "TestAppSimple.csproj");
5578

5679
var floatingProject = XDocument.Load(floatingProjectPath);
5780
var ns = floatingProject.Root.Name.Namespace;
5881

59-
6082
if (packageName == TestProjectCreator.NETCorePackageName)
6183
{
6284
// Float the RuntimeFrameworkVersion to get the latest version of the runtime available from feeds
@@ -73,11 +95,10 @@ internal void ItRollsForwardToTheLatestVersion(string packageName, string minorV
7395

7496
floatingProject.Save(floatingProjectPath);
7597

76-
new RestoreCommand()
77-
.WithWorkingDirectory(floatingProjectInstance.Root.FullName)
78-
.Execute().Should().Pass();
98+
new RestoreCommand(floatingProjectInstance)
99+
.Execute().Should().Pass();
79100

80-
string floatingAssetsFilePath = Path.Combine(floatingProjectInstance.Root.FullName, "obj", "project.assets.json");
101+
string floatingAssetsFilePath = Path.Combine(floatingProjectInstance.TestRoot, "obj", "project.assets.json");
81102

82103
var floatedAssetsFile = new LockFileFormat().Read(floatingAssetsFilePath);
83104

@@ -98,12 +119,13 @@ private static NuGetVersion GetPackageVersion(LockFile lockFile, string packageN
98119
public void WeCoverLatestNetCoreAppRollForward()
99120
{
100121
// Run "dotnet new console", get TargetFramework property, and make sure it's covered in SupportedNetCoreAppVersions
101-
var directory = TestAssets.CreateTestDirectory();
102-
string projectDirectory = directory.FullName;
122+
var directory = _testAssetsManager.CreateTestDirectory();
123+
string projectDirectory = directory.Path;
103124

104-
new NewCommandShim()
125+
new DotnetNewCommand(Log, "web", "--no-restore")
126+
.WithVirtualHive()
105127
.WithWorkingDirectory(projectDirectory)
106-
.Execute("console --no-restore").Should().Pass();
128+
.Execute().Should().Pass();
107129

108130
string projectPath = Path.Combine(projectDirectory, Path.GetFileName(projectDirectory) + ".csproj");
109131

@@ -122,14 +144,15 @@ public void WeCoverLatestNetCoreAppRollForward()
122144
[Fact]
123145
public void WeCoverLatestAspNetCoreAppRollForward()
124146
{
125-
var directory = TestAssets.CreateTestDirectory();
126-
string projectDirectory = directory.FullName;
147+
var directory = _testAssetsManager.CreateTestDirectory();
148+
string projectDirectory = directory.Path;
127149

128150
// Run "dotnet new web", get TargetFramework property, and make sure it's covered in SupportedAspNetCoreAppVersions
129151

130-
new NewCommandShim()
152+
new DotnetNewCommand(Log, "web", "--no-restore")
153+
.WithVirtualHive()
131154
.WithWorkingDirectory(projectDirectory)
132-
.Execute("web --no-restore").Should().Pass();
155+
.Execute().Should().Pass();
133156

134157
string projectPath = Path.Combine(projectDirectory, Path.GetFileName(projectDirectory) + ".csproj");
135158

@@ -142,7 +165,7 @@ public void WeCoverLatestAspNetCoreAppRollForward()
142165

143166
TargetFrameworkHelper.GetNetAppTargetFrameworks(SupportedAspNetCoreVersions.Versions)
144167
.Should().Contain(targetFramework, $"the {nameof(SupportedAspNetCoreVersions)} should include the default version " +
145-
"of Microsoft.AspNetCore.App used by the templates created by \"dotnet new web\"");
168+
"of Microsoft.AspNetCore.App used by the templates created by \"dotnet new web\"");
146169
}
147170
}
148171
}

test/EndToEnd.Tests/GivenUsingDefaultRuntimeFrameworkVersions.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using EndToEnd.Tests.Utilities;
45
using NuGet.Versioning;
5-
using RestoreCommand = Microsoft.DotNet.Tools.Test.Utilities.RestoreCommand;
6-
using TestBase = Microsoft.DotNet.Tools.Test.Utilities.TestBase;
7-
using static Microsoft.DotNet.Tools.Test.Utilities.TestCommandExtensions;
86

9-
namespace EndToEnd
7+
namespace EndToEnd.Tests
108
{
11-
public partial class GivenUsingDefaultRuntimeFrameworkVersions : TestBase
9+
public partial class GivenUsingDefaultRuntimeFrameworkVersions(ITestOutputHelper log) : SdkTest(log)
1210
{
1311
private static readonly IEnumerable<string> frameworks = new string[] {"Microsoft.NETCore.App", "Microsoft.WindowsDesktop.App",
1412
"Microsoft.WindowsDesktop.App.WPF", "Microsoft.WindowsDesktop.App.WindowsForms", "Microsoft.AspNetCore.App" };
@@ -24,9 +22,9 @@ public void DefaultRuntimeVersionsAreUpToDate()
2422
PackageName = "DefaultRuntimeVersionsAreUpToDate",
2523
MinorVersion = "3.0"
2624
};
27-
var testProject = testProjectCreator.Create();
25+
var testProject = testProjectCreator.Create(_testAssetsManager);
2826

29-
var projectFile = new DirectoryInfo(testProject.Root.FullName).GetFiles("*.csproj").First().FullName;
27+
var projectFile = new DirectoryInfo(testProject.TestRoot).GetFiles("*.csproj").First().FullName;
3028
var project = XDocument.Load(projectFile);
3129
string writeResolvedVersionsTarget = @$"
3230
<Target Name=`WriteResolvedVersions` AfterTargets=`PrepareForBuild;ProcessFrameworkReferences`>
@@ -51,11 +49,10 @@ public void DefaultRuntimeVersionsAreUpToDate()
5149
project.Save(file);
5250
}
5351

54-
new RestoreCommand()
55-
.WithWorkingDirectory(testProject.Root.FullName)
56-
.Execute().Should().Pass();
52+
new RestoreCommand(testProject)
53+
.Execute().Should().Pass();
5754

58-
var binDirectory = new DirectoryInfo(testProject.Root.FullName).Sub("bin").Sub("Debug").GetDirectories().FirstOrDefault();
55+
var binDirectory = new DirectoryInfo(testProject.TestRoot).Sub("bin").Sub("Debug").GetDirectories().FirstOrDefault();
5956
binDirectory.Should().HaveFilesMatching(outputFile, SearchOption.TopDirectoryOnly);
6057
var resolvedVersionsFile = File.ReadAllLines(Path.Combine(binDirectory.FullName, outputFile));
6158
foreach (var framework in frameworks)

test/EndToEnd.Tests/GivenWeWantToRequireWindowsForDesktopApps.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) .NET Foundation and contributors. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4+
using EndToEnd.Tests.Utilities;
5+
46
namespace EndToEnd.Tests
57
{
68
public class GivenWeWantToRequireWindowsForDesktopApps(ITestOutputHelper log) : SdkTest(log)

test/EndToEnd.Tests/Utilities/SupportedNetCoreAppVersions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
using System.Collections;
55

6-
namespace EndToEnd.Tests
6+
namespace EndToEnd.Tests.Utilities
77
{
88
public static class TargetFrameworkHelper
99
{

test/EndToEnd.Tests/Utilities/TestProjectCreator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
using System.Runtime.CompilerServices;
55

6-
namespace EndToEnd.Tests
6+
namespace EndToEnd.Tests.Utilities
77
{
88
class TestProjectCreator
99
{

0 commit comments

Comments
 (0)