2017-01-31 17:31:37 -08:00
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2016-12-13 14:15:35 -08:00
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System ;
using System.IO ;
2017-02-10 14:14:04 -06:00
using System.Linq ;
using System.Xml.Linq ;
2016-12-13 14:15:35 -08:00
using FluentAssertions ;
2017-02-10 14:14:04 -06:00
using Microsoft.DotNet.Tools.Test.Utilities ;
2017-03-23 11:21:39 -07:00
using Microsoft.Extensions.DependencyModel ;
2017-01-06 14:48:27 -08:00
using Xunit ;
2016-12-13 14:15:35 -08:00
namespace Microsoft.DotNet.New.Tests
{
public class GivenThatIWantANewApp : TestBase
{
[Fact]
public void When_dotnet_new_is_invoked_mupliple_times_it_should_fail ( )
{
2017-02-15 15:35:03 -08:00
var rootPath = TestAssets . CreateTestDirectory ( ) . FullName ;
2016-12-13 14:15:35 -08:00
2017-02-10 14:14:04 -06:00
new NewCommand ( )
. WithWorkingDirectory ( rootPath )
2017-07-10 15:57:30 -07:00
. Execute ( $"console --debug:ephemeral-hive --no-restore" ) ;
2016-12-13 14:15:35 -08:00
DateTime expectedState = Directory . GetLastWriteTime ( rootPath ) ;
2017-02-10 14:14:04 -06:00
var result = new NewCommand ( )
. WithWorkingDirectory ( rootPath )
2017-07-10 15:57:30 -07:00
. ExecuteWithCapturedOutput ( $"console --debug:ephemeral-hive --no-restore" ) ;
2016-12-13 14:15:35 -08:00
DateTime actualState = Directory . GetLastWriteTime ( rootPath ) ;
Assert . Equal ( expectedState , actualState ) ;
2017-01-31 17:31:37 -08:00
result . Should ( ) . Fail ( ) ;
}
[Fact]
public void RestoreDoesNotUseAnyCliProducedPackagesOnItsTemplates ( )
{
string [ ] cSharpTemplates = new [ ] { "console" , "classlib" , "mstest" , "xunit" , "web" , "mvc" , "webapi" } ;
2017-02-15 15:35:03 -08:00
var rootPath = TestAssets . CreateTestDirectory ( ) . FullName ;
2017-01-31 17:31:37 -08:00
var packagesDirectory = Path . Combine ( rootPath , "packages" ) ;
foreach ( string cSharpTemplate in cSharpTemplates )
{
var projectFolder = Path . Combine ( rootPath , cSharpTemplate + "1" ) ;
Directory . CreateDirectory ( projectFolder ) ;
CreateAndRestoreNewProject ( cSharpTemplate , projectFolder , packagesDirectory ) ;
}
Directory . EnumerateFiles ( packagesDirectory , $"*.nupkg" , SearchOption . AllDirectories )
. Should ( ) . NotContain ( p = > p . Contains ( "Microsoft.DotNet.Cli.Utils" ) ) ;
}
private void CreateAndRestoreNewProject (
string projectType ,
string projectFolder ,
string packagesDirectory )
{
2017-04-03 10:45:35 -07:00
var repoRootNuGetConfig = Path . Combine ( RepoDirectoriesProvider . RepoRoot , "NuGet.Config" ) ;
2017-02-10 14:14:04 -06:00
new NewCommand ( )
. WithWorkingDirectory ( projectFolder )
2017-07-10 15:57:30 -07:00
. Execute ( $"{projectType} --debug:ephemeral-hive --no-restore" )
2017-01-31 17:31:37 -08:00
. Should ( ) . Pass ( ) ;
2017-06-14 00:27:26 -07:00
// https://github.com/dotnet/templating/issues/946 - remove DisableImplicitAssetTargetFallback once this is fixed.
2017-01-31 17:31:37 -08:00
new RestoreCommand ( )
. WithWorkingDirectory ( projectFolder )
2017-06-14 00:27:26 -07:00
. Execute ( $"--configfile {repoRootNuGetConfig} --packages {packagesDirectory} /p:DisableImplicitAssetTargetFallback=true" )
2017-01-31 17:31:37 -08:00
. Should ( ) . Pass ( ) ;
2016-12-13 14:15:35 -08:00
}
2017-02-10 14:14:04 -06:00
2017-03-23 11:21:39 -07:00
[Theory]
2017-11-28 12:54:06 -08:00
[InlineData("console", "microsoft.netcore.app", "2.0.0")]
[InlineData("classlib", "netstandard.library", "2.0.1")]
public void NewProjectRestoresCorrectPackageVersion ( string type , string packageName , string expectedVersion )
2017-02-10 14:14:04 -06:00
{
2017-03-27 17:46:32 -07:00
var rootPath = TestAssets . CreateTestDirectory ( identifier : $"_{type}" ) . FullName ;
2017-02-10 14:14:04 -06:00
var packagesDirectory = Path . Combine ( rootPath , "packages" ) ;
2017-03-23 11:21:39 -07:00
var projectName = "Project" ;
2017-04-03 10:45:35 -07:00
var repoRootNuGetConfig = Path . Combine ( RepoDirectoriesProvider . RepoRoot , "NuGet.Config" ) ;
2017-02-10 14:14:04 -06:00
new NewCommand ( )
. WithWorkingDirectory ( rootPath )
2017-07-10 15:57:30 -07:00
. Execute ( $"{type} --name {projectName} -o . --debug:ephemeral-hive --no-restore" )
2017-02-10 14:14:04 -06:00
. Should ( ) . Pass ( ) ;
new RestoreCommand ( )
. WithWorkingDirectory ( rootPath )
2017-04-03 10:45:35 -07:00
. Execute ( $"--configfile {repoRootNuGetConfig} --packages {packagesDirectory}" )
2017-02-10 14:14:04 -06:00
. Should ( ) . Pass ( ) ;
2017-03-23 11:21:39 -07:00
new DirectoryInfo ( Path . Combine ( packagesDirectory , packageName ) )
2017-02-10 14:14:04 -06:00
. Should ( ) . Exist ( )
. And . HaveDirectory ( expectedVersion ) ;
}
2016-12-13 14:15:35 -08:00
}
}