2020-05-06 09:59:23 -05:00
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System ;
2018-06-21 10:40:44 -07:00
using System.IO ;
using System.Linq ;
using FluentAssertions ;
using Microsoft.DotNet.Tools.Test.Utilities ;
using NuGet.ProjectModel ;
using NuGet.Versioning ;
using Xunit ;
namespace EndToEnd
{
public class GivenFrameworkDependentApps : TestBase
{
[Theory]
[ClassData(typeof(SupportedNetCoreAppVersions))]
2018-09-26 18:54:17 -07:00
public void ItDoesNotRollForwardToTheLatestVersionOfNetCore ( string minorVersion )
{
2019-10-17 09:47:44 -07:00
if ( minorVersion = = "3.0" | | minorVersion = = "3.1" | | minorVersion = = "5.0" )
2019-02-20 16:29:03 -08:00
{
// https://github.com/dotnet/core-sdk/issues/621
return ;
}
2018-11-08 12:11:30 -08:00
ItDoesNotRollForwardToTheLatestVersion ( TestProjectCreator . NETCorePackageName , minorVersion ) ;
2018-09-26 18:54:17 -07:00
}
2018-11-08 12:11:30 -08:00
[Theory]
2018-09-26 18:54:17 -07:00
[ClassData(typeof(SupportedAspNetCoreVersions))]
public void ItDoesNotRollForwardToTheLatestVersionOfAspNetCoreApp ( string minorVersion )
{
2019-10-17 09:47:44 -07:00
if ( minorVersion = = "3.0" | | minorVersion = = "3.1" | | minorVersion = = "5.0" )
2019-02-20 16:29:03 -08:00
{
// https://github.com/dotnet/core-sdk/issues/621
return ;
}
2018-11-08 12:11:30 -08:00
ItDoesNotRollForwardToTheLatestVersion ( TestProjectCreator . AspNetCoreAppPackageName , minorVersion ) ;
2018-09-26 18:54:17 -07:00
}
2018-11-08 12:11:30 -08:00
[Theory]
[ClassData(typeof(SupportedAspNetCoreAllVersions))]
2018-09-26 18:54:17 -07:00
public void ItDoesNotRollForwardToTheLatestVersionOfAspNetCoreAll ( string minorVersion )
{
2018-11-08 12:11:30 -08:00
ItDoesNotRollForwardToTheLatestVersion ( TestProjectCreator . AspNetCoreAllPackageName , minorVersion ) ;
2018-09-26 18:54:17 -07:00
}
2018-10-22 19:59:58 -07:00
internal void ItDoesNotRollForwardToTheLatestVersion ( string packageName , string minorVersion )
2018-06-21 10:40:44 -07:00
{
2018-11-08 12:11:30 -08:00
var testProjectCreator = new TestProjectCreator ( )
{
PackageName = packageName ,
MinorVersion = minorVersion ,
} ;
var _testInstance = testProjectCreator . Create ( ) ;
2018-06-21 10:40:44 -07:00
string projectDirectory = _testInstance . Root . FullName ;
string projectPath = Path . Combine ( projectDirectory , "TestAppSimple.csproj" ) ;
// Get the resolved version of .NET Core
new RestoreCommand ( )
. WithWorkingDirectory ( projectDirectory )
. Execute ( )
. Should ( ) . Pass ( ) ;
string assetsFilePath = Path . Combine ( projectDirectory , "obj" , "project.assets.json" ) ;
var assetsFile = new LockFileFormat ( ) . Read ( assetsFilePath ) ;
2018-09-26 18:54:17 -07:00
var versionInAssertsJson = GetPackageVersion ( assetsFile , packageName ) ;
2018-06-21 10:40:44 -07:00
versionInAssertsJson . Should ( ) . NotBeNull ( ) ;
if ( versionInAssertsJson . IsPrerelease & & versionInAssertsJson . Patch = = 0 )
{
// if the bundled version is, for example, a prerelease of
// .NET Core 2.1.1, that we don't roll forward to that prerelease
// version for framework-dependent deployments.
return ;
}
2018-09-26 18:54:17 -07:00
versionInAssertsJson . ToNormalizedString ( ) . Should ( ) . BeEquivalentTo ( GetExpectedVersion ( packageName , minorVersion ) ) ;
2018-06-21 10:40:44 -07:00
}
2018-09-26 18:54:17 -07:00
private static NuGetVersion GetPackageVersion ( LockFile lockFile , string packageName )
2018-06-21 10:40:44 -07:00
{
return lockFile ? . Targets ? . SingleOrDefault ( t = > t . RuntimeIdentifier = = null )
? . Libraries ? . SingleOrDefault ( l = >
2018-09-26 18:54:17 -07:00
string . Compare ( l . Name , packageName , StringComparison . CurrentCultureIgnoreCase ) = = 0 )
2018-06-21 10:40:44 -07:00
? . Version ;
}
2018-09-26 18:54:17 -07:00
public string GetExpectedVersion ( string packageName , string minorVersion )
2018-06-21 10:40:44 -07:00
{
if ( minorVersion . StartsWith ( "1.0" ) )
{
return "1.0.5" ; // special case for 1.0
}
else if ( minorVersion . StartsWith ( "1.1" ) )
{
return "1.1.2" ; // special case for 1.1
}
else
{
2018-09-26 18:54:17 -07:00
// 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.
2018-11-08 12:11:30 -08:00
if ( packageName = = TestProjectCreator . AspNetCoreAppPackageName | |
packageName = = TestProjectCreator . AspNetCoreAllPackageName )
2018-09-26 18:54:17 -07:00
{
if ( minorVersion = = "2.1" )
{
return "2.1.1" ;
}
}
2018-06-21 10:40:44 -07:00
var parsed = NuGetVersion . Parse ( minorVersion ) ;
return new NuGetVersion ( parsed . Major , parsed . Minor , 0 ) . ToNormalizedString ( ) ;
}
}
}
}