|
1 | 1 | // Copyright (c) .NET Foundation. All rights reserved. |
2 | 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. |
3 | 3 |
|
| 4 | +using System; |
4 | 5 | using System.Linq; |
5 | 6 | using System.Threading.Tasks; |
6 | 7 | using FluentAssertions; |
@@ -673,6 +674,73 @@ public async Task RestoreCommand_WithAliasesOfSameFrameworkAndProjectReferences_ |
673 | 674 | result.LockFile.LogMessages[0].TargetGraphs.Should().BeEquivalentTo([banana]); |
674 | 675 | } |
675 | 676 |
|
| 677 | + // P (apple) -> Project2 (apple) -> Package A |
| 678 | + // P (banana) -> Project2 (banana) -> Package B |
| 679 | + [Fact] |
| 680 | + public async Task RestoreCommand_WithAliasesOfSameFrameworkAndProjectReferenceToASingleProject_WithConditionalWarningSuppression_SupressesWarningsCorrectly() |
| 681 | + { |
| 682 | + using var pathContext = new SimpleTestPathContext(); |
| 683 | + |
| 684 | + // Create packages |
| 685 | + var pkgA = new SimpleTestPackageContext("PackageA", "1.0.1"); |
| 686 | + var pkgB = new SimpleTestPackageContext("PackageB", "1.0.1"); |
| 687 | + await SimpleTestPackageUtility.CreatePackagesAsync(pathContext.PackageSource, pkgA, pkgB); |
| 688 | + |
| 689 | + string apple = nameof(apple); |
| 690 | + string banana = nameof(banana); |
| 691 | + |
| 692 | + var project2Spec = @" |
| 693 | + { |
| 694 | + ""frameworks"": { |
| 695 | + ""net8.0"": { |
| 696 | + ""framework"": ""net8.0"", |
| 697 | + ""targetAlias"": ""net8.0"", |
| 698 | + ""dependencies"": { |
| 699 | + ""PackageA"": { |
| 700 | + ""version"": ""[,2.0.0)"", |
| 701 | + ""target"": ""Package"", |
| 702 | + ""noWarn"": [""NU1603""] |
| 703 | + } |
| 704 | + } |
| 705 | + } |
| 706 | + } |
| 707 | + }"; |
| 708 | + |
| 709 | + var project2 = ProjectTestHelpers.GetPackageSpecWithProjectNameAndSpec("Project2", pathContext.SolutionRoot, project2Spec); |
| 710 | + |
| 711 | + // Create Project1 spec that references Project2 |
| 712 | + var project1Spec = @" |
| 713 | + { |
| 714 | + ""frameworks"": { |
| 715 | + ""apple"": { |
| 716 | + ""framework"": ""net10.0"", |
| 717 | + ""targetAlias"": ""apple"", |
| 718 | + ""dependencies"": { |
| 719 | + } |
| 720 | + }, |
| 721 | + ""banana"": { |
| 722 | + ""framework"": ""net10.0"", |
| 723 | + ""targetAlias"": ""banana"", |
| 724 | + ""dependencies"": { |
| 725 | + } |
| 726 | + } |
| 727 | + } |
| 728 | + }"; |
| 729 | + |
| 730 | + var project1 = ProjectTestHelpers.GetPackageSpecWithProjectNameAndSpec("Project1", pathContext.SolutionRoot, project1Spec); |
| 731 | + project1 = project1.WithTestProjectReference(project2); |
| 732 | + |
| 733 | + // Act |
| 734 | + var result = await RunRestoreAsync(pathContext, project1, project2); |
| 735 | + |
| 736 | + // Assert |
| 737 | + result.Success.Should().BeTrue(because: string.Join(Environment.NewLine, result.LockFile.LogMessages.Select(e => e.Message))); |
| 738 | + result.LockFile.Targets.Should().HaveCount(2); |
| 739 | + result.LockFile.LogMessages.Should().HaveCount(1); |
| 740 | + result.LockFile.LogMessages[0].Code.Should().Be(NuGetLogCode.NU1602); |
| 741 | + result.LockFile.LogMessages[0].TargetGraphs.Should().BeEquivalentTo([apple, banana]); |
| 742 | + } |
| 743 | + |
676 | 744 | internal static Task<RestoreResult> RunRestoreAsync(SimpleTestPathContext pathContext, params PackageSpec[] projects) |
677 | 745 | { |
678 | 746 | return RunRestoreAsync(pathContext, forceEvaluate: false, new TestLogger(), projects); |
|
0 commit comments