Refactor / fix implicit version tests
This commit is contained in:
parent
158fbdbbad
commit
cc5a67d2e5
7 changed files with 174 additions and 1048 deletions
File diff suppressed because it is too large
Load diff
|
@ -19,52 +19,37 @@ namespace EndToEnd
|
||||||
[ClassData(typeof(SupportedNetCoreAppVersions))]
|
[ClassData(typeof(SupportedNetCoreAppVersions))]
|
||||||
public void ItDoesNotRollForwardToTheLatestVersionOfNetCore(string minorVersion)
|
public void ItDoesNotRollForwardToTheLatestVersionOfNetCore(string minorVersion)
|
||||||
{
|
{
|
||||||
ItDoesNotRollForwardToTheLatestVersion(GivenSelfContainedAppsRollForward.NETCorePackageName, minorVersion);
|
ItDoesNotRollForwardToTheLatestVersion(TestProjectCreator.NETCorePackageName, minorVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory(Skip = "https://github.com/dotnet/cli/issues/10123")]
|
[Theory]
|
||||||
[ClassData(typeof(SupportedAspNetCoreVersions))]
|
[ClassData(typeof(SupportedAspNetCoreVersions))]
|
||||||
public void ItDoesNotRollForwardToTheLatestVersionOfAspNetCoreApp(string minorVersion)
|
public void ItDoesNotRollForwardToTheLatestVersionOfAspNetCoreApp(string minorVersion)
|
||||||
{
|
{
|
||||||
ItDoesNotRollForwardToTheLatestVersion(GivenSelfContainedAppsRollForward.AspNetCoreAppPackageName, minorVersion);
|
ItDoesNotRollForwardToTheLatestVersion(TestProjectCreator.AspNetCoreAppPackageName, minorVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory(Skip = "https://github.com/dotnet/cli/issues/10123")]
|
[Theory]
|
||||||
[ClassData(typeof(SupportedAspNetCoreVersions))]
|
[ClassData(typeof(SupportedAspNetCoreAllVersions))]
|
||||||
public void ItDoesNotRollForwardToTheLatestVersionOfAspNetCoreAll(string minorVersion)
|
public void ItDoesNotRollForwardToTheLatestVersionOfAspNetCoreAll(string minorVersion)
|
||||||
{
|
{
|
||||||
ItDoesNotRollForwardToTheLatestVersion(GivenSelfContainedAppsRollForward.AspNetCoreAllPackageName, minorVersion);
|
ItDoesNotRollForwardToTheLatestVersion(TestProjectCreator.AspNetCoreAllPackageName, minorVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ItDoesNotRollForwardToTheLatestVersion(string packageName, string minorVersion)
|
public void ItDoesNotRollForwardToTheLatestVersion(string packageName, string minorVersion)
|
||||||
{
|
{
|
||||||
var _testInstance = TestAssets.Get("TestAppSimple")
|
var testProjectCreator = new TestProjectCreator()
|
||||||
.CreateInstance(identifier: packageName + "_" + minorVersion)
|
{
|
||||||
// scope the feed to only dotnet-core feed to avoid flaky when different feed has a newer / lower version
|
PackageName = packageName,
|
||||||
.WithNuGetConfig(new RepoDirectoriesProvider().TestPackages)
|
MinorVersion = minorVersion,
|
||||||
.WithSourceFiles();
|
};
|
||||||
|
|
||||||
|
var _testInstance = testProjectCreator.Create();
|
||||||
|
|
||||||
string projectDirectory = _testInstance.Root.FullName;
|
string projectDirectory = _testInstance.Root.FullName;
|
||||||
|
|
||||||
string projectPath = Path.Combine(projectDirectory, "TestAppSimple.csproj");
|
string projectPath = Path.Combine(projectDirectory, "TestAppSimple.csproj");
|
||||||
|
|
||||||
var project = XDocument.Load(projectPath);
|
|
||||||
var ns = project.Root.Name.Namespace;
|
|
||||||
|
|
||||||
// Update TargetFramework to the right version of .NET Core
|
|
||||||
project.Root.Element(ns + "PropertyGroup")
|
|
||||||
.Element(ns + "TargetFramework")
|
|
||||||
.Value = "netcoreapp" + minorVersion;
|
|
||||||
|
|
||||||
if (packageName != GivenSelfContainedAppsRollForward.NETCorePackageName)
|
|
||||||
{
|
|
||||||
// Add implicit ASP.NET reference
|
|
||||||
project.Root.Add(new XElement(ns + "ItemGroup",
|
|
||||||
new XElement(ns + "PackageReference", new XAttribute("Include", packageName))));
|
|
||||||
}
|
|
||||||
|
|
||||||
project.Save(projectPath);
|
|
||||||
|
|
||||||
// Get the resolved version of .NET Core
|
// Get the resolved version of .NET Core
|
||||||
new RestoreCommand()
|
new RestoreCommand()
|
||||||
.WithWorkingDirectory(projectDirectory)
|
.WithWorkingDirectory(projectDirectory)
|
||||||
|
@ -110,8 +95,8 @@ namespace EndToEnd
|
||||||
{
|
{
|
||||||
// ASP.NET 2.1.0 packages had exact version dependencies, which was problematic,
|
// ASP.NET 2.1.0 packages had exact version dependencies, which was problematic,
|
||||||
// so the default version for 2.1 apps is 2.1.1.
|
// so the default version for 2.1 apps is 2.1.1.
|
||||||
if (packageName == GivenSelfContainedAppsRollForward.AspNetCoreAppPackageName ||
|
if (packageName == TestProjectCreator.AspNetCoreAppPackageName ||
|
||||||
packageName == GivenSelfContainedAppsRollForward.AspNetCoreAllPackageName)
|
packageName == TestProjectCreator.AspNetCoreAllPackageName)
|
||||||
{
|
{
|
||||||
if (minorVersion == "2.1")
|
if (minorVersion == "2.1")
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,65 +16,43 @@ namespace EndToEnd
|
||||||
{
|
{
|
||||||
public partial class GivenSelfContainedAppsRollForward : TestBase
|
public partial class GivenSelfContainedAppsRollForward : TestBase
|
||||||
{
|
{
|
||||||
public const string NETCorePackageName = "Microsoft.NETCore.App";
|
|
||||||
public const string AspNetCoreAppPackageName = "Microsoft.AspNetCore.App";
|
|
||||||
public const string AspNetCoreAllPackageName = "Microsoft.AspNetCore.All";
|
|
||||||
|
|
||||||
[Theory(Skip = "https://github.com/dotnet/cli/issues/10123")]
|
[Theory]
|
||||||
// MemberData is used instead of InlineData here so we can access it in another test to
|
// MemberData is used instead of InlineData here so we can access it in another test to
|
||||||
// verify that we are covering the latest release of .NET Core
|
// verify that we are covering the latest release of .NET Core
|
||||||
[ClassData(typeof(SupportedNetCoreAppVersions))]
|
[ClassData(typeof(SupportedNetCoreAppVersions))]
|
||||||
public void ItRollsForwardToTheLatestNetCoreVersion(string minorVersion)
|
public void ItRollsForwardToTheLatestNetCoreVersion(string minorVersion)
|
||||||
{
|
{
|
||||||
ItRollsForwardToTheLatestVersion(NETCorePackageName, minorVersion);
|
ItRollsForwardToTheLatestVersion(TestProjectCreator.NETCorePackageName, minorVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory(Skip = "https://github.com/dotnet/cli/issues/10123")]
|
[Theory]
|
||||||
[ClassData(typeof(SupportedAspNetCoreVersions))]
|
[ClassData(typeof(SupportedAspNetCoreVersions))]
|
||||||
public void ItRollsForwardToTheLatestAspNetCoreAppVersion(string minorVersion)
|
public void ItRollsForwardToTheLatestAspNetCoreAppVersion(string minorVersion)
|
||||||
{
|
{
|
||||||
ItRollsForwardToTheLatestVersion(AspNetCoreAppPackageName, minorVersion);
|
ItRollsForwardToTheLatestVersion(TestProjectCreator.AspNetCoreAppPackageName, minorVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory(Skip = "https://github.com/dotnet/cli/issues/10123")]
|
[Theory]
|
||||||
[ClassData(typeof(SupportedAspNetCoreVersions))]
|
[ClassData(typeof(SupportedAspNetCoreAllVersions))]
|
||||||
public void ItRollsForwardToTheLatestAspNetCoreAllVersion(string minorVersion)
|
public void ItRollsForwardToTheLatestAspNetCoreAllVersion(string minorVersion)
|
||||||
{
|
{
|
||||||
ItRollsForwardToTheLatestVersion(AspNetCoreAllPackageName, minorVersion);
|
ItRollsForwardToTheLatestVersion(TestProjectCreator.AspNetCoreAllPackageName, minorVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ItRollsForwardToTheLatestVersion(string packageName, string minorVersion)
|
public void ItRollsForwardToTheLatestVersion(string packageName, string minorVersion)
|
||||||
{
|
{
|
||||||
var _testInstance = TestAssets.Get("TestAppSimple")
|
var testProjectCreator = new TestProjectCreator()
|
||||||
.CreateInstance(identifier: packageName + "_" + minorVersion)
|
|
||||||
.WithSourceFiles();
|
|
||||||
|
|
||||||
string projectDirectory = _testInstance.Root.FullName;
|
|
||||||
|
|
||||||
string projectPath = Path.Combine(projectDirectory, "TestAppSimple.csproj");
|
|
||||||
|
|
||||||
var project = XDocument.Load(projectPath);
|
|
||||||
var ns = project.Root.Name.Namespace;
|
|
||||||
|
|
||||||
// Update TargetFramework to the right version of .NET Core
|
|
||||||
project.Root.Element(ns + "PropertyGroup")
|
|
||||||
.Element(ns + "TargetFramework")
|
|
||||||
.Value = "netcoreapp" + minorVersion;
|
|
||||||
|
|
||||||
var rid = Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment.GetRuntimeIdentifier();
|
|
||||||
|
|
||||||
// Set RuntimeIdentifier to opt in to roll-forward behavior
|
|
||||||
project.Root.Element(ns + "PropertyGroup")
|
|
||||||
.Add(new XElement(ns + "RuntimeIdentifier", rid));
|
|
||||||
|
|
||||||
if (packageName != NETCorePackageName)
|
|
||||||
{
|
{
|
||||||
// Add implicit ASP.NET reference
|
PackageName = packageName,
|
||||||
project.Root.Add(new XElement(ns + "ItemGroup",
|
MinorVersion = minorVersion,
|
||||||
new XElement(ns + "PackageReference", new XAttribute("Include", packageName))));
|
// Set RuntimeIdentifier to opt in to roll-forward behavior
|
||||||
}
|
RuntimeIdentifier = Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment.GetRuntimeIdentifier()
|
||||||
|
};
|
||||||
|
|
||||||
project.Save(projectPath);
|
var testInstance = testProjectCreator.Create();
|
||||||
|
|
||||||
|
string projectDirectory = testInstance.Root.FullName;
|
||||||
|
|
||||||
// Get the version rolled forward to
|
// Get the version rolled forward to
|
||||||
new RestoreCommand()
|
new RestoreCommand()
|
||||||
|
@ -97,29 +75,40 @@ namespace EndToEnd
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Directory.Delete(Path.Combine(projectDirectory, "obj"), true);
|
testProjectCreator.Identifier = "floating";
|
||||||
if (packageName == NETCorePackageName)
|
|
||||||
|
var floatingProjectInstance = testProjectCreator.Create();
|
||||||
|
|
||||||
|
var floatingProjectPath = Path.Combine(floatingProjectInstance.Root.FullName, "TestAppSimple.csproj");
|
||||||
|
|
||||||
|
var floatingProject = XDocument.Load(floatingProjectPath);
|
||||||
|
var ns = floatingProject.Root.Name.Namespace;
|
||||||
|
|
||||||
|
|
||||||
|
if (packageName == TestProjectCreator.NETCorePackageName)
|
||||||
{
|
{
|
||||||
// Float the RuntimeFrameworkVersion to get the latest version of the runtime available from feeds
|
// Float the RuntimeFrameworkVersion to get the latest version of the runtime available from feeds
|
||||||
project.Root.Element(ns + "PropertyGroup")
|
floatingProject.Root.Element(ns + "PropertyGroup")
|
||||||
.Add(new XElement(ns + "RuntimeFrameworkVersion", $"{minorVersion}.*"));
|
.Add(new XElement(ns + "RuntimeFrameworkVersion", $"{minorVersion}.*"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
project.Root.Element(ns + "ItemGroup")
|
floatingProject.Root.Element(ns + "ItemGroup")
|
||||||
.Element(ns + "PackageReference")
|
.Element(ns + "PackageReference")
|
||||||
.Add(new XAttribute("Version", $"{minorVersion}.*"),
|
.Add(new XAttribute("Version", $"{minorVersion}.*"),
|
||||||
new XAttribute("AllowExplicitVersion", "true"));
|
new XAttribute("AllowExplicitVersion", "true"));
|
||||||
}
|
}
|
||||||
|
|
||||||
project.Save(projectPath);
|
floatingProject.Save(floatingProjectPath);
|
||||||
|
|
||||||
new RestoreCommand()
|
new RestoreCommand()
|
||||||
.WithWorkingDirectory(projectDirectory)
|
.WithWorkingDirectory(floatingProjectInstance.Root.FullName)
|
||||||
.Execute()
|
.Execute()
|
||||||
.Should().Pass();
|
.Should().Pass();
|
||||||
|
|
||||||
var floatedAssetsFile = new LockFileFormat().Read(assetsFilePath);
|
string floatingAssetsFilePath = Path.Combine(floatingProjectInstance.Root.FullName, "obj", "project.assets.json");
|
||||||
|
|
||||||
|
var floatedAssetsFile = new LockFileFormat().Read(floatingAssetsFilePath);
|
||||||
|
|
||||||
var floatedVersion = GetPackageVersion(floatedAssetsFile, packageName);
|
var floatedVersion = GetPackageVersion(floatedAssetsFile, packageName);
|
||||||
floatedVersion.Should().NotBeNull();
|
floatedVersion.Should().NotBeNull();
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System.Collections;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
@ -19,6 +20,8 @@ namespace EndToEnd
|
||||||
"1.1",
|
"1.1",
|
||||||
"2.0",
|
"2.0",
|
||||||
"2.1",
|
"2.1",
|
||||||
|
// 2.2 currently disabled in master: https://github.com/dotnet/cli/issues/10125
|
||||||
|
// "2.2",
|
||||||
"3.0"
|
"3.0"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -40,4 +43,18 @@ namespace EndToEnd
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class SupportedAspNetCoreAllVersions : IEnumerable<object[]>
|
||||||
|
{
|
||||||
|
public IEnumerator<object[]> GetEnumerator() => Versions.Select(version => new object[] { version }).GetEnumerator();
|
||||||
|
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||||
|
|
||||||
|
public static IEnumerable<string> Versions
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return SupportedAspNetCoreVersions.Versions.Where(v => new Version(v).Major < 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
80
test/EndToEnd/TestProjectCreator.cs
Normal file
80
test/EndToEnd/TestProjectCreator.cs
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Text;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
using Microsoft.DotNet.TestFramework;
|
||||||
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||||
|
|
||||||
|
namespace EndToEnd
|
||||||
|
{
|
||||||
|
class TestProjectCreator
|
||||||
|
{
|
||||||
|
public const string NETCorePackageName = "Microsoft.NETCore.App";
|
||||||
|
public const string AspNetCoreAppPackageName = "Microsoft.AspNetCore.App";
|
||||||
|
public const string AspNetCoreAllPackageName = "Microsoft.AspNetCore.All";
|
||||||
|
|
||||||
|
|
||||||
|
public string TestName { get; set; }
|
||||||
|
public string Identifier { get; set; }
|
||||||
|
|
||||||
|
public string PackageName { get; set; } = NETCorePackageName;
|
||||||
|
|
||||||
|
public string MinorVersion { get; set; }
|
||||||
|
|
||||||
|
public string RuntimeIdentifier { get; set; }
|
||||||
|
|
||||||
|
public TestProjectCreator([CallerMemberName] string testName = null, string identifier = "")
|
||||||
|
{
|
||||||
|
TestName = testName;
|
||||||
|
Identifier = identifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TestAssetInstance Create()
|
||||||
|
{
|
||||||
|
var testInstance = TestBase.TestAssets.Get("TestAppSimple")
|
||||||
|
.CreateInstance(callingMethod: TestName, identifier: Identifier + PackageName + "_" + MinorVersion)
|
||||||
|
.WithSourceFiles();
|
||||||
|
|
||||||
|
string projectDirectory = testInstance.Root.FullName;
|
||||||
|
|
||||||
|
string projectPath = Path.Combine(projectDirectory, "TestAppSimple.csproj");
|
||||||
|
|
||||||
|
var project = XDocument.Load(projectPath);
|
||||||
|
var ns = project.Root.Name.Namespace;
|
||||||
|
|
||||||
|
// Update TargetFramework to the right version of .NET Core
|
||||||
|
project.Root.Element(ns + "PropertyGroup")
|
||||||
|
.Element(ns + "TargetFramework")
|
||||||
|
.Value = "netcoreapp" + MinorVersion;
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(RuntimeIdentifier))
|
||||||
|
{
|
||||||
|
project.Root.Element(ns + "PropertyGroup")
|
||||||
|
.Add(new XElement(ns + "RuntimeIdentifier", RuntimeIdentifier));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (PackageName != NETCorePackageName)
|
||||||
|
{
|
||||||
|
if (new Version(MinorVersion).Major < 3)
|
||||||
|
{
|
||||||
|
// Add ASP.NET PackageReference with implicit version for target framework versions prior to 3.0
|
||||||
|
project.Root.Add(new XElement(ns + "ItemGroup",
|
||||||
|
new XElement(ns + "PackageReference", new XAttribute("Include", PackageName))));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
project.Root.Add(new XElement(ns + "ItemGroup",
|
||||||
|
new XElement(ns + "FrameworkReference", new XAttribute("Include", PackageName))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
project.Save(projectPath);
|
||||||
|
|
||||||
|
return testInstance;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -42,7 +42,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static TestAssets TestAssets
|
public static TestAssets TestAssets
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
<RunSettings>
|
|
||||||
<DataCollectionRunSettings>
|
|
||||||
<DataCollectors>
|
|
||||||
<DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0">
|
|
||||||
<Configuration>
|
|
||||||
<CodeCoverage>
|
|
||||||
<!-- Match assembly file paths: -->
|
|
||||||
<ModulePaths>
|
|
||||||
<Exclude>
|
|
||||||
<ModulePath>.*Test.dll</ModulePath>
|
|
||||||
</Exclude>
|
|
||||||
</ModulePaths>
|
|
||||||
|
|
||||||
<!-- We recommend you do not change the following values: -->
|
|
||||||
<UseVerifiableInstrumentation>True</UseVerifiableInstrumentation>
|
|
||||||
<AllowLowIntegrityProcesses>True</AllowLowIntegrityProcesses>
|
|
||||||
<CollectFromChildProcesses>True</CollectFromChildProcesses>
|
|
||||||
<CollectAspDotNet>False</CollectAspDotNet>
|
|
||||||
|
|
||||||
</CodeCoverage>
|
|
||||||
</Configuration>
|
|
||||||
</DataCollector>
|
|
||||||
</DataCollectors>
|
|
||||||
</DataCollectionRunSettings>
|
|
||||||
</RunSettings>
|
|
Loading…
Reference in a new issue