2016-12-18 00:45:25 -08: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 ;
using System.Collections.Generic ;
using System.IO ;
using Microsoft.Build.Construction ;
using Microsoft.DotNet.Tools.Test.Utilities ;
using Xunit ;
using FluentAssertions ;
using System.Linq ;
namespace Microsoft.DotNet.Restore.Tests
{
public class GivenThatIWantToRestoreApp : TestBase
{
2017-04-03 22:15:40 -07:00
private static string RepoRootNuGetConfig = Path . Combine ( RepoDirectoriesProvider . RepoRoot , "NuGet.Config" ) ;
2016-12-18 00:45:25 -08:00
[Fact]
public void ItRestoresAppToSpecificDirectory ( )
{
2017-02-15 15:35:03 -08:00
var rootPath = TestAssets . CreateTestDirectory ( ) . FullName ;
2016-12-18 00:45:25 -08:00
string dir = "pkgs" ;
string fullPath = Path . GetFullPath ( Path . Combine ( rootPath , dir ) ) ;
2017-07-10 15:57:30 -07:00
string newArgs = $"console -o \" { rootPath } \ " --no-restore" ;
2017-01-31 17:31:37 -08:00
new NewCommandShim ( )
2016-12-18 00:45:25 -08:00
. WithWorkingDirectory ( rootPath )
2017-01-31 17:31:37 -08:00
. Execute ( newArgs )
2016-12-18 00:45:25 -08:00
. Should ( )
. Pass ( ) ;
2017-04-03 22:15:40 -07:00
string args = $"--configfile {RepoRootNuGetConfig} --packages \" { dir } \ "" ;
2016-12-18 00:45:25 -08:00
new RestoreCommand ( )
. WithWorkingDirectory ( rootPath )
. ExecuteWithCapturedOutput ( args )
. Should ( )
. Pass ( )
. And . NotHaveStdErr ( ) ;
Directory . Exists ( fullPath ) . Should ( ) . BeTrue ( ) ;
Directory . EnumerateFiles ( fullPath , "*.dll" , SearchOption . AllDirectories ) . Count ( ) . Should ( ) . BeGreaterThan ( 0 ) ;
}
[Fact]
public void ItRestoresLibToSpecificDirectory ( )
{
2017-02-15 15:35:03 -08:00
var rootPath = TestAssets . CreateTestDirectory ( ) . FullName ;
2016-12-18 00:45:25 -08:00
string dir = "pkgs" ;
string fullPath = Path . GetFullPath ( Path . Combine ( rootPath , dir ) ) ;
2017-07-10 15:57:30 -07:00
string newArgs = $"classlib -o \" { rootPath } \ " --no-restore" ;
2017-01-31 17:31:37 -08:00
new NewCommandShim ( )
2016-12-18 00:45:25 -08:00
. WithWorkingDirectory ( rootPath )
2017-01-31 17:31:37 -08:00
. Execute ( newArgs )
2016-12-18 00:45:25 -08:00
. Should ( )
. Pass ( ) ;
2017-04-03 22:15:40 -07:00
string args = $"--configfile {RepoRootNuGetConfig} --packages \" { dir } \ "" ;
2016-12-18 00:45:25 -08:00
new RestoreCommand ( )
. WithWorkingDirectory ( rootPath )
. ExecuteWithCapturedOutput ( args )
. Should ( )
. Pass ( )
. And . NotHaveStdErr ( ) ;
Directory . Exists ( fullPath ) . Should ( ) . BeTrue ( ) ;
Directory . EnumerateFiles ( fullPath , "*.dll" , SearchOption . AllDirectories ) . Count ( ) . Should ( ) . BeGreaterThan ( 0 ) ;
}
[Fact]
public void ItRestoresTestAppToSpecificDirectory ( )
{
2017-05-02 21:30:51 -07:00
var rootPath = TestAssets . Get ( "VSTestCore" ) . CreateInstance ( ) . WithSourceFiles ( ) . Root . FullName ;
2016-12-18 00:45:25 -08:00
string dir = "pkgs" ;
string fullPath = Path . GetFullPath ( Path . Combine ( rootPath , dir ) ) ;
2017-04-03 22:15:40 -07:00
string args = $"--configfile {RepoRootNuGetConfig} --packages \" { dir } \ "" ;
2016-12-18 00:45:25 -08:00
new RestoreCommand ( )
. WithWorkingDirectory ( rootPath )
. ExecuteWithCapturedOutput ( args )
. Should ( )
. Pass ( )
. And . NotHaveStdErr ( ) ;
Directory . Exists ( fullPath ) . Should ( ) . BeTrue ( ) ;
Directory . EnumerateFiles ( fullPath , "*.dll" , SearchOption . AllDirectories ) . Count ( ) . Should ( ) . BeGreaterThan ( 0 ) ;
}
2017-05-18 14:13:01 -07:00
[Fact]
public void ItRestoresWithTheSpecifiedVerbosity ( )
{
var rootPath = TestAssets . CreateTestDirectory ( ) . FullName ;
string dir = "pkgs" ;
string fullPath = Path . GetFullPath ( Path . Combine ( rootPath , dir ) ) ;
2017-07-10 15:57:30 -07:00
string newArgs = $"console -o \" { rootPath } \ " --no-restore" ;
2017-05-18 14:13:01 -07:00
new NewCommandShim ( )
. WithWorkingDirectory ( rootPath )
. Execute ( newArgs )
. Should ( )
. Pass ( ) ;
string args = $"--configfile {RepoRootNuGetConfig} --packages \" { dir } \ " --verbosity quiet" ;
new RestoreCommand ( )
. WithWorkingDirectory ( rootPath )
. ExecuteWithCapturedOutput ( args )
. Should ( )
. Pass ( )
. And . NotHaveStdErr ( )
. And . NotHaveStdOut ( ) ;
}
2016-12-18 00:45:25 -08:00
}
}