2016-03-24 21:52:46 -07: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.IO ;
using System.Linq ;
using FluentAssertions ;
using Xunit ;
using Microsoft.DotNet.Tools.Test.Utilities ;
2016-03-30 11:41:16 -07:00
using NuGet.ProjectModel ;
2016-03-24 21:52:46 -07:00
namespace Microsoft.DotNet.ProjectModel.Tests
{
public class LockFilePatchingTests : TestBase
{
2016-03-30 11:41:16 -07:00
private static string ExportFilesRoot = > Path . Combine ( RepoRoot , "TestAssets" , "LockFiles" , "ExportFiles" ) ;
2016-09-26 13:47:55 -07:00
2016-03-31 14:06:04 -07:00
[Fact]
public void TestMissingExportUnderDesignTime ( )
{
var lockFilePath = GetLockFilePath ( "invalid_nofragment" ) ;
// not throw under design time scenario
2016-09-26 13:47:55 -07:00
Assert . NotNull ( new LockFileFormat ( ) . Read ( lockFilePath ) ) ;
2016-03-24 21:52:46 -07:00
}
2016-03-31 14:06:04 -07:00
[Fact]
public void TestMissingExportsUnderDesignTime ( )
{
var lockFilePath = GetLockFilePath ( "invalid_missing-exports" ) ;
// not throw under design time scenario
2016-09-26 13:47:55 -07:00
Assert . NotNull ( new LockFileFormat ( ) . Read ( lockFilePath ) ) ;
2016-03-24 21:52:46 -07:00
}
2016-09-26 13:47:55 -07:00
2016-03-31 14:06:04 -07:00
[Fact]
public void TestMissmatchingFileVersionsUnderDesignTime ( )
{
var lockFilePath = GetLockFilePath ( "invalid_missmatching-versions" ) ;
2016-09-26 13:47:55 -07:00
Assert . NotNull ( new LockFileFormat ( ) . Read ( lockFilePath ) ) ;
2016-03-31 14:06:04 -07:00
}
2016-07-26 13:20:23 -05:00
[Fact]
public void TestPackageFoldersLoadCorrectly ( )
{
var lockFilePath = GetLockFilePath ( "valid" ) ;
2016-09-26 13:47:55 -07:00
var lockFile = new LockFileFormat ( ) . Read ( lockFilePath ) ;
2016-07-26 13:20:23 -05:00
Assert . Equal ( 2 , lockFile . PackageFolders . Count ) ;
Assert . Equal ( "/foo/packages" , lockFile . PackageFolders [ 0 ] . Path ) ;
Assert . Equal ( "/foo/packages2" , lockFile . PackageFolders [ 1 ] . Path ) ;
}
2016-09-26 13:47:55 -07:00
private static int LibraryNumberFromName ( LockFileTargetLibrary library )
2016-03-30 11:41:16 -07:00
{
var libraryName = library . Name ;
return ( int ) char . GetNumericValue ( libraryName [ libraryName . Length - 1 ] ) ;
}
2016-09-26 13:47:55 -07:00
private static void AssertTargetLibrary ( LockFileTargetLibrary library )
2016-03-24 21:52:46 -07:00
{
2016-03-30 11:41:16 -07:00
var libraryNumber = LibraryNumberFromName ( library ) ;
library . Type . Should ( ) . Be ( "project" ) ;
2016-03-24 21:52:46 -07:00
2016-03-30 11:41:16 -07:00
library . Name . Should ( ) . Be ( "ClassLibrary" + libraryNumber ) ;
library . Version . ToNormalizedString ( ) . Should ( ) . Be ( "1.0.0" ) ;
2016-03-24 21:52:46 -07:00
2016-03-30 11:41:16 -07:00
var dll = $"bin/Debug/ClassLibrary{libraryNumber}.dll" ;
2016-03-24 21:52:46 -07:00
dll = dll . Replace ( '/' , Path . DirectorySeparatorChar ) ;
2016-03-30 11:41:16 -07:00
library . CompileTimeAssemblies . Count . Should ( ) . Be ( 1 ) ;
library . CompileTimeAssemblies . ElementAt ( 0 ) . Path . Should ( ) . Be ( dll ) ;
2016-03-24 21:52:46 -07:00
2016-03-30 11:41:16 -07:00
library . RuntimeAssemblies . Count . Should ( ) . Be ( 1 ) ;
library . RuntimeAssemblies . ElementAt ( 0 ) . Path . Should ( ) . Be ( dll ) ;
2016-03-24 21:52:46 -07:00
}
2016-03-30 11:41:16 -07:00
private static string GetLockFilePath ( string exportSample )
2016-03-24 21:52:46 -07:00
{
return Path . Combine ( ExportFilesRoot , exportSample , "project.lock.json" ) ;
}
}
}