2017-03-02 21:04:03 -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 ;
2016-08-22 12:24:10 -07:00
using System.Collections.Generic ;
using System.Linq ;
using System.Threading.Tasks ;
using Microsoft.Build.Construction ;
using Microsoft.DotNet.ProjectJsonMigration ;
2016-10-27 18:46:43 -07:00
using Microsoft.DotNet.Internal.ProjectModel ;
2016-08-22 12:24:10 -07:00
using Microsoft.DotNet.Tools.Test.Utilities ;
using NuGet.Frameworks ;
using Xunit ;
using FluentAssertions ;
2016-08-23 13:50:05 -07:00
using Microsoft.DotNet.ProjectJsonMigration.Rules ;
2016-08-22 12:24:10 -07:00
using Microsoft.DotNet.ProjectJsonMigration.Tests ;
2016-09-14 15:30:11 -07:00
namespace Microsoft.DotNet.ProjectJsonMigration.Tests
2016-08-22 12:24:10 -07:00
{
public class GivenThatIWantToMigrateConfigurations : TestBase
{
[Fact]
2017-01-05 11:46:02 -08:00
public void ConfigurationBuildOptionsProduceExpectedPropertiesInAGroupWithACondition ( )
2016-08-22 12:24:10 -07:00
{
var mockProj = RunConfigurationsRuleOnPj ( @ "
{
"" configurations "" : {
"" testconfig "" : {
"" buildOptions "" : {
"" emitEntryPoint "" : "" true "" ,
"" debugType "" : "" full ""
}
}
}
} ");
mockProj . Properties . Count (
2016-08-23 13:50:05 -07:00
prop = > prop . Name = = "OutputType" | | prop . Name = = "DebugType" ) . Should ( ) . Be ( 2 ) ;
2016-08-22 12:24:10 -07:00
mockProj . Properties . First ( p = > p . Name = = "OutputType" )
. Parent . Condition . Should ( )
. Contain ( "'$(Configuration)' == 'testconfig'" ) ;
}
2016-09-08 14:40:46 -07:00
[Fact]
2017-01-05 11:46:02 -08:00
public void FrameworksBuildOptionsProduceExpectedPropertiesInAGroupWithACondition ( )
2016-09-08 14:40:46 -07:00
{
var mockProj = RunConfigurationsRuleOnPj ( @ "
{
"" frameworks "" : {
"" netcoreapp1 . 0 "" : {
"" buildOptions "" : {
"" emitEntryPoint "" : "" true "" ,
"" debugType "" : "" full ""
}
}
}
} ");
mockProj . Properties . Count (
prop = > prop . Name = = "OutputType" | | prop . Name = = "DebugType" ) . Should ( ) . Be ( 2 ) ;
mockProj . Properties . First ( p = > p . Name = = "OutputType" )
. Parent . Condition . Should ( )
2016-10-12 14:59:36 -07:00
. Contain ( "'$(TargetFramework)' == 'netcoreapp1.0'" ) ;
2016-09-08 14:40:46 -07:00
}
2016-11-02 15:05:45 -07:00
[Fact]
2017-01-05 11:46:02 -08:00
public void ItDoesNotAddADefineForTheFramework ( )
2016-11-02 15:05:45 -07:00
{
var mockProj = RunConfigurationsRuleOnPj ( @ "
{
"" frameworks "" : {
"" netcoreapp1 . 0 "" : {
}
}
} ");
mockProj . Properties . Count (
2017-01-05 11:46:02 -08:00
prop = > prop . Name = = "DefineConstants" & & prop . Value . Contains ( "NETCOREAPP10" ) ) . Should ( ) . Be ( 0 ) ;
2016-11-02 15:05:45 -07:00
}
2016-09-08 14:40:46 -07:00
2016-08-22 12:24:10 -07:00
[Fact]
2017-01-05 11:46:02 -08:00
public void ItDoesNotAddADefineForReleaseConfiguration ( )
{
var mockProj = RunRulesOnPj ( @ "
{
"" frameworks "" : {
"" netcoreapp1 . 0 "" : {
}
}
} ",
new IMigrationRule [ ]
{
new AddDefaultsToProjectRule ( ) ,
new MigrateConfigurationsRule ( ) ,
new RemoveDefaultsFromProjectRule ( )
} ) ;
mockProj . Properties . Count (
prop = > prop . Name = = "DefineConstants" & & prop . Value . Contains ( "Release" ) ) . Should ( ) . Be ( 0 ) ;
}
[Fact]
public void ItDoesNotAddADefineForDebugConfiguration ( )
{
var mockProj = RunRulesOnPj ( @ "
{
"" frameworks "" : {
"" netcoreapp1 . 0 "" : {
}
}
} ",
new IMigrationRule [ ]
{
new AddDefaultsToProjectRule ( ) ,
new MigrateConfigurationsRule ( ) ,
new RemoveDefaultsFromProjectRule ( )
} ) ;
mockProj . Properties . Count (
prop = > prop . Name = = "DefineConstants" & & prop . Value . Contains ( "Debug" ) ) . Should ( ) . Be ( 0 ) ;
}
[Fact]
public void ConfigurationBuildOptionsPropertiesAreNotWrittenWhenTheyOverlapWithBuildOptions ( )
2016-08-22 12:24:10 -07:00
{
var mockProj = RunConfigurationsAndBuildOptionsRuleOnPj ( @ "
{
"" buildOptions "" : {
"" emitEntryPoint "" : "" true "" ,
"" debugType "" : "" full ""
} ,
"" configurations "" : {
"" testconfig "" : {
"" buildOptions "" : {
"" emitEntryPoint "" : "" true "" ,
"" debugType "" : "" full ""
}
}
}
} ");
mockProj . Properties . Count ( property = >
2016-08-23 13:50:05 -07:00
property . Name = = "OutputType" | | property . Name = = "DebugType" )
. Should ( ) . Be ( 2 ) ;
2016-08-22 12:24:10 -07:00
foreach ( var property in mockProj . Properties . Where ( property = >
2016-08-23 13:50:05 -07:00
property . Name = = "OutputType" | | property . Name = = "DebugType" ) )
2016-08-22 12:24:10 -07:00
{
property . Parent . Condition . Should ( ) . Be ( string . Empty ) ;
}
}
[Fact]
2017-01-05 11:46:02 -08:00
public void ConfigurationBuildOptionsIncludesAndRemoveAreWrittenWhenTheyDifferFromBaseBuildOptions ( )
2016-08-22 12:24:10 -07:00
{
var mockProj = RunConfigurationsAndBuildOptionsRuleOnPj ( @ "
{
"" buildOptions "" : {
"" copyToOutput "" : {
"" include "" : [ "" src "" ] ,
2017-02-23 18:46:44 -08:00
"" exclude "" : [ "" anothersource "" , "" rootfile . cs "" ] ,
2016-08-22 12:24:10 -07:00
"" includeFiles "" : [ "" src / file1 . cs "" , "" src / file2 . cs "" ] ,
2017-02-23 18:46:44 -08:00
"" excludeFiles "" : [ "" anothersource / file2 . cs "" ]
2016-08-22 12:24:10 -07:00
}
} ,
"" configurations "" : {
"" testconfig "" : {
"" buildOptions "" : {
"" copyToOutput "" : {
"" include "" : [ "" root "" , "" src "" , "" rootfile . cs "" ] ,
2017-02-23 18:46:44 -08:00
"" exclude "" : [ "" anothersource "" , "" root / rootfile . cs "" ] ,
2016-08-22 12:24:10 -07:00
"" includeFiles "" : [ "" src / file1 . cs "" , "" src / file2 . cs "" ] ,
2017-02-23 18:46:44 -08:00
"" excludeFiles "" : [ "" src / file3 . cs "" ]
2016-08-22 12:24:10 -07:00
}
}
}
}
} ");
2017-02-22 22:06:45 -08:00
var contentItems = mockProj . Items . Where ( item = > item . ItemType = = "None" ) ;
2016-09-08 14:40:46 -07:00
2017-02-23 18:46:44 -08:00
contentItems . Count ( ) . Should ( ) . Be ( 8 ) ;
contentItems . Where ( i = > i . ConditionChain ( ) . Count ( ) = = 0 ) . Should ( ) . HaveCount ( 4 ) ;
contentItems . Where ( i = >
i . ConditionChain ( ) . Count ( ) = = 0 & &
i . Metadata . Any ( m = > m . Value = = "PreserveNewest" ) ) . Should ( ) . HaveCount ( 2 ) ;
contentItems . Where ( i = >
i . ConditionChain ( ) . Count ( ) = = 0 & &
i . Metadata . Any ( m = > m . Value = = "Never" ) ) . Should ( ) . HaveCount ( 2 ) ;
contentItems . Where ( i = > i . ConditionChain ( ) . Count ( ) = = 1 ) . Should ( ) . HaveCount ( 4 ) ;
contentItems . Where ( i = >
i . ConditionChain ( ) . Count ( ) = = 1 & &
i . Metadata . Any ( m = > m . Value = = "PreserveNewest" ) ) . Should ( ) . HaveCount ( 1 ) ;
contentItems . Where ( i = >
i . ConditionChain ( ) . Count ( ) = = 1 & &
i . Metadata . Any ( m = > m . Value = = "Never" ) ) . Should ( ) . HaveCount ( 2 ) ;
contentItems . First ( i = >
i . ConditionChain ( ) . Count ( ) = = 1 & &
i . Metadata . Any ( m = > m . Value = = "PreserveNewest" ) & &
! string . IsNullOrEmpty ( i . Update ) ) . Update . Should ( ) . Be ( @"root;rootfile.cs" ) ;
contentItems . First ( i = >
i . ConditionChain ( ) . Count ( ) = = 1 & &
i . Metadata . Any ( m = > m . Value = = "Never" ) & &
! string . IsNullOrEmpty ( i . Update ) & &
i . Update . Contains ( @"src\file3.cs" ) ) . Update . Should ( ) . Be ( @"src\file3.cs" ) ;
contentItems . First ( i = >
i . ConditionChain ( ) . Count ( ) = = 1 & &
i . Metadata . Any ( m = > m . Value = = "Never" ) & &
! string . IsNullOrEmpty ( i . Update ) & &
i . Update . Contains ( @"root\rootfile.cs" ) ) . Update . Should ( ) . Be ( @"root\rootfile.cs" ) ;
contentItems . First ( i = >
i . ConditionChain ( ) . Count ( ) = = 0 & &
i . Metadata . Any ( m = > m . Value = = "PreserveNewest" ) & &
! string . IsNullOrEmpty ( i . Update ) & &
i . Update . Contains ( @"src\file1.cs" ) ) . Update . Should ( ) . Be ( @"src\file1.cs;src\file2.cs" ) ;
contentItems . First ( i = >
i . ConditionChain ( ) . Count ( ) = = 0 & &
i . Metadata . Any ( m = > m . Value = = "PreserveNewest" ) & &
! string . IsNullOrEmpty ( i . Update ) & &
i . Update . Equals ( @"src" ) ) . Update . Should ( ) . Be ( @"src" ) ;
contentItems . First ( i = >
i . ConditionChain ( ) . Count ( ) = = 0 & &
i . Metadata . Any ( m = > m . Value = = "Never" ) & &
! string . IsNullOrEmpty ( i . Update ) & &
i . Update . Equals ( @"anothersource\file2.cs" ) ) . Update . Should ( ) . Be ( @"anothersource\file2.cs" ) ;
contentItems . First ( i = >
i . ConditionChain ( ) . Count ( ) = = 0 & &
i . Metadata . Any ( m = > m . Value = = "Never" ) & &
! string . IsNullOrEmpty ( i . Update ) & &
i . Update . Equals ( @"anothersource;rootfile.cs" ) ) . Update . Should ( ) . Be ( @"anothersource;rootfile.cs" ) ;
2016-08-22 12:24:10 -07:00
}
[Fact]
2017-01-05 11:46:02 -08:00
public void ConfigurationBuildOptionsWhichHaveDifferentExcludesThanBuildOptionsOverwrites ( )
2016-08-22 12:24:10 -07:00
{
2016-09-08 14:40:46 -07:00
var mockProj = RunConfigurationsAndBuildOptionsRuleOnPj ( @ "
2016-08-22 12:24:10 -07:00
{
"" buildOptions "" : {
"" copyToOutput "" : {
"" include "" : [ "" src "" ] ,
"" exclude "" : [ "" rootfile . cs "" ] ,
"" includeFiles "" : [ "" src / file1 . cs "" , "" src / file2 . cs "" ] ,
"" excludeFiles "" : [ "" src / file3 . cs "" ]
}
} ,
"" configurations "" : {
"" testconfig "" : {
"" buildOptions "" : {
"" copyToOutput "" : {
2017-02-23 18:46:44 -08:00
"" include "" : [ "" root "" , "" anothersource "" , "" rootfile . cs "" ] ,
2016-09-08 14:40:46 -07:00
"" exclude "" : [ "" rootfile . cs "" , "" someotherfile . cs "" ] ,
2016-08-22 12:24:10 -07:00
"" includeFiles "" : [ "" src / file1 . cs "" , "" src / file2 . cs "" ] ,
"" excludeFiles "" : [ "" src / file2 . cs "" ]
}
}
}
}
} ");
2017-02-22 22:06:45 -08:00
var contentItems = mockProj . Items . Where ( item = > item . ItemType = = "None" ) ;
2016-09-08 14:40:46 -07:00
2017-02-23 18:46:44 -08:00
contentItems . Count ( ) . Should ( ) . Be ( 9 ) ;
contentItems . Where ( i = > i . ConditionChain ( ) . Count ( ) = = 0 ) . Should ( ) . HaveCount ( 4 ) ;
contentItems . Where ( i = > i . ConditionChain ( ) . Count ( ) = = 1 ) . Should ( ) . HaveCount ( 5 ) ;
contentItems . Where ( i = >
i . ConditionChain ( ) . Count ( ) = = 0 & &
i . Metadata . Any ( m = > m . Value = = "PreserveNewest" ) ) . Should ( ) . HaveCount ( 2 ) ;
contentItems . Where ( i = >
i . ConditionChain ( ) . Count ( ) = = 0 & &
i . Metadata . Any ( m = > m . Value = = "Never" ) ) . Should ( ) . HaveCount ( 2 ) ;
contentItems . Where ( i = >
i . ConditionChain ( ) . Count ( ) = = 1 & &
i . Metadata . Any ( m = > m . Value = = "PreserveNewest" ) ) . Should ( ) . HaveCount ( 1 ) ;
contentItems . Where ( i = >
i . ConditionChain ( ) . Count ( ) = = 1 & &
i . Metadata . Any ( m = > m . Value = = "Never" ) ) . Should ( ) . HaveCount ( 3 ) ;
contentItems . First ( i = >
i . ConditionChain ( ) . Count ( ) = = 0 & &
i . Metadata . Any ( m = > m . Value = = "PreserveNewest" ) & &
! string . IsNullOrEmpty ( i . Update ) & &
i . Update . Contains ( @"src\file1.cs" ) ) . Update . Should ( ) . Be ( @"src\file1.cs;src\file2.cs" ) ;
contentItems . First ( i = >
i . ConditionChain ( ) . Count ( ) = = 0 & &
i . Metadata . Any ( m = > m . Value = = "PreserveNewest" ) & &
! string . IsNullOrEmpty ( i . Update ) & &
i . Update . Equals ( @"src" ) ) . Update . Should ( ) . Be ( @"src" ) ;
contentItems . First ( i = >
i . ConditionChain ( ) . Count ( ) = = 0 & &
i . Metadata . Any ( m = > m . Value = = "Never" ) & &
! string . IsNullOrEmpty ( i . Update ) & &
i . Update . Equals ( @"src\file3.cs" ) ) . Update . Should ( ) . Be ( @"src\file3.cs" ) ;
contentItems . First ( i = >
i . ConditionChain ( ) . Count ( ) = = 0 & &
i . Metadata . Any ( m = > m . Value = = "Never" ) & &
! string . IsNullOrEmpty ( i . Update ) & &
i . Update . Equals ( @"rootfile.cs" ) ) . Update . Should ( ) . Be ( @"rootfile.cs" ) ;
contentItems . First ( i = >
i . ConditionChain ( ) . Count ( ) = = 1 & &
i . Metadata . Any ( m = > m . Value = = "PreserveNewest" ) & &
! string . IsNullOrEmpty ( i . Update ) & &
i . Update . Contains ( @"root;anothersource" ) ) . Update . Should ( ) . Be ( @"root;anothersource" ) ;
contentItems . First ( i = >
i . ConditionChain ( ) . Count ( ) = = 1 & &
i . Metadata . Any ( m = > m . Value = = "Never" ) & &
! string . IsNullOrEmpty ( i . Update ) & &
i . Update . Contains ( @"src\file2.cs" ) ) . Update . Should ( ) . Be ( @"src\file2.cs" ) ;
contentItems . First ( i = >
i . ConditionChain ( ) . Count ( ) = = 1 & &
i . Metadata . Any ( m = > m . Value = = "Never" ) & &
! string . IsNullOrEmpty ( i . Update ) & &
i . Update . Contains ( @"rootfile.cs" ) ) . Update . Should ( ) . Be ( @"rootfile.cs" ) ;
contentItems . First ( i = >
i . ConditionChain ( ) . Count ( ) = = 1 & &
i . Metadata . Any ( m = > m . Value = = "Never" ) & &
! string . IsNullOrEmpty ( i . Update ) & &
i . Update . Contains ( @"someotherfile.cs" ) ) . Update . Should ( ) . Be ( @"someotherfile.cs" ) ;
2016-09-08 14:40:46 -07:00
}
[Fact]
2017-01-05 11:46:02 -08:00
public void ConfigurationBuildOptionsWhichHaveMappingsToDirectoryAddLinkMetadataWithItemMetadata ( )
2016-09-08 14:40:46 -07:00
{
var mockProj = RunConfigurationsAndBuildOptionsRuleOnPj ( @ "
{
"" configurations "" : {
"" testconfig "" : {
"" buildOptions "" : {
"" copyToOutput "" : {
"" mappings "" : {
"" / some / dir / "" : {
"" include "" : [ "" src "" , "" root "" ] ,
"" exclude "" : [ "" src "" , "" rootfile . cs "" ] ,
"" includeFiles "" : [ "" src / file1 . cs "" , "" src / file2 . cs "" ] ,
"" excludeFiles "" : [ "" src / file2 . cs "" ]
}
}
}
}
}
}
} ");
2017-02-22 22:06:45 -08:00
var contentItems = mockProj . Items . Where ( item = > item . ItemType = = "None" ) ;
2016-09-08 14:40:46 -07:00
2017-02-23 20:36:02 -08:00
contentItems . Count ( ) . Should ( ) . Be ( 5 ) ;
contentItems . Where ( i = > i . ConditionChain ( ) . Count ( ) = = 1 ) . Should ( ) . HaveCount ( 5 ) ;
2016-09-08 14:40:46 -07:00
2017-02-23 20:36:02 -08:00
var configIncludeContentItem = contentItems . First ( item = > item . Update . Contains ( "root" ) ) ;
var configIncludeContentItem2 = contentItems . First ( item = > item . Update . Contains ( @"src\file1.cs" ) ) ;
var configIncludeContentItem3 = contentItems . First ( item = > item . Update . Contains ( @"src\file2.cs" ) ) ;
var configIncludeContentItem4 = contentItems . First ( item = > item . Update . Equals ( @"src" ) ) ;
var configIncludeContentItem5 = contentItems . First ( item = > item . Update . Contains ( @"rootfile.cs" ) ) ;
2016-09-08 14:40:46 -07:00
2017-02-23 20:36:02 -08:00
configIncludeContentItem . Updates ( ) . Should ( ) . BeEquivalentTo ( "root" ) ;
2016-09-08 14:40:46 -07:00
configIncludeContentItem . GetMetadataWithName ( "Link" ) . Should ( ) . NotBeNull ( ) ;
configIncludeContentItem . GetMetadataWithName ( "Link" ) . Value . Should ( ) . Be ( "/some/dir/%(FileName)%(Extension)" ) ;
configIncludeContentItem . GetMetadataWithName ( "CopyToOutputDirectory" ) . Should ( ) . NotBeNull ( ) ;
configIncludeContentItem . GetMetadataWithName ( "CopyToOutputDirectory" ) . Value . Should ( ) . Be ( "PreserveNewest" ) ;
2017-02-23 20:36:02 -08:00
configIncludeContentItem2 . Updates ( ) . Should ( ) . BeEquivalentTo ( @"src\file1.cs" ) ;
2016-09-08 14:40:46 -07:00
configIncludeContentItem2 . GetMetadataWithName ( "Link" ) . Should ( ) . NotBeNull ( ) ;
configIncludeContentItem2 . GetMetadataWithName ( "Link" ) . Value . Should ( ) . Be ( "/some/dir/%(FileName)%(Extension)" ) ;
configIncludeContentItem2 . GetMetadataWithName ( "CopyToOutputDirectory" ) . Should ( ) . NotBeNull ( ) ;
configIncludeContentItem2 . GetMetadataWithName ( "CopyToOutputDirectory" ) . Value . Should ( ) . Be ( "PreserveNewest" ) ;
2017-02-23 20:36:02 -08:00
configIncludeContentItem3 . Updates ( ) . Should ( ) . BeEquivalentTo ( @"src\file2.cs" ) ;
configIncludeContentItem3 . GetMetadataWithName ( "Link" ) . Should ( ) . NotBeNull ( ) ;
configIncludeContentItem3 . GetMetadataWithName ( "Link" ) . Value . Should ( ) . Be ( "/some/dir/%(FileName)%(Extension)" ) ;
configIncludeContentItem3 . GetMetadataWithName ( "CopyToOutputDirectory" ) . Should ( ) . NotBeNull ( ) ;
configIncludeContentItem3 . GetMetadataWithName ( "CopyToOutputDirectory" ) . Value . Should ( ) . Be ( "Never" ) ;
configIncludeContentItem4 . Updates ( ) . Should ( ) . BeEquivalentTo ( @"src" ) ;
configIncludeContentItem4 . GetMetadataWithName ( "Link" ) . Should ( ) . NotBeNull ( ) ;
configIncludeContentItem4 . GetMetadataWithName ( "Link" ) . Value . Should ( ) . Be ( "/some/dir/%(FileName)%(Extension)" ) ;
configIncludeContentItem4 . GetMetadataWithName ( "CopyToOutputDirectory" ) . Should ( ) . NotBeNull ( ) ;
configIncludeContentItem4 . GetMetadataWithName ( "CopyToOutputDirectory" ) . Value . Should ( ) . Be ( "Never" ) ;
configIncludeContentItem5 . Updates ( ) . Should ( ) . BeEquivalentTo ( @"rootfile.cs" ) ;
configIncludeContentItem5 . GetMetadataWithName ( "Link" ) . Should ( ) . NotBeNull ( ) ;
configIncludeContentItem5 . GetMetadataWithName ( "Link" ) . Value . Should ( ) . Be ( "/some/dir/%(FileName)%(Extension)" ) ;
configIncludeContentItem5 . GetMetadataWithName ( "CopyToOutputDirectory" ) . Should ( ) . NotBeNull ( ) ;
configIncludeContentItem5 . GetMetadataWithName ( "CopyToOutputDirectory" ) . Value . Should ( ) . Be ( "Never" ) ;
2016-09-08 14:40:46 -07:00
}
[Fact]
2017-01-05 11:46:02 -08:00
public void ConfigurationBuildOptionsWhichHaveMappingsOverlappingWithIncludesInSameConfigurationMergedItemsHaveLinkMetadata ( )
2016-09-08 14:40:46 -07:00
{
var mockProj = RunConfigurationsAndBuildOptionsRuleOnPj ( @ "
{
"" configurations "" : {
"" testconfig "" : {
"" buildOptions "" : {
"" copyToOutput "" : {
"" include "" : [ "" src "" , "" root "" ] ,
"" exclude "" : [ "" src "" , "" rootfile . cs "" ] ,
"" includeFiles "" : [ "" src / file1 . cs "" ] ,
"" excludeFiles "" : [ "" src / file2 . cs "" ] ,
"" mappings "" : {
"" / some / dir / "" : {
"" include "" : [ "" src "" ] ,
"" exclude "" : [ "" src "" , "" src / rootfile . cs "" ]
}
}
}
}
}
}
} ");
2017-02-22 22:06:45 -08:00
var contentItems = mockProj . Items . Where ( item = > item . ItemType = = "None" ) ;
2016-09-08 14:40:46 -07:00
2017-02-23 20:36:02 -08:00
contentItems . Count ( ) . Should ( ) . Be ( 6 ) ;
contentItems . Where ( i = > i . ConditionChain ( ) . Count ( ) = = 1 ) . Should ( ) . HaveCount ( 6 ) ;
2016-09-08 14:40:46 -07:00
var configIncludeContentItem = contentItems . First (
item = > item . ConditionChain ( ) . Count ( ) > 0
2017-02-22 23:16:54 -08:00
& & item . Update = = "root" ) ;
2016-09-08 14:40:46 -07:00
var configIncludeContentItem2 = contentItems . First (
item = > item . ConditionChain ( ) . Count ( ) > 0
2017-02-22 23:16:54 -08:00
& & item . Update = = "src" ) ;
2016-09-08 14:40:46 -07:00
var configIncludeContentItem3 = contentItems . First (
item = > item . ConditionChain ( ) . Count ( ) > 0
2017-02-22 23:16:54 -08:00
& & item . Update . Contains ( @"src\file1.cs" ) ) ;
2016-09-08 14:40:46 -07:00
2017-02-23 20:36:02 -08:00
var configIncludeContentItem4 = contentItems . First (
item = > item . ConditionChain ( ) . Count ( ) > 0
& & item . Update . Contains ( @"src\file2.cs" ) ) ;
2016-09-08 14:40:46 -07:00
2017-02-23 20:36:02 -08:00
var configIncludeContentItem5 = contentItems . First (
item = > item . ConditionChain ( ) . Count ( ) > 0
& & item . Update . Equals ( @"rootfile.cs" ) ) ;
2016-09-08 14:40:46 -07:00
2017-02-23 20:36:02 -08:00
var configIncludeContentItem6 = contentItems . First (
item = > item . ConditionChain ( ) . Count ( ) > 0
& & item . Update . Equals ( @"src\rootfile.cs" ) ) ;
configIncludeContentItem . Updates ( ) . Should ( ) . BeEquivalentTo ( "root" ) ;
2016-09-08 14:40:46 -07:00
configIncludeContentItem . GetMetadataWithName ( "Link" ) . Should ( ) . BeNull ( ) ;
configIncludeContentItem . GetMetadataWithName ( "CopyToOutputDirectory" ) . Should ( ) . NotBeNull ( ) ;
configIncludeContentItem . GetMetadataWithName ( "CopyToOutputDirectory" ) . Value . Should ( ) . Be ( "PreserveNewest" ) ;
2017-02-22 23:16:54 -08:00
configIncludeContentItem2 . Update . Should ( ) . Be ( "src" ) ;
2016-09-08 14:40:46 -07:00
configIncludeContentItem2 . GetMetadataWithName ( "Link" ) . Should ( ) . NotBeNull ( ) ;
configIncludeContentItem2 . GetMetadataWithName ( "Link" ) . Value . Should ( ) . Be ( "/some/dir/%(FileName)%(Extension)" ) ;
configIncludeContentItem2 . GetMetadataWithName ( "CopyToOutputDirectory" ) . Should ( ) . NotBeNull ( ) ;
2017-02-23 20:36:02 -08:00
configIncludeContentItem2 . GetMetadataWithName ( "CopyToOutputDirectory" ) . Value . Should ( ) . Be ( "Never" ) ;
2016-09-08 14:40:46 -07:00
2017-02-22 23:16:54 -08:00
configIncludeContentItem3 . Updates ( ) . Should ( ) . BeEquivalentTo ( @"src\file1.cs" ) ;
2016-09-08 14:40:46 -07:00
configIncludeContentItem3 . GetMetadataWithName ( "Link" ) . Should ( ) . BeNull ( ) ;
configIncludeContentItem3 . GetMetadataWithName ( "CopyToOutputDirectory" ) . Should ( ) . NotBeNull ( ) ;
configIncludeContentItem3 . GetMetadataWithName ( "CopyToOutputDirectory" ) . Value . Should ( ) . Be ( "PreserveNewest" ) ;
2017-02-23 20:36:02 -08:00
configIncludeContentItem4 . Updates ( ) . Should ( ) . BeEquivalentTo ( @"src\file2.cs" ) ;
configIncludeContentItem4 . GetMetadataWithName ( "Link" ) . Should ( ) . BeNull ( ) ;
configIncludeContentItem4 . GetMetadataWithName ( "CopyToOutputDirectory" ) . Should ( ) . NotBeNull ( ) ;
configIncludeContentItem4 . GetMetadataWithName ( "CopyToOutputDirectory" ) . Value . Should ( ) . Be ( "Never" ) ;
configIncludeContentItem5 . Updates ( ) . Should ( ) . BeEquivalentTo ( @"rootfile.cs" ) ;
configIncludeContentItem5 . GetMetadataWithName ( "Link" ) . Should ( ) . BeNull ( ) ;
configIncludeContentItem5 . GetMetadataWithName ( "CopyToOutputDirectory" ) . Should ( ) . NotBeNull ( ) ;
configIncludeContentItem5 . GetMetadataWithName ( "CopyToOutputDirectory" ) . Value . Should ( ) . Be ( "Never" ) ;
configIncludeContentItem6 . Updates ( ) . Should ( ) . BeEquivalentTo ( @"src\rootfile.cs" ) ;
configIncludeContentItem6 . GetMetadataWithName ( "Link" ) . Value . Should ( ) . Be ( "/some/dir/%(FileName)%(Extension)" ) ;
configIncludeContentItem6 . GetMetadataWithName ( "CopyToOutputDirectory" ) . Should ( ) . NotBeNull ( ) ;
configIncludeContentItem6 . GetMetadataWithName ( "CopyToOutputDirectory" ) . Value . Should ( ) . Be ( "Never" ) ;
2016-09-08 14:40:46 -07:00
}
2017-03-02 21:04:03 -08:00
2016-09-08 14:40:46 -07:00
[Fact]
2017-01-05 11:46:02 -08:00
public void ConfigurationBuildOptionsWhichHaveMappingsOverlappingWithIncludesInRootBuildoptionsHasRemove ( )
2016-09-08 14:40:46 -07:00
{
var mockProj = RunConfigurationsAndBuildOptionsRuleOnPj ( @ "
{
"" buildOptions "" : {
"" copyToOutput "" : {
"" include "" : [ "" src "" , "" root "" ] ,
"" exclude "" : [ "" src "" , "" rootfile . cs "" ] ,
"" includeFiles "" : [ "" src / file1 . cs "" , "" src / file2 . cs "" ] ,
"" excludeFiles "" : [ "" src / file2 . cs "" ]
}
} ,
"" configurations "" : {
"" testconfig "" : {
"" buildOptions "" : {
"" copyToOutput "" : {
"" mappings "" : {
"" / some / dir / "" : {
"" include "" : [ "" src "" ] ,
"" exclude "" : [ "" src "" , "" rootfile . cs "" ]
}
}
}
}
}
}
} ");
2017-02-22 22:06:45 -08:00
var contentItems = mockProj . Items . Where ( item = > item . ItemType = = "None" ) ;
2016-09-08 14:40:46 -07:00
2017-02-23 20:36:02 -08:00
contentItems . Count ( ) . Should ( ) . Be ( 8 ) ;
2016-09-08 14:40:46 -07:00
var rootBuildOptionsContentItems = contentItems . Where ( i = > i . ConditionChain ( ) . Count ( ) = = 0 ) . ToList ( ) ;
2017-02-23 18:46:44 -08:00
rootBuildOptionsContentItems . Count ( ) . Should ( ) . Be ( 5 ) ;
2016-09-08 14:40:46 -07:00
foreach ( var buildOptionContentItem in rootBuildOptionsContentItems )
{
buildOptionContentItem . GetMetadataWithName ( "Link" ) . Should ( ) . BeNull ( ) ;
}
2017-02-23 18:46:44 -08:00
contentItems . First ( i = >
i . ConditionChain ( ) . Count ( ) = = 0 & &
i . Metadata . Any ( m = > m . Value = = "PreserveNewest" ) & &
! string . IsNullOrEmpty ( i . Update ) & &
i . Update . Equals ( @"src\file1.cs" ) ) . Update . Should ( ) . Be ( @"src\file1.cs" ) ;
contentItems . First ( i = >
i . ConditionChain ( ) . Count ( ) = = 0 & &
i . Metadata . Any ( m = > m . Value = = "PreserveNewest" ) & &
! string . IsNullOrEmpty ( i . Update ) & &
i . Update . Equals ( @"root" ) ) . Update . Should ( ) . Be ( @"root" ) ;
contentItems . First ( i = >
i . ConditionChain ( ) . Count ( ) = = 0 & &
i . Metadata . Any ( m = > m . Value = = "Never" ) & &
! string . IsNullOrEmpty ( i . Update ) & &
i . Update . Equals ( @"src\file2.cs" ) ) . Update . Should ( ) . Be ( @"src\file2.cs" ) ;
contentItems . First ( i = >
i . ConditionChain ( ) . Count ( ) = = 0 & &
i . Metadata . Any ( m = > m . Value = = "Never" ) & &
! string . IsNullOrEmpty ( i . Update ) & &
i . Update . Equals ( @"src" ) ) . Update . Should ( ) . Be ( @"src" ) ;
contentItems . First ( i = >
i . ConditionChain ( ) . Count ( ) = = 0 & &
i . Metadata . Any ( m = > m . Value = = "Never" ) & &
! string . IsNullOrEmpty ( i . Update ) & &
i . Update . Equals ( @"rootfile.cs" ) ) . Update . Should ( ) . Be ( @"rootfile.cs" ) ;
2016-09-08 14:40:46 -07:00
var configItems = contentItems . Where ( i = > i . ConditionChain ( ) . Count ( ) = = 1 ) ;
2017-02-23 20:36:02 -08:00
configItems . Should ( ) . HaveCount ( 3 ) ;
2016-09-08 14:40:46 -07:00
var configIncludeContentItem = contentItems . First (
item = > item . ConditionChain ( ) . Count ( ) > 0
2017-02-22 23:16:54 -08:00
& & item . Update . Contains ( "src" ) ) ;
2016-09-08 14:40:46 -07:00
var configRemoveContentItem = contentItems . First (
item = > item . ConditionChain ( ) . Count ( ) > 0
& & ! string . IsNullOrEmpty ( item . Remove ) ) ;
2017-02-22 23:16:54 -08:00
configIncludeContentItem . Update . Should ( ) . Be ( "src" ) ;
2016-09-08 14:40:46 -07:00
configIncludeContentItem . GetMetadataWithName ( "Link" ) . Should ( ) . NotBeNull ( ) ;
configIncludeContentItem . GetMetadataWithName ( "Link" ) . Value . Should ( ) . Be ( "/some/dir/%(FileName)%(Extension)" ) ;
configIncludeContentItem . GetMetadataWithName ( "CopyToOutputDirectory" ) . Should ( ) . NotBeNull ( ) ;
2017-02-23 18:46:44 -08:00
configIncludeContentItem . GetMetadataWithName ( "CopyToOutputDirectory" ) . Value . Should ( ) . Be ( "Never" ) ;
2016-09-08 14:40:46 -07:00
2017-02-23 20:36:02 -08:00
configRemoveContentItem . Remove . Should ( ) . Be ( "src;rootfile.cs" ) ;
2016-09-08 14:40:46 -07:00
}
[Fact]
2017-01-05 11:46:02 -08:00
public void ConfigurationBuildOptionsWhichHaveMappingsOverlappingWithIncludesInSameConfigurationAndRootBuildOptionsHaveRemovesAndLinkMetadataAndEncompassedItemsAreMerged ( )
2016-09-08 14:40:46 -07:00
{
var mockProj = RunConfigurationsAndBuildOptionsRuleOnPj ( @ "
{
"" buildOptions "" : {
"" copyToOutput "" : {
"" include "" : [ "" src "" , "" root "" ] ,
"" exclude "" : [ "" src "" , "" rootfile . cs "" ] ,
"" includeFiles "" : [ "" src / file1 . cs "" ] ,
"" excludeFiles "" : [ "" src / file2 . cs "" ]
}
} ,
"" configurations "" : {
"" testconfig "" : {
"" buildOptions "" : {
"" copyToOutput "" : {
"" include "" : [ "" src "" , "" root "" ] ,
"" exclude "" : [ "" src "" , "" rootfile . cs "" ] ,
"" includeFiles "" : [ "" src / file3 . cs "" ] ,
"" excludeFiles "" : [ "" src / file2 . cs "" ] ,
"" mappings "" : {
"" / some / dir / "" : {
"" include "" : [ "" src "" ] ,
"" exclude "" : [ "" src "" , "" src / rootfile . cs "" ]
}
}
}
}
}
}
} ");
2017-02-22 22:06:45 -08:00
var contentItems = mockProj . Items . Where ( item = > item . ItemType = = "None" ) ;
2016-09-08 14:40:46 -07:00
2017-02-23 20:36:02 -08:00
contentItems . Count ( ) . Should ( ) . Be ( 9 ) ;
contentItems . Where ( i = > i . ConditionChain ( ) . Count ( ) = = 1 ) . Should ( ) . HaveCount ( 4 ) ;
2016-09-08 14:40:46 -07:00
var rootBuildOptionsContentItems = contentItems . Where ( i = > i . ConditionChain ( ) . Count ( ) = = 0 ) . ToList ( ) ;
2017-02-23 18:46:44 -08:00
rootBuildOptionsContentItems . Count ( ) . Should ( ) . Be ( 5 ) ;
2016-09-08 14:40:46 -07:00
foreach ( var buildOptionContentItem in rootBuildOptionsContentItems )
{
buildOptionContentItem . GetMetadataWithName ( "Link" ) . Should ( ) . BeNull ( ) ;
}
var configIncludeEncompassedItem = contentItems . FirstOrDefault (
item = > item . ConditionChain ( ) . Count ( ) > 0
2017-02-22 23:16:54 -08:00
& & item . Update = = "root" ) ;
2016-09-08 14:40:46 -07:00
configIncludeEncompassedItem . Should ( ) . BeNull ( ) ;
2017-03-02 21:04:03 -08:00
2016-09-08 14:40:46 -07:00
var configIncludeContentItem = contentItems . First (
item = > item . ConditionChain ( ) . Count ( ) > 0
2017-02-22 23:16:54 -08:00
& & item . Update = = "src" ) ;
2016-09-08 14:40:46 -07:00
var configIncludeContentItem2 = contentItems . First (
item = > item . ConditionChain ( ) . Count ( ) > 0
2017-02-22 23:16:54 -08:00
& & item . Update . Contains ( @"src\file3.cs" ) ) ;
2016-09-08 14:40:46 -07:00
var configRemoveContentItem = contentItems . First (
item = > item . ConditionChain ( ) . Count ( ) > 0
& & ! string . IsNullOrEmpty ( item . Remove ) ) ;
2017-02-22 23:16:54 -08:00
configIncludeContentItem . Update . Should ( ) . Be ( "src" ) ;
2016-09-08 14:40:46 -07:00
configIncludeContentItem . GetMetadataWithName ( "Link" ) . Should ( ) . NotBeNull ( ) ;
configIncludeContentItem . GetMetadataWithName ( "Link" ) . Value . Should ( ) . Be ( "/some/dir/%(FileName)%(Extension)" ) ;
configIncludeContentItem . GetMetadataWithName ( "CopyToOutputDirectory" ) . Should ( ) . NotBeNull ( ) ;
2017-02-23 18:46:44 -08:00
configIncludeContentItem . GetMetadataWithName ( "CopyToOutputDirectory" ) . Value . Should ( ) . Be ( "Never" ) ;
2016-09-08 14:40:46 -07:00
2017-02-22 23:16:54 -08:00
configIncludeContentItem2 . Updates ( ) . Should ( ) . BeEquivalentTo ( @"src\file3.cs" ) ;
2016-09-08 14:40:46 -07:00
configIncludeContentItem2 . GetMetadataWithName ( "Link" ) . Should ( ) . BeNull ( ) ;
configIncludeContentItem2 . GetMetadataWithName ( "CopyToOutputDirectory" ) . Should ( ) . NotBeNull ( ) ;
configIncludeContentItem2 . GetMetadataWithName ( "CopyToOutputDirectory" ) . Value . Should ( ) . Be ( "PreserveNewest" ) ;
configRemoveContentItem . Removes ( ) . Should ( ) . BeEquivalentTo ( "src" ) ;
2016-08-22 12:24:10 -07:00
}
2016-09-08 14:40:46 -07:00
2016-08-22 12:24:10 -07:00
private ProjectRootElement RunConfigurationsRuleOnPj ( string s , string testDirectory = null )
{
testDirectory = testDirectory ? ? Temp . CreateDirectory ( ) . Path ;
2017-01-05 11:46:02 -08:00
return RunRulesOnPj ( s , new [ ] { new MigrateConfigurationsRule ( ) } , testDirectory ) ;
2016-08-22 12:24:10 -07:00
}
private ProjectRootElement RunConfigurationsAndBuildOptionsRuleOnPj ( string s , string testDirectory = null )
{
2017-01-05 11:46:02 -08:00
return RunRulesOnPj (
2017-03-02 21:04:03 -08:00
s ,
2017-01-05 11:46:02 -08:00
new IMigrationRule [ ]
2016-08-22 12:24:10 -07:00
{
new MigrateBuildOptionsRule ( ) ,
new MigrateConfigurationsRule ( )
2017-01-05 11:46:02 -08:00
} ,
testDirectory ) ;
}
private ProjectRootElement RunRulesOnPj ( string s , IMigrationRule [ ] migrationRules , string testDirectory = null )
{
testDirectory = testDirectory ? ? Temp . CreateDirectory ( ) . Path ;
return TemporaryProjectFileRuleRunner . RunRules ( migrationRules , s , testDirectory ) ;
2016-08-22 12:24:10 -07:00
}
}
}