diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateRootOptionsRule.cs b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateRootOptionsRule.cs index 73760a3a0..f8ee1d9c9 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateRootOptionsRule.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateRootOptionsRule.cs @@ -1,7 +1,9 @@ // 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.Collections.Generic; using System.Linq; +using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.ProjectJsonMigration.Transforms; using Project = Microsoft.DotNet.Internal.ProjectModel.Project; @@ -22,7 +24,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules CopyrightTransform, TitleTransform, LanguageTransform, - VersionTransform + VersionTransform, + AuthorsTransform }; } @@ -42,23 +45,34 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules } } - private AddPropertyTransform DescriptionTransform => new AddPropertyTransform("Description", + private AddPropertyTransform DescriptionTransform => new AddPropertyTransform( + "Description", project => project.Description, project => !string.IsNullOrEmpty(project.Description)); - private AddPropertyTransform CopyrightTransform => new AddPropertyTransform("Copyright", + private AddPropertyTransform CopyrightTransform => new AddPropertyTransform( + "Copyright", project => project.Copyright, project => !string.IsNullOrEmpty(project.Copyright)); - private AddPropertyTransform TitleTransform => new AddPropertyTransform("AssemblyTitle", + private AddPropertyTransform TitleTransform => new AddPropertyTransform( + "AssemblyTitle", project => project.Title, project => !string.IsNullOrEmpty(project.Title)); - private AddPropertyTransform LanguageTransform => new AddPropertyTransform("NeutralLanguage", + private AddPropertyTransform LanguageTransform => new AddPropertyTransform( + "NeutralLanguage", project => project.Language, project => !string.IsNullOrEmpty(project.Language)); - private AddPropertyTransform VersionTransform => new AddPropertyTransform("VersionPrefix", - project => project.Version.ToString(), p => true); + private AddPropertyTransform VersionTransform => new AddPropertyTransform( + "VersionPrefix", + project => project.Version.ToString(), + p => true); + + private AddPropertyTransform AuthorsTransform => new AddPropertyTransform( + "Authors", + project => string.Join(";", project.Authors), + project => project.Authors.OrEmptyIfNull().Any()); } } diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateRootOptions.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateRootOptions.cs new file mode 100644 index 000000000..1ddf6dcfc --- /dev/null +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateRootOptions.cs @@ -0,0 +1,37 @@ +// 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.Linq; +using Microsoft.Build.Construction; +using Microsoft.DotNet.Tools.Test.Utilities; +using FluentAssertions; +using Microsoft.DotNet.ProjectJsonMigration.Rules; +using Xunit; + +namespace Microsoft.DotNet.ProjectJsonMigration.Tests +{ + public class GivenThatIWantToMigrateRootOptions : TestBase + { + [Fact] + public void It_migrates_authors() + { + var mockProj = RunPropertiesRuleOnPj(@" + { + ""authors"": [ ""Some author"", ""Some other author"" ] + }"); + + mockProj.Properties.Count(p => p.Name == "Authors").Should().Be(1); + mockProj.Properties.First(p => p.Name == "Authors").Value.Should().Be( + "Some author;Some other author"); + } + + private ProjectRootElement RunPropertiesRuleOnPj(string project, string testDirectory = null) + { + testDirectory = testDirectory ?? Temp.CreateDirectory().Path; + return TemporaryProjectFileRuleRunner.RunRules(new IMigrationRule[] + { + new MigrateRootOptionsRule() + }, project, testDirectory); + } + } +} \ No newline at end of file