49 lines
1.6 KiB
C#
49 lines
1.6 KiB
C#
using System.Xml.Linq;
|
|
using FluentAssertions;
|
|
|
|
namespace NugetPrime.Tests;
|
|
|
|
public sealed class NugetPrimeTests
|
|
{
|
|
[Theory]
|
|
[InlineData("nuget-prime.csproj")]
|
|
[InlineData("nuget-prime-v9.csproj")]
|
|
public void PackageDownloads_ArePinned(string projectFile)
|
|
{
|
|
var repoRoot = FindRepoRoot();
|
|
var path = Path.Combine(repoRoot, "devops", "tools", "nuget-prime", projectFile);
|
|
File.Exists(path).Should().BeTrue($"expected {projectFile} under devops/tools/nuget-prime");
|
|
|
|
var doc = XDocument.Load(path);
|
|
var packages = doc.Descendants().Where(element => element.Name.LocalName == "PackageDownload").ToList();
|
|
packages.Should().NotBeEmpty();
|
|
|
|
foreach (var package in packages)
|
|
{
|
|
var include = package.Attribute("Include")?.Value;
|
|
include.Should().NotBeNullOrWhiteSpace();
|
|
|
|
var version = package.Attribute("Version")?.Value;
|
|
version.Should().NotBeNullOrWhiteSpace();
|
|
version.Should().NotContain("*");
|
|
}
|
|
}
|
|
|
|
private static string FindRepoRoot()
|
|
{
|
|
var current = new DirectoryInfo(AppContext.BaseDirectory);
|
|
for (var i = 0; i < 12 && current is not null; i++)
|
|
{
|
|
var candidate = Path.Combine(current.FullName, "devops", "tools", "nuget-prime", "nuget-prime.csproj");
|
|
if (File.Exists(candidate))
|
|
{
|
|
return current.FullName;
|
|
}
|
|
|
|
current = current.Parent;
|
|
}
|
|
|
|
throw new DirectoryNotFoundException("Repo root not found for devops/tools/nuget-prime");
|
|
}
|
|
}
|