Skip to content

Commit c55f844

Browse files
update the CentralPackageManagementTest to not rely on a specific version
Instead check the Apphost.csproj and Directory.Packages.props more thoroughly for the expected result.
1 parent f91e97b commit c55f844

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

tests/Aspire.Cli.EndToEnd.Tests/CentralPackageManagementTests.cs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -170,34 +170,39 @@ public async Task AspireAddPackageVersionToDirectoryPackagesProps()
170170
</Project>
171171
""");
172172

173-
await auto.TypeAsync("aspire add Aspire.Hosting.Redis --version 13.1.2");
173+
await auto.TypeAsync("aspire add Aspire.Hosting.Redis");
174174
await auto.EnterAsync();
175175

176176
await auto.WaitForSuccessPromptAsync(counter);
177177

178178
// Verify the AppHost project does not end up with a version-pinned Redis PackageReference.
179179
{
180180
var appHostProject = XDocument.Load(appHostCsprojPath);
181-
var hasVersionPinnedRedisReference = false;
181+
var directoryPackagesProps = XDocument.Load(directoryPackagesPropsPath);
182182

183-
foreach (var element in appHostProject.Descendants())
183+
static IEnumerable<XElement> GetRedisProperties(XDocument document, string propertyName)
184184
{
185-
if (element.Name.LocalName == "PackageReference" &&
186-
string.Equals((string?)element.Attribute("Include"), "Aspire.Hosting.Redis", StringComparison.Ordinal) &&
187-
element.Attribute("Version") is not null)
188-
{
189-
hasVersionPinnedRedisReference = true;
190-
break;
191-
}
185+
return document.Descendants()
186+
.Where(element => element.Name.LocalName == propertyName)
187+
.Where(element => string.Equals((string?)element.Attribute("Include"), "Aspire.Hosting.Redis", StringComparison.Ordinal));
192188
}
193189

194-
if (hasVersionPinnedRedisReference)
190+
var projectHasRedisVersionPin = GetRedisProperties(appHostProject, "PackageReference")
191+
.Any(element => element.Attribute("Version") is not null);
192+
var directoryPackagesHasRedisVersionPin = GetRedisProperties(directoryPackagesProps, "PackageVersion")
193+
.Single().Attribute("Version") is not null;
194+
195+
if (projectHasRedisVersionPin)
195196
{
196197
throw new InvalidOperationException($"File {appHostCsprojPath} unexpectedly contains a version-pinned PackageReference for Aspire.Hosting.Redis");
197198
}
199+
if (!directoryPackagesHasRedisVersionPin)
200+
{
201+
throw new InvalidOperationException($"File {directoryPackagesPropsPath} unexpectedly does not contain the central PackageVersion for Aspire.Hosting.Redis");
202+
}
198203
}
199204

200-
// Verify dotnet restore succeeds (would fail with NU1009 if AppHost.csproj contained a version)
205+
// Verify dotnet restore succeeds (would fail with NU1008 if AppHost.csproj contained a version)
201206
await auto.TypeAsync($"dotnet restore \"{containerAppHostCsprojPath}\"");
202207
await auto.EnterAsync();
203208
await auto.WaitForSuccessPromptAsync(counter, TimeSpan.FromSeconds(120));

0 commit comments

Comments
 (0)