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))]
|
||||
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))]
|
||||
public void ItDoesNotRollForwardToTheLatestVersionOfAspNetCoreApp(string minorVersion)
|
||||
{
|
||||
ItDoesNotRollForwardToTheLatestVersion(GivenSelfContainedAppsRollForward.AspNetCoreAppPackageName, minorVersion);
|
||||
ItDoesNotRollForwardToTheLatestVersion(TestProjectCreator.AspNetCoreAppPackageName, minorVersion);
|
||||
}
|
||||
|
||||
[Theory(Skip = "https://github.com/dotnet/cli/issues/10123")]
|
||||
[ClassData(typeof(SupportedAspNetCoreVersions))]
|
||||
[Theory]
|
||||
[ClassData(typeof(SupportedAspNetCoreAllVersions))]
|
||||
public void ItDoesNotRollForwardToTheLatestVersionOfAspNetCoreAll(string minorVersion)
|
||||
{
|
||||
ItDoesNotRollForwardToTheLatestVersion(GivenSelfContainedAppsRollForward.AspNetCoreAllPackageName, minorVersion);
|
||||
ItDoesNotRollForwardToTheLatestVersion(TestProjectCreator.AspNetCoreAllPackageName, minorVersion);
|
||||
}
|
||||
|
||||
public void ItDoesNotRollForwardToTheLatestVersion(string packageName, string minorVersion)
|
||||
{
|
||||
var _testInstance = TestAssets.Get("TestAppSimple")
|
||||
.CreateInstance(identifier: packageName + "_" + minorVersion)
|
||||
// scope the feed to only dotnet-core feed to avoid flaky when different feed has a newer / lower version
|
||||
.WithNuGetConfig(new RepoDirectoriesProvider().TestPackages)
|
||||
.WithSourceFiles();
|
||||
var testProjectCreator = new TestProjectCreator()
|
||||
{
|
||||
PackageName = packageName,
|
||||
MinorVersion = minorVersion,
|
||||
};
|
||||
|
||||
var _testInstance = testProjectCreator.Create();
|
||||
|
||||
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 (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
|
||||
new RestoreCommand()
|
||||
.WithWorkingDirectory(projectDirectory)
|
||||
|
@ -110,8 +95,8 @@ namespace EndToEnd
|
|||
{
|
||||
// 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.
|
||||
if (packageName == GivenSelfContainedAppsRollForward.AspNetCoreAppPackageName ||
|
||||
packageName == GivenSelfContainedAppsRollForward.AspNetCoreAllPackageName)
|
||||
if (packageName == TestProjectCreator.AspNetCoreAppPackageName ||
|
||||
packageName == TestProjectCreator.AspNetCoreAllPackageName)
|
||||
{
|
||||
if (minorVersion == "2.1")
|
||||
{
|
||||
|
|
|
@ -16,65 +16,43 @@ namespace EndToEnd
|
|||
{
|
||||
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
|
||||
// verify that we are covering the latest release of .NET Core
|
||||
[ClassData(typeof(SupportedNetCoreAppVersions))]
|
||||
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))]
|
||||
public void ItRollsForwardToTheLatestAspNetCoreAppVersion(string minorVersion)
|
||||
{
|
||||
ItRollsForwardToTheLatestVersion(AspNetCoreAppPackageName, minorVersion);
|
||||
ItRollsForwardToTheLatestVersion(TestProjectCreator.AspNetCoreAppPackageName, minorVersion);
|
||||
}
|
||||
|
||||
[Theory(Skip = "https://github.com/dotnet/cli/issues/10123")]
|
||||
[ClassData(typeof(SupportedAspNetCoreVersions))]
|
||||
[Theory]
|
||||
[ClassData(typeof(SupportedAspNetCoreAllVersions))]
|
||||
public void ItRollsForwardToTheLatestAspNetCoreAllVersion(string minorVersion)
|
||||
{
|
||||
ItRollsForwardToTheLatestVersion(AspNetCoreAllPackageName, minorVersion);
|
||||
ItRollsForwardToTheLatestVersion(TestProjectCreator.AspNetCoreAllPackageName, minorVersion);
|
||||
}
|
||||
|
||||
public void ItRollsForwardToTheLatestVersion(string packageName, string minorVersion)
|
||||
{
|
||||
var _testInstance = TestAssets.Get("TestAppSimple")
|
||||
.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)
|
||||
var testProjectCreator = new TestProjectCreator()
|
||||
{
|
||||
// Add implicit ASP.NET reference
|
||||
project.Root.Add(new XElement(ns + "ItemGroup",
|
||||
new XElement(ns + "PackageReference", new XAttribute("Include", packageName))));
|
||||
}
|
||||
PackageName = packageName,
|
||||
MinorVersion = minorVersion,
|
||||
// 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
|
||||
new RestoreCommand()
|
||||
|
@ -97,29 +75,40 @@ namespace EndToEnd
|
|||
return;
|
||||
}
|
||||
|
||||
Directory.Delete(Path.Combine(projectDirectory, "obj"), true);
|
||||
if (packageName == NETCorePackageName)
|
||||
testProjectCreator.Identifier = "floating";
|
||||
|
||||
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
|
||||
project.Root.Element(ns + "PropertyGroup")
|
||||
floatingProject.Root.Element(ns + "PropertyGroup")
|
||||
.Add(new XElement(ns + "RuntimeFrameworkVersion", $"{minorVersion}.*"));
|
||||
}
|
||||
else
|
||||
{
|
||||
project.Root.Element(ns + "ItemGroup")
|
||||
floatingProject.Root.Element(ns + "ItemGroup")
|
||||
.Element(ns + "PackageReference")
|
||||
.Add(new XAttribute("Version", $"{minorVersion}.*"),
|
||||
new XAttribute("AllowExplicitVersion", "true"));
|
||||
}
|
||||
|
||||
project.Save(projectPath);
|
||||
floatingProject.Save(floatingProjectPath);
|
||||
|
||||
new RestoreCommand()
|
||||
.WithWorkingDirectory(projectDirectory)
|
||||
.WithWorkingDirectory(floatingProjectInstance.Root.FullName)
|
||||
.Execute()
|
||||
.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);
|
||||
floatedVersion.Should().NotBeNull();
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System.Collections;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
@ -19,6 +20,8 @@ namespace EndToEnd
|
|||
"1.1",
|
||||
"2.0",
|
||||
"2.1",
|
||||
// 2.2 currently disabled in master: https://github.com/dotnet/cli/issues/10125
|
||||
// "2.2",
|
||||
"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
|
||||
{
|
||||
|
|
|
@ -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