77 lines
2.6 KiB
C#
77 lines
2.6 KiB
C#
using System.Xml.Linq;
|
|
|
|
namespace AcDream.Launcher.Tests;
|
|
|
|
public sealed class LauncherProjectBoundaryTests
|
|
{
|
|
private static readonly string[] ExpectedAvaloniaPackages =
|
|
[
|
|
"Avalonia",
|
|
"Avalonia.Desktop",
|
|
"Avalonia.Themes.Fluent",
|
|
];
|
|
|
|
[Fact]
|
|
public void LauncherReferencesOnlyLauncherCoreAndPinsOneAvaloniaVersion()
|
|
{
|
|
string root = FindRepositoryRoot();
|
|
string projectPath = Path.Combine(
|
|
root,
|
|
"src",
|
|
"AcDream.Launcher",
|
|
"AcDream.Launcher.csproj");
|
|
XDocument project = XDocument.Load(projectPath);
|
|
|
|
string projectReference = Assert.Single(
|
|
project.Descendants("ProjectReference")
|
|
.Select(element => element.Attribute("Include")?.Value ?? string.Empty));
|
|
Assert.EndsWith(
|
|
"AcDream.Launcher.Core\\AcDream.Launcher.Core.csproj",
|
|
projectReference,
|
|
StringComparison.Ordinal);
|
|
|
|
(string Name, string Version)[] packages = project
|
|
.Descendants("PackageReference")
|
|
.Select(element => (
|
|
element.Attribute("Include")?.Value ?? string.Empty,
|
|
element.Attribute("Version")?.Value ?? string.Empty))
|
|
.OrderBy(package => package.Item1, StringComparer.Ordinal)
|
|
.ToArray();
|
|
|
|
Assert.Equal(ExpectedAvaloniaPackages, packages.Select(package => package.Name));
|
|
Assert.All(packages, package => Assert.Equal("12.1.1", package.Version));
|
|
}
|
|
|
|
[Fact]
|
|
public void LauncherAndItsTestsAreSolutionMembers()
|
|
{
|
|
string root = FindRepositoryRoot();
|
|
XDocument solution = XDocument.Load(Path.Combine(root, "AcDream.slnx"));
|
|
string[] paths = solution.Descendants("Project")
|
|
.Select(element => (element.Attribute("Path")?.Value ?? string.Empty)
|
|
.Replace('\\', '/'))
|
|
.ToArray();
|
|
|
|
Assert.Contains("src/AcDream.Launcher/AcDream.Launcher.csproj", paths);
|
|
Assert.Contains("tests/AcDream.Launcher.Tests/AcDream.Launcher.Tests.csproj", paths);
|
|
}
|
|
|
|
private static string FindRepositoryRoot()
|
|
{
|
|
foreach (string start in new[] { AppContext.BaseDirectory, Environment.CurrentDirectory })
|
|
{
|
|
DirectoryInfo? directory = new(start);
|
|
while (directory is not null)
|
|
{
|
|
if (File.Exists(Path.Combine(directory.FullName, "AcDream.slnx")))
|
|
{
|
|
return directory.FullName;
|
|
}
|
|
|
|
directory = directory.Parent;
|
|
}
|
|
}
|
|
|
|
throw new DirectoryNotFoundException("Could not find AcDream.slnx.");
|
|
}
|
|
}
|