private static void Cleanup(Project project, string itemTypeToCleanup) { var items = project.Items.Where(x => x.ItemType == itemTypeToCleanup).ToList(); project.RemoveItems(items); var sortedItems = items.OrderBy(x => x.UnevaluatedInclude); foreach (var item in sortedItems) project.AddItemFast(itemTypeToCleanup, item.UnevaluatedInclude); }
public void AddItemFast_MatchesWildcardInSemicolonList() { Project project = new Project(); project.Xml.AddItem("i", "a;*.xxx;b"); project.ReevaluateIfNecessary(); project.AddItemFast("i", "i1.xxx"); string expected = ObjectModelHelpers.CleanupFileContents( @"<Project ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""msbuildnamespace""> <ItemGroup> <i Include=""a;*.xxx;b"" /> </ItemGroup> </Project>"); Helpers.VerifyAssertProjectContent(expected, project); }
public void AddItemFastWithMetadata_DoesNotMatchWildcardWithNoMetadata() { Project project = new Project(); ProjectItemElement item1 = project.Xml.AddItem("i", "*.xxx"); project.ReevaluateIfNecessary(); Dictionary<string, string> metadata = new Dictionary<string, string>() { { "m", "m1" } }; ProjectItemElement item2 = project.AddItemFast("i", "i1.xxx", metadata)[0].Xml; string expected = ObjectModelHelpers.CleanupFileContents( @"<Project ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""msbuildnamespace""> <ItemGroup> <i Include=""*.xxx"" /> <i Include=""i1.xxx""> <m>m1</m> </i> </ItemGroup> </Project>"); Helpers.VerifyAssertProjectContent(expected, project); }
public void AddItemFast_DoesntMatchComplicatedWildcard() { Project project = new Project(); ProjectItemElement item1 = project.Xml.AddItem("i", @"c:\subdir1\**\subdir2\**\*.x?x"); project.ReevaluateIfNecessary(); ProjectItemElement item2 = project.AddItemFast("i", @"c:\subdir1\a\b\c\i1.xyx")[0].Xml; string expected = ObjectModelHelpers.CleanupFileContents( @"<Project ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""msbuildnamespace""> <ItemGroup> <i Include=""c:\subdir1\**\subdir2\**\*.x?x"" /> <i Include=""c:\subdir1\a\b\c\i1.xyx"" /> </ItemGroup> </Project>"); Helpers.VerifyAssertProjectContent(expected, project); Assert.Equal(false, Object.ReferenceEquals(item1, item2)); }
public void AddItemFast_MatchesWildcardWithExclude() { Project project = new Project(); ProjectItemElement itemElement = project.Xml.AddItem("i", "*.xxx"); itemElement.Exclude = "i2.xxx"; project.ReevaluateIfNecessary(); project.AddItemFast("i", "i1.xxx"); string expected = ObjectModelHelpers.CleanupFileContents( @"<Project ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""msbuildnamespace""> <ItemGroup> <i Include=""*.xxx"" Exclude=""i2.xxx"" /> <i Include=""i1.xxx"" /> </ItemGroup> </Project>"); Helpers.VerifyAssertProjectContent(expected, project); }
public void AddItemFast_ContainingWildcardNoMatches() { Project project = new Project(); IList<ProjectItem> items = project.AddItemFast("i", @"c:\" + Guid.NewGuid().ToString() + @"\**\i1"); Assert.Equal(0, items.Count); }
public void AddItemFast_IncludeContainsItemExpression() { Project project = new Project(); project.AddItemFast("h", "h1"); project.ReevaluateIfNecessary(); ProjectItem item = project.AddItemFast("i", "@(h)")[0]; Assert.Equal("@(h)", item.UnevaluatedInclude); Assert.Equal("h1", item.EvaluatedInclude); }
public void AddItemFast_IncludeContainsWildcard() { string[] paths = null; try { paths = Helpers.CreateFiles("i1.xxx", "i2.xxx"); string wildcard = Path.Combine(Path.GetDirectoryName(paths[0]), "*.xxx;"); Project project = new Project(); project.AddItemFast("i", wildcard); string expected = String.Format ( ObjectModelHelpers.CleanupFileContents( @"<Project ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""msbuildnamespace""> <ItemGroup> <i Include=""{0}"" /> </ItemGroup> </Project>" ), wildcard ); List<ProjectItem> items = Helpers.MakeList(project.Items); Assert.Equal(2, items.Count); Assert.Equal(paths[0], items[0].EvaluatedInclude); Assert.Equal(paths[1], items[1].EvaluatedInclude); } finally { Helpers.DeleteFiles(paths); } }
public void AddItemFast_IncludeContainsPropertyExpression() { Project project = new Project(); project.SetProperty("p", "v1"); project.ReevaluateIfNecessary(); project.AddItemFast("i", "$(p)"); Assert.Equal("$(p)", Helpers.GetFirst(project.Items).UnevaluatedInclude); Assert.Equal("v1", Helpers.GetFirst(project.Items).EvaluatedInclude); }
public void AddItemFast_NullMetadata() { Project project = new Project(); project.AddItemFast("i", "i1", null); string expected = ObjectModelHelpers.CleanupFileContents( @"<Project ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""msbuildnamespace""> <ItemGroup> <i Include=""i1"" /> </ItemGroup> </Project>"); Helpers.VerifyAssertProjectContent(expected, project.Xml); }
public void AddItemFast_InvalidEmptyInclude() { Assert.Throws<ArgumentException>(() => { Project project = new Project(); project.AddItemFast("i", String.Empty); } ); }
public void AddItemFast_WithMetadata() { Project project = new Project(); List<KeyValuePair<string, string>> metadata = new List<KeyValuePair<string, string>>(); metadata.Add(new KeyValuePair<string, string>("m", "m1")); project.AddItemFast("i", "i1", metadata); string expected = ObjectModelHelpers.CleanupFileContents( @"<Project ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""msbuildnamespace""> <ItemGroup> <i Include=""i1""> <m>m1</m> </i> </ItemGroup> </Project>"); Helpers.VerifyAssertProjectContent(expected, project.Xml); }
public void AddItemFast_EscapedItemInclude() { Project project = new Project(); project.AddItemFast("i", "i%281%29"); string expected = ObjectModelHelpers.CleanupFileContents( @"<Project ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""msbuildnamespace""> <ItemGroup> <i Include=""i%281%29"" /> </ItemGroup> </Project>"); Helpers.VerifyAssertProjectContent(expected, project.Xml); List<ProjectItem> items = Helpers.MakeList(project.Items); Assert.Equal(1, items.Count); Assert.Equal("i", items[0].ItemType); Assert.Equal("i(1)", items[0].EvaluatedInclude); Assert.Equal("i(1)", Helpers.GetFirst(project.GetItems("i")).EvaluatedInclude); Assert.Equal("i(1)", Helpers.MakeList(project.CreateProjectInstance().GetItems("i"))[0].EvaluatedInclude); }
public void AddItemFast_MatchesWildcard() { Project project = new Project(); ProjectItemElement item1 = project.Xml.AddItem("i", "*.xxx"); project.ReevaluateIfNecessary(); ProjectItemElement item2 = project.AddItemFast("i", "i1.xxx")[0].Xml; string expected = ObjectModelHelpers.CleanupFileContents( @"<Project ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""msbuildnamespace""> <ItemGroup> <i Include=""*.xxx"" /> </ItemGroup> </Project>"); Helpers.VerifyAssertProjectContent(expected, project); Assert.AreEqual(true, Object.ReferenceEquals(item1, item2)); }
public void AddItemFast_InvalidEmptyInclude() { Project project = new Project(); project.AddItemFast("i", String.Empty); }