diff --git a/src/app/dev/DevToys.Core/AppHelper.cs b/src/app/dev/DevToys.Core/AppHelper.cs index 6d3146daee..f64fa9d812 100644 --- a/src/app/dev/DevToys.Core/AppHelper.cs +++ b/src/app/dev/DevToys.Core/AppHelper.cs @@ -109,14 +109,14 @@ var assemblyInformationalVersion .GetExecutingAssembly() .GetCustomAttribute(typeof(AssemblyInformationalVersionAttribute))!; - string currentVersion + string currentVersionString = assemblyInformationalVersion.InformationalVersion .TrimStart('v') .Replace("-alpha", string.Empty) .Replace("-beta", string.Empty) .Replace("-preview", string.Empty) .Replace("-pre", string.Empty); - string? releaseVersion + string? gitHubVersionString = potentialRelease.Name? .TrimStart('v') .Replace("-alpha", string.Empty) @@ -124,9 +124,14 @@ string currentVersion .Replace("-preview", string.Empty) .Replace("-pre", string.Empty); - if (!string.IsNullOrEmpty(releaseVersion) && !string.IsNullOrEmpty(currentVersion)) + if (!string.IsNullOrEmpty(gitHubVersionString) && !string.IsNullOrEmpty(currentVersionString)) { - if (new System.Version(releaseVersion) > new System.Version(currentVersion)) + var gitHubReleaseVersion = new System.Version(gitHubVersionString); + var currentVersion = new System.Version(currentVersionString); + + if (gitHubReleaseVersion.Major > currentVersion.Major + || (gitHubReleaseVersion.Major == currentVersion.Major && gitHubReleaseVersion.Minor > currentVersion.Minor) + || (gitHubReleaseVersion.Major == currentVersion.Major && gitHubReleaseVersion.Minor == currentVersion.Minor && gitHubReleaseVersion.Build > currentVersion.Build)) { return true; } diff --git a/src/app/tests/DevToys.UnitTests/Core/AppHelperTests.cs b/src/app/tests/DevToys.UnitTests/Core/AppHelperTests.cs index 159a6188be..38c2ddbfee 100644 --- a/src/app/tests/DevToys.UnitTests/Core/AppHelperTests.cs +++ b/src/app/tests/DevToys.UnitTests/Core/AppHelperTests.cs @@ -102,6 +102,34 @@ GitHubRelease[] releases result.Should().BeFalse(); } + [Fact] + public async Task CheckForUpdate_Preview_NoUpdate2_Async() + { + GitHubRelease[] releases + = [ + new GitHubRelease + { + Draft = false, + PreRelease = true, + Name = "v0.0.0" + }, + ]; + string releasesJson = JsonSerializer.Serialize(releases); + + var mockWebClientService = new Mock(); + mockWebClientService + .Setup(service => service.SafeGetStringAsync(It.IsAny(), CancellationToken.None)) + .ReturnsAsync(releasesJson); + + var mockVersionService = new Mock(); + mockVersionService + .Setup(service => service.IsPreviewVersion()) + .Returns(true); + + bool result = await AppHelper.CheckForUpdateAsync(mockWebClientService.Object, mockVersionService.Object, CancellationToken.None); + result.Should().BeFalse(); + } + [Fact] public async Task CheckForUpdate_StableAsync() {