2016-02-26 10:54:17 -08:00
using System.Linq ;
2016-02-23 02:34:27 -08:00
using Microsoft.DotNet.ProjectModel.Graph ;
using Microsoft.DotNet.ProjectModel.Resolution ;
2016-02-26 10:54:17 -08:00
using Microsoft.DotNet.TestFramework ;
using Microsoft.DotNet.Tools.Test.Utilities ;
2016-07-26 13:20:23 -05:00
using NuGet.Configuration ;
2016-02-23 02:34:27 -08:00
using NuGet.Frameworks ;
using NuGet.Versioning ;
using Xunit ;
2016-05-03 09:08:57 -07:00
using System.IO ;
2016-02-23 02:34:27 -08:00
namespace Microsoft.DotNet.ProjectModel.Tests
{
2016-02-26 10:54:17 -08:00
public class PackageDependencyProviderTests : TestBase
2016-02-23 02:34:27 -08:00
{
[Fact]
public void GetDescriptionShouldNotModifyTarget ( )
{
2016-07-26 13:20:23 -05:00
var provider = new PackageDependencyProvider ( NuGetPathContext . Create ( "/foo/packages" ) , new FrameworkReferenceResolver ( "/foo/references" ) ) ;
2016-02-23 02:34:27 -08:00
var package = new LockFilePackageLibrary ( ) ;
package . Name = "Something" ;
package . Version = NuGetVersion . Parse ( "1.0.0" ) ;
package . Files . Add ( "lib/dotnet/_._" ) ;
package . Files . Add ( "runtimes/any/native/Microsoft.CSharp.CurrentVersion.targets" ) ;
var target = new LockFileTargetLibrary ( ) ;
target . Name = "Something" ;
target . Version = package . Version ;
target . RuntimeAssemblies . Add ( "lib/dotnet/_._" ) ;
target . CompileTimeAssemblies . Add ( "lib/dotnet/_._" ) ;
target . NativeLibraries . Add ( "runtimes/any/native/Microsoft.CSharp.CurrentVersion.targets" ) ;
2016-04-12 17:29:07 -07:00
var p1 = provider . GetDescription ( NuGetFramework . Parse ( "netcoreapp1.0" ) , package , target ) ;
var p2 = provider . GetDescription ( NuGetFramework . Parse ( "netcoreapp1.0" ) , package , target ) ;
2016-02-23 02:34:27 -08:00
Assert . True ( p1 . Compatible ) ;
Assert . True ( p2 . Compatible ) ;
Assert . Empty ( p1 . CompileTimeAssemblies ) ;
Assert . Empty ( p1 . RuntimeAssemblies ) ;
2016-02-26 10:54:17 -08:00
2016-02-23 02:34:27 -08:00
Assert . Empty ( p2 . CompileTimeAssemblies ) ;
Assert . Empty ( p2 . RuntimeAssemblies ) ;
}
2016-02-26 10:54:17 -08:00
2016-05-03 02:00:12 -07:00
[Fact]
public void HasCompileTimePlaceholderChecksAllCompileTimeAssets ( )
{
2016-07-26 13:20:23 -05:00
var provider = new PackageDependencyProvider ( NuGetPathContext . Create ( "/foo/packages" ) , new FrameworkReferenceResolver ( "/foo/references" ) ) ;
2016-05-03 02:00:12 -07:00
var package = new LockFilePackageLibrary ( ) ;
package . Name = "Something" ;
package . Version = NuGetVersion . Parse ( "1.0.0" ) ;
package . Files . Add ( "lib/net46/_._" ) ;
package . Files . Add ( "lib/net46/Something.dll" ) ;
var target = new LockFileTargetLibrary ( ) ;
target . Name = "Something" ;
target . Version = package . Version ;
target . RuntimeAssemblies . Add ( "lib/net46/_._" ) ;
target . RuntimeAssemblies . Add ( "lib/net46/Something.dll" ) ;
target . CompileTimeAssemblies . Add ( "lib/net46/_._" ) ;
target . CompileTimeAssemblies . Add ( "lib/net46/Something.dll" ) ;
var p1 = provider . GetDescription ( NuGetFramework . Parse ( "net46" ) , package , target ) ;
Assert . False ( p1 . HasCompileTimePlaceholder ) ;
Assert . Equal ( 1 , p1 . CompileTimeAssemblies . Count ( ) ) ;
Assert . Equal ( 1 , p1 . RuntimeAssemblies . Count ( ) ) ;
Assert . Equal ( "lib/net46/Something.dll" , p1 . CompileTimeAssemblies . First ( ) . Path ) ;
Assert . Equal ( "lib/net46/Something.dll" , p1 . RuntimeAssemblies . First ( ) . Path ) ;
}
[Fact]
public void HasCompileTimePlaceholderReturnsFalseIfEmpty ( )
{
2016-07-26 13:20:23 -05:00
var provider = new PackageDependencyProvider ( NuGetPathContext . Create ( "/foo/packages" ) , new FrameworkReferenceResolver ( "/foo/references" ) ) ;
2016-05-03 02:00:12 -07:00
var package = new LockFilePackageLibrary ( ) ;
package . Name = "Something" ;
package . Version = NuGetVersion . Parse ( "1.0.0" ) ;
var target = new LockFileTargetLibrary ( ) ;
target . Name = "Something" ;
target . Version = package . Version ;
var p1 = provider . GetDescription ( NuGetFramework . Parse ( "net46" ) , package , target ) ;
Assert . False ( p1 . HasCompileTimePlaceholder ) ;
Assert . Equal ( 0 , p1 . CompileTimeAssemblies . Count ( ) ) ;
Assert . Equal ( 0 , p1 . RuntimeAssemblies . Count ( ) ) ;
}
2016-04-07 21:32:19 -07:00
[Theory]
2016-04-22 15:01:56 -07:00
[InlineData("TestMscorlibReference", true)]
[InlineData("TestMscorlibReference", false)]
[InlineData("TestMicrosoftCSharpReference", true)]
[InlineData("TestMicrosoftCSharpReference", false)]
[InlineData("TestSystemReference", true)]
[InlineData("TestSystemReference", false)]
[InlineData("TestSystemCoreReference", true)]
[InlineData("TestSystemCoreReference", false)]
2016-04-07 21:32:19 -07:00
public void TestDuplicateDefaultDesktopReferences ( string sampleName , bool withLockFile )
2016-02-26 10:54:17 -08:00
{
2016-04-07 21:32:19 -07:00
var instance = TestAssetsManager . CreateTestInstance ( sampleName ) ;
if ( withLockFile )
{
instance = instance . WithLockFiles ( ) ;
}
2016-02-26 10:54:17 -08:00
var context = new ProjectContextBuilder ( ) . WithProjectDirectory ( instance . TestRoot )
2016-04-07 21:32:19 -07:00
. WithTargetFramework ( "net451" )
2016-02-26 10:54:17 -08:00
. Build ( ) ;
Assert . Equal ( 4 , context . RootProject . Dependencies . Count ( ) ) ;
}
2016-04-22 15:01:56 -07:00
2016-04-21 09:05:55 -07:00
[Fact]
public void NoDuplicateReferencesWhenFrameworkMissing ( )
{
var instance = TestAssetsManager . CreateTestInstance ( "TestMicrosoftCSharpReferenceMissingFramework" )
. WithLockFiles ( ) ;
var context = new ProjectContextBuilder ( ) . WithProjectDirectory ( instance . TestRoot )
. WithTargetFramework ( "net99" )
. Build ( ) ;
2016-04-21 21:47:20 -07:00
// Will fail with dupes if any
2016-07-28 21:17:32 -07:00
context . LibraryManager . GetLibraries ( ) . ToDictionary ( l = > l . Identity . Name , StringComparer . OrdinalIgnoreCase ) ;
2016-04-21 09:05:55 -07:00
}
2016-04-22 15:01:56 -07:00
2016-04-21 21:47:20 -07:00
[Fact]
public void NetCore50ShouldNotResolveFrameworkAssemblies ( )
{
var instance = TestAssetsManager . CreateTestInstance ( "TestMicrosoftCSharpReferenceMissingFramework" )
. WithLockFiles ( ) ;
var context = new ProjectContextBuilder ( ) . WithProjectDirectory ( instance . TestRoot )
. WithTargetFramework ( "netcore50" )
. Build ( ) ;
var diagnostics = context . LibraryManager . GetAllDiagnostics ( ) ;
Assert . False ( diagnostics . Any ( d = > d . ErrorCode = = ErrorCodes . DOTNET1011 ) ) ;
}
2016-05-03 09:08:57 -07:00
[Fact]
public void NoDuplicatesWithProjectAndReferenceAssemblyWithSameName ( )
{
var instance = TestAssetsManager . CreateTestInstance ( "DuplicatedReferenceAssembly" )
. WithLockFiles ( ) ;
var context = new ProjectContextBuilder ( ) . WithProjectDirectory ( Path . Combine ( instance . TestRoot , "TestApp" ) )
. WithTargetFramework ( "net461" )
. Build ( ) ;
// Will fail with dupes if any
2016-07-28 21:17:32 -07:00
context . LibraryManager . GetLibraries ( ) . ToDictionary ( l = > l . Identity . Name , StringComparer . OrdinalIgnoreCase ) ;
2016-05-03 09:08:57 -07:00
}
2016-02-23 02:34:27 -08:00
}
}