using Elfisa.Core;
using Xunit;

namespace Elfisa.Tests;

public class UpdateServiceTests
{
    [Theory]
    [InlineData("v2.0.4", "2.0.4.0")]
    [InlineData("2.0.4", "2.0.4.0")]
    [InlineData("2.0", "2.0.0.0")]
    [InlineData("2", "2.0.0.0")]
    [InlineData("2.0.4-beta", "2.0.4.0")]
    [InlineData("V10.2.1", "10.2.1.0")]
    [InlineData("  2.0.9  ", "2.0.9.0")]
    public void ParseVersion_valid(string tag, string expected)
        => Assert.Equal(Version.Parse(expected), UpdateService.ParseVersion(tag));

    [Theory]
    [InlineData("")]
    [InlineData(null)]
    [InlineData("garbage")]
    [InlineData("v.x.y")]
    public void ParseVersion_invalid_returns_null(string? tag)
        => Assert.Null(UpdateService.ParseVersion(tag));

    [Fact]
    public void Newer_version_compares_greater()
    {
        Assert.True(UpdateService.ParseVersion("v2.0.5") > UpdateService.ParseVersion("v2.0.4"));
        Assert.True(UpdateService.ParseVersion("2.1.0") > UpdateService.ParseVersion("2.0.9"));
        Assert.False(UpdateService.ParseVersion("2.0.4") > UpdateService.ParseVersion("2.0.4"));
        Assert.True(UpdateService.ParseVersion("v3") > UpdateService.ParseVersion("2.9.9"));
    }

    [Fact]
    public void SetupUrl_points_to_cdn()
        => Assert.Equal("https://cdn.24pharmdata.ru/ElfisaPharmacy-Setup.exe", UpdateService.SetupUrl);
}
