From 875d91629ecf05d2c57e7c843e3f993d015cbf43 Mon Sep 17 00:00:00 2001 From: Bryan Thornbury Date: Wed, 21 Sep 2016 11:31:30 -0700 Subject: [PATCH] case insensitive msbuild metadata findng --- .../MSBuildExtensions.cs | 15 +-------------- .../GivenMSBuildExtensions.cs | 11 +++++++++++ 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/MSBuildExtensions.cs b/src/Microsoft.DotNet.ProjectJsonMigration/MSBuildExtensions.cs index 87c7a1161..c43280de5 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/MSBuildExtensions.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/MSBuildExtensions.cs @@ -171,20 +171,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration public static ProjectMetadataElement GetMetadataWithName(this ProjectItemElement item, string name) { - return item.Metadata.FirstOrDefault(m => m.Name.Equals(name, StringComparison.Ordinal)); - } - - public static bool HasConflictingMetadata(this ProjectItemElement item, ProjectItemElement otherItem) - { - foreach (var metadata in item.Metadata) - { - if (otherItem.Metadata.Any(m => m.Name == metadata.Name && m.Value != metadata.Value)) - { - return true; - } - } - - return false; + return item.Metadata.FirstOrDefault(m => m.Name.Equals(name, StringComparison.OrdinalIgnoreCase)); } public static void AddMetadata(this ProjectItemElement item, ProjectMetadataElement metadata) diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/GivenMSBuildExtensions.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/GivenMSBuildExtensions.cs index f3281cd7e..c4bbf1ab8 100644 --- a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/GivenMSBuildExtensions.cs +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/GivenMSBuildExtensions.cs @@ -129,6 +129,17 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests item1.ConditionChainsAreEquivalent(item2).Should().BeFalse(); } + [Fact] + public void GetMetadataWithName_is_case_insensitive() + { + var project = ProjectRootElement.Create(); + var item1 = project.AddItem("test", "include1"); + item1.AddMetadata("name", "value"); + + item1.GetMetadataWithName("Name").Should().NotBeNull(); + item1.GetMetadataWithName("Name").Value.Should().Be("value"); + } + [Fact] public void HasConflictingMetadata_returns_true_when_items_have_metadata_with_same_name_but_different_value() {