|
5 | 5 | using Microsoft.Build.Evaluation; |
6 | 6 | using Shouldly; |
7 | 7 | using System.Collections.Generic; |
| 8 | +using System.Linq; |
8 | 9 | using Xunit; |
9 | 10 |
|
10 | 11 | namespace Microsoft.Build.Utilities.ProjectCreation.UnitTests |
@@ -292,6 +293,54 @@ public void RemoveItem() |
292 | 293 | StringCompareShould.IgnoreLineEndings); |
293 | 294 | } |
294 | 295 |
|
| 296 | + [Fact] |
| 297 | + public void TryGetItemsCustomSelector() |
| 298 | + { |
| 299 | + ProjectCreator.Create(projectFileOptions: NewProjectFileOptions.None) |
| 300 | + .ItemInclude("MyItem", "3F114C1509CF4D499A44F986BEBD5707") |
| 301 | + .ItemInclude("MyItem", "8A9654A639F5429AB1C7A8F2AE9639D8") |
| 302 | + .TryGetItems("MyItem", i => i.EvaluatedInclude, out IReadOnlyCollection<string> items); |
| 303 | + |
| 304 | + items.ShouldBe(new List<string> |
| 305 | + { |
| 306 | + "3F114C1509CF4D499A44F986BEBD5707", |
| 307 | + "8A9654A639F5429AB1C7A8F2AE9639D8" |
| 308 | + }); |
| 309 | + } |
| 310 | + |
| 311 | + [Fact] |
| 312 | + public void TryGetItemsDictionary() |
| 313 | + { |
| 314 | + ProjectCreator.Create(projectFileOptions: NewProjectFileOptions.None) |
| 315 | + .ItemInclude("MyItem", "A9AA54F5E51E4C0A966A5F5CDBD5EC9D", metadata: new Dictionary<string, string> { ["MyMetadata"] = "A3A33B3B55A841D883A05F6CA920AC1F" }) |
| 316 | + .ItemInclude("MyItem", "910E2DA9075043AA850D923E8E3EE398", metadata: new Dictionary<string, string> { ["MyMetadata"] = "EF8E0862B0A946D98DA7082E70AEC3E9" }) |
| 317 | + .TryGetItems("MyItem", "MyMetadata", out IReadOnlyDictionary<string, string> items); |
| 318 | + |
| 319 | + items.ShouldBe(new Dictionary<string, string> |
| 320 | + { |
| 321 | + ["A9AA54F5E51E4C0A966A5F5CDBD5EC9D"] = "A3A33B3B55A841D883A05F6CA920AC1F", |
| 322 | + ["910E2DA9075043AA850D923E8E3EE398"] = "EF8E0862B0A946D98DA7082E70AEC3E9" |
| 323 | + }); |
| 324 | + } |
| 325 | + |
| 326 | + [Fact] |
| 327 | + public void TryGetItemsProjectItems() |
| 328 | + { |
| 329 | + ProjectCreator.Create(projectFileOptions: NewProjectFileOptions.None) |
| 330 | + .ItemInclude("MyItem", "B39E047FC97A48E3964EEA70C46F4E35") |
| 331 | + .ItemInclude("MyItem", "E0FA8DA2551F4EE18D2102149D3049D4") |
| 332 | + .TryGetItems("MyItem", out IReadOnlyCollection<ProjectItem> items); |
| 333 | + |
| 334 | + items |
| 335 | + .Select(i => i.EvaluatedInclude) |
| 336 | + .ToList() |
| 337 | + .ShouldBe(new List<string> |
| 338 | + { |
| 339 | + "B39E047FC97A48E3964EEA70C46F4E35", |
| 340 | + "E0FA8DA2551F4EE18D2102149D3049D4" |
| 341 | + }); |
| 342 | + } |
| 343 | + |
295 | 344 | [Fact] |
296 | 345 | public void UpdateItem() |
297 | 346 | { |
|
0 commit comments