Skip to content

Commit 44ecec4

Browse files
Copilotmitchdenny
andauthored
Fix TemporaryNuGetConfig to include AllPackages ("*") mappings (#10894)
* Initial plan * Fix TemporaryNuGetConfig to include AllPackages mappings Co-authored-by: mitchdenny <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: mitchdenny <[email protected]>
1 parent 4704f1f commit 44ecec4

File tree

2 files changed

+112
-5
lines changed

2 files changed

+112
-5
lines changed

src/Aspire.Cli/Packaging/TemporaryNuGetConfig.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,7 @@ private static async Task GenerateNuGetConfigAsync(PackageMapping[] mappings, Fi
7070
{
7171
await xmlWriter.WriteStartElementAsync(null, "packageSourceMapping", null);
7272

73-
var mappingsWithSpecificFilters = mappings
74-
.Where(m => m.PackageFilter != PackageMapping.AllPackages)
75-
.ToArray();
76-
77-
var groupedBySource = mappingsWithSpecificFilters
73+
var groupedBySource = mappings
7874
.GroupBy(m => m.Source, StringComparer.OrdinalIgnoreCase);
7975

8076
foreach (var sourceGroup in groupedBySource)
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Xml;
5+
using Aspire.Cli.Packaging;
6+
7+
namespace Aspire.Cli.Tests.Packaging;
8+
9+
public class TemporaryNuGetConfigTests
10+
{
11+
[Fact]
12+
public async Task CreateAsync_IncludesAllPackageSourceMappings()
13+
{
14+
// Arrange
15+
var mappings = new PackageMapping[]
16+
{
17+
new("Aspire.*", "https://example.com/feed1"),
18+
new(PackageMapping.AllPackages, "https://example.com/feed2"), // "*" filter
19+
new("Microsoft.*", "https://example.com/feed1")
20+
};
21+
22+
// Act
23+
using var tempConfig = await TemporaryNuGetConfig.CreateAsync(mappings);
24+
25+
// Assert
26+
var configContent = await File.ReadAllTextAsync(tempConfig.ConfigFile.FullName);
27+
var xmlDoc = new XmlDocument();
28+
xmlDoc.LoadXml(configContent);
29+
30+
// Verify that package source mappings section exists
31+
var packageSourceMappingNode = xmlDoc.SelectSingleNode("//packageSourceMapping");
32+
Assert.NotNull(packageSourceMappingNode);
33+
34+
// Verify all package sources are present
35+
var packageSourceNodes = xmlDoc.SelectNodes("//packageSourceMapping/packageSource");
36+
Assert.NotNull(packageSourceNodes);
37+
Assert.Equal(2, packageSourceNodes.Count); // Two distinct sources
38+
39+
// Verify that the AllPackages mapping is included
40+
var allPackagesMapping = xmlDoc.SelectSingleNode("//packageSourceMapping/packageSource[@key='https://example.com/feed2']/package[@pattern='*']");
41+
Assert.NotNull(allPackagesMapping);
42+
43+
// Verify other specific mappings are also included
44+
var aspireMapping = xmlDoc.SelectSingleNode("//packageSourceMapping/packageSource[@key='https://example.com/feed1']/package[@pattern='Aspire.*']");
45+
Assert.NotNull(aspireMapping);
46+
47+
var microsoftMapping = xmlDoc.SelectSingleNode("//packageSourceMapping/packageSource[@key='https://example.com/feed1']/package[@pattern='Microsoft.*']");
48+
Assert.NotNull(microsoftMapping);
49+
}
50+
51+
[Fact]
52+
public async Task CreateAsync_WithOnlyAllPackagesMappings_IncludesAllMappings()
53+
{
54+
// Arrange
55+
var mappings = new PackageMapping[]
56+
{
57+
new(PackageMapping.AllPackages, "https://feed1.example.com"),
58+
new(PackageMapping.AllPackages, "https://feed2.example.com")
59+
};
60+
61+
// Act
62+
using var tempConfig = await TemporaryNuGetConfig.CreateAsync(mappings);
63+
64+
// Assert
65+
var configContent = await File.ReadAllTextAsync(tempConfig.ConfigFile.FullName);
66+
var xmlDoc = new XmlDocument();
67+
xmlDoc.LoadXml(configContent);
68+
69+
// Verify that package source mappings section exists
70+
var packageSourceMappingNode = xmlDoc.SelectSingleNode("//packageSourceMapping");
71+
Assert.NotNull(packageSourceMappingNode);
72+
73+
// Verify all package sources are present
74+
var packageSourceNodes = xmlDoc.SelectNodes("//packageSourceMapping/packageSource");
75+
Assert.NotNull(packageSourceNodes);
76+
Assert.Equal(2, packageSourceNodes.Count); // Two distinct sources
77+
78+
// Verify that both AllPackages mappings are included
79+
var feed1Mapping = xmlDoc.SelectSingleNode("//packageSourceMapping/packageSource[@key='https://feed1.example.com']/package[@pattern='*']");
80+
Assert.NotNull(feed1Mapping);
81+
82+
var feed2Mapping = xmlDoc.SelectSingleNode("//packageSourceMapping/packageSource[@key='https://feed2.example.com']/package[@pattern='*']");
83+
Assert.NotNull(feed2Mapping);
84+
}
85+
86+
[Fact]
87+
public async Task CreateAsync_WithNoMappings_CreatesValidConfig()
88+
{
89+
// Arrange
90+
var mappings = Array.Empty<PackageMapping>();
91+
92+
// Act
93+
using var tempConfig = await TemporaryNuGetConfig.CreateAsync(mappings);
94+
95+
// Assert
96+
var configContent = await File.ReadAllTextAsync(tempConfig.ConfigFile.FullName);
97+
var xmlDoc = new XmlDocument();
98+
xmlDoc.LoadXml(configContent);
99+
100+
// Verify basic structure exists
101+
var configNode = xmlDoc.SelectSingleNode("//configuration");
102+
Assert.NotNull(configNode);
103+
104+
var packageSourcesNode = xmlDoc.SelectSingleNode("//packageSources");
105+
Assert.NotNull(packageSourcesNode);
106+
107+
// No package source mappings should exist when no mappings provided
108+
var packageSourceMappingNode = xmlDoc.SelectSingleNode("//packageSourceMapping");
109+
Assert.Null(packageSourceMappingNode);
110+
}
111+
}

0 commit comments

Comments
 (0)