2016-12-20 13:04:01 -10: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 FluentAssertions ;
using Microsoft.DotNet.Cli.Sln.Internal ;
using Microsoft.DotNet.TestFramework ;
using Microsoft.DotNet.Tools.Test.Utilities ;
using System.IO ;
using System.Linq ;
2017-01-11 17:06:03 -08:00
using System.Runtime.CompilerServices ;
2016-12-20 13:04:01 -10:00
using Xunit ;
namespace Microsoft.DotNet.Migration.Tests
{
public class GivenThatIWantToMigrateSolutions : TestBase
{
2017-01-17 14:48:54 -08:00
[Theory]
[InlineData("PJAppWithSlnVersion14", "Visual Studio 15", "15.0.26114.2", "10.0.40219.1")]
[InlineData("PJAppWithSlnVersion15", "Visual Studio 15 Custom", "15.9.12345.4", "10.9.1234.5")]
[InlineData("PJAppWithSlnVersionUnknown", "Visual Studio 15", "15.0.26114.2", "10.0.40219.1")]
public void ItMigratesSlnAndEnsuresAtLeastVS15 (
string projectName ,
string productDescription ,
string visualStudioVersion ,
string minVisualStudioVersion )
{
var projectDirectory = TestAssets
. Get ( "NonRestoredTestProjects" , projectName )
. CreateInstance ( )
. WithSourceFiles ( )
. Root ;
var solutionRelPath = "TestApp.sln" ;
new DotnetCommand ( )
. WithWorkingDirectory ( projectDirectory )
. Execute ( $"migrate \" { solutionRelPath } \ "" )
. Should ( ) . Pass ( ) ;
SlnFile slnFile = SlnFile . Read ( Path . Combine ( projectDirectory . FullName , solutionRelPath ) ) ;
slnFile . ProductDescription . Should ( ) . Be ( productDescription ) ;
slnFile . VisualStudioVersion . Should ( ) . Be ( visualStudioVersion ) ;
slnFile . MinimumVisualStudioVersion . Should ( ) . Be ( minVisualStudioVersion ) ;
}
2016-12-20 13:04:01 -10:00
[Fact]
public void ItMigratesAndBuildsSln ( )
{
MigrateAndBuild (
"NonRestoredTestProjects" ,
2017-01-05 12:04:57 -10:00
"PJAppWithSlnAndXprojRefs" ) ;
2016-12-20 13:04:01 -10:00
}
[Fact]
public void WhenDirectoryAlreadyContainsCsprojFileItMigratesAndBuildsSln ( )
{
MigrateAndBuild (
"NonRestoredTestProjects" ,
2017-01-05 12:04:57 -10:00
"PJAppWithSlnAndXprojRefsAndUnrelatedCsproj" ) ;
2016-12-20 13:04:01 -10:00
}
[Fact]
public void WhenXprojReferencesCsprojAndSlnDoesNotItMigratesAndBuildsSln ( )
{
MigrateAndBuild (
"NonRestoredTestProjects" ,
2017-01-05 12:04:57 -10:00
"PJAppWithSlnAndXprojRefThatRefsCsprojWhereSlnDoesNotRefCsproj" ) ;
2016-12-20 13:04:01 -10:00
}
2017-01-11 17:06:03 -08:00
private void MigrateAndBuild ( string groupName , string projectName , [ CallerMemberName ] string callingMethod = "" , string identifier = "" )
2016-12-20 13:04:01 -10:00
{
var projectDirectory = TestAssets
. Get ( groupName , projectName )
2017-01-11 17:06:03 -08:00
. CreateInstance ( callingMethod : callingMethod , identifier : identifier )
2016-12-20 13:04:01 -10:00
. WithSourceFiles ( )
. Root ;
var solutionRelPath = Path . Combine ( "TestApp" , "TestApp.sln" ) ;
new DotnetCommand ( )
. WithWorkingDirectory ( projectDirectory )
. Execute ( $"migrate \" { solutionRelPath } \ "" )
. Should ( ) . Pass ( ) ;
new DotnetCommand ( )
. WithWorkingDirectory ( projectDirectory )
2017-01-03 11:06:51 -10:00
. Execute ( $"restore \" { solutionRelPath } \ "" )
2016-12-20 13:04:01 -10:00
. Should ( ) . Pass ( ) ;
2017-01-04 18:32:09 -10:00
//ISSUE: https://github.com/dotnet/cli/issues/5205
2016-12-21 14:06:06 -08:00
//new DotnetCommand()
// .WithWorkingDirectory(projectDirectory)
// .Execute($"build \"{solutionRelPath}\"")
// .Should().Pass();
2016-12-20 13:04:01 -10:00
SlnFile slnFile = SlnFile . Read ( Path . Combine ( projectDirectory . FullName , solutionRelPath ) ) ;
2017-01-04 18:32:09 -10:00
var nonSolutionFolderProjects = slnFile . Projects
. Where ( p = > p . TypeGuid ! = ProjectTypeGuids . SolutionFolderGuid ) ;
2016-12-20 13:04:01 -10:00
2017-01-04 18:32:09 -10:00
nonSolutionFolderProjects . Count ( ) . Should ( ) . Be ( 3 ) ;
var slnProject = nonSolutionFolderProjects . Where ( ( p ) = > p . Name = = "TestApp" ) . Single ( ) ;
2016-12-20 13:04:01 -10:00
slnProject . TypeGuid . Should ( ) . Be ( ProjectTypeGuids . CSharpProjectTypeGuid ) ;
slnProject . FilePath . Should ( ) . Be ( "TestApp.csproj" ) ;
2017-01-04 18:32:09 -10:00
slnProject = nonSolutionFolderProjects . Where ( ( p ) = > p . Name = = "TestLibrary" ) . Single ( ) ;
2016-12-20 13:04:01 -10:00
slnProject . TypeGuid . Should ( ) . Be ( ProjectTypeGuids . CSharpProjectTypeGuid ) ;
slnProject . FilePath . Should ( ) . Be ( Path . Combine ( ".." , "TestLibrary" , "TestLibrary.csproj" ) ) ;
2017-01-04 18:32:09 -10:00
slnProject = nonSolutionFolderProjects . Where ( ( p ) = > p . Name = = "subdir" ) . Single ( ) ;
2017-01-05 12:04:57 -10:00
//ISSUE: https://github.com/dotnet/sdk/issues/522
//Once we have that change migrate will always burn in the C# guid
//slnProject.TypeGuid.Should().Be(ProjectTypeGuids.CSharpProjectTypeGuid);
2016-12-20 13:04:01 -10:00
slnProject . FilePath . Should ( ) . Be ( Path . Combine ( "src" , "subdir" , "subdir.csproj" ) ) ;
}
}
}