using System.IO;
using Xunit;

namespace NexusShell.Tests;

public sealed class NexusStoreViewXamlTests
{
    [Fact]
    public void Operation_progress_binding_is_one_way()
    {
        var xaml = File.ReadAllText(ResolveSourcePath(
            "source",
            "nexus-shell",
            "NexusShell",
            "Views",
            "NexusStoreView.xaml"));

        Assert.Contains("Value=\"{Binding OperationProgress, Mode=OneWay}\"", xaml);
        Assert.Contains("IsIndeterminate=\"{Binding IsOperationIndeterminate, Mode=OneWay}\"", xaml);
    }

    private static string ResolveSourcePath(params string[] parts)
    {
        var dir = new DirectoryInfo(AppContext.BaseDirectory);
        while (dir is not null)
        {
            var candidate = Path.Combine(new[] { dir.FullName }.Concat(parts).ToArray());
            if (File.Exists(candidate))
            {
                return candidate;
            }

            dir = dir.Parent;
        }

        throw new FileNotFoundException("Could not locate source file.", Path.Combine(parts));
    }
}
