using Microsoft.VisualStudio.TestTools.UnitTesting;
using YMhut.Box.Core.Updates;

namespace YMhut.Box.Tests;

[TestClass]
public sealed class UpdateVersionComparerTests
{
    [TestMethod]
    public void NormalizeVersionDoesNotAppendBuildWhenVersionAlreadyHasRevision()
    {
        Assert.AreEqual("2.0.6.2", UpdateVersionComparer.NormalizeVersion("2.0.6.2", "2"));
    }

    [TestMethod]
    public void NormalizeVersionAppendsBuildOnlyToShortVersion()
    {
        Assert.AreEqual("2.0.6.2", UpdateVersionComparer.NormalizeVersion("2.0.6", "2"));
    }

    [TestMethod]
    public void SameVersionWithBuildIsNotNewer()
    {
        Assert.IsFalse(UpdateVersionComparer.IsRemoteNewer("2.0.6.2", "2", "2.0.6.2"));
        Assert.AreEqual(0, UpdateVersionComparer.Compare("2.0.6.2", "2", "2.0.6.2"));
    }

    [TestMethod]
    public void HigherRemoteVersionIsNewer()
    {
        Assert.IsTrue(UpdateVersionComparer.IsRemoteNewer("2.0.6.3", "", "2.0.6.2"));
        Assert.IsTrue(UpdateVersionComparer.IsRemoteNewer("2.0.7", "", "2.0.6.2"));
    }

    [TestMethod]
    public void LowerRemoteVersionIsNotNewer()
    {
        Assert.IsFalse(UpdateVersionComparer.IsRemoteNewer("2.0.6.1", "", "2.0.6.2"));
        Assert.IsFalse(UpdateVersionComparer.IsRemoteNewer("2.0.5", "", "2.0.6.2"));
    }
}
