diff --git a/starsky/starsky.foundation.platform/VersionHelpers/SemVersion.cs b/starsky/starsky.foundation.platform/VersionHelpers/SemVersion.cs
index a87f84edf9..37ead0db7e 100644
--- a/starsky/starsky.foundation.platform/VersionHelpers/SemVersion.cs
+++ b/starsky/starsky.foundation.platform/VersionHelpers/SemVersion.cs
@@ -185,7 +185,7 @@ private static int CompareComponent(string a, string? b, bool nonemptyIsLower =
return nonemptyIsLower ? -1 : 1;
var aComps = a.Split('.');
- var bComps = b.Split('.');
+ var bComps = b!.Split('.');
return CompareComponentCompareLoop(aComps, bComps);
}
@@ -228,7 +228,7 @@ public override int GetHashCode()
unchecked
{
// verify this. Some versions start result = 17. Some use 37 instead of 31
- int result = Major.GetHashCode();
+ var result = Major.GetHashCode();
result = result * 31 + Minor.GetHashCode();
result = result * 31 + Patch.GetHashCode();
result = result * 31 + Prerelease.GetHashCode();
@@ -315,7 +315,7 @@ private static int CompareComponentCompareOther(bool aIsNum, bool bIsNum, string
/// The second version to compare.
/// A signed number indicating the relative values of
/// and .
- private static int Compare(SemVersion versionA, SemVersion versionB)
+ internal static int Compare(SemVersion? versionA, SemVersion? versionB)
{
if ( ReferenceEquals(versionA, versionB) ) return 0;
if ( versionA is null ) return -1;
diff --git a/starsky/starskytest/Controllers/HealthCheckForUpdatesControllerTest.cs b/starsky/starskytest/Controllers/HealthCheckForUpdatesControllerTest.cs
index 236c7db14e..d12dc547be 100644
--- a/starsky/starskytest/Controllers/HealthCheckForUpdatesControllerTest.cs
+++ b/starsky/starskytest/Controllers/HealthCheckForUpdatesControllerTest.cs
@@ -1,3 +1,4 @@
+using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
@@ -31,6 +32,33 @@ public async Task CheckForUpdates_Disabled()
Assert.AreEqual(208, actionResult?.StatusCode);
}
+ private class TestOverWriteEnumModel
+ {
+ public UpdateStatus Value { get; set; }
+ }
+
+
+ [TestMethod]
+ [ExpectedException(typeof(NotSupportedException))]
+ public async Task CheckForUpdates_NotSupportedException()
+ {
+ var input = new TestOverWriteEnumModel { Value = UpdateStatus.Disabled };
+
+ // Use reflection to set the updateStatus field to UpdateAvailable
+ // overwrite enum value
+ var propertyInfo = input.GetType().GetProperty("Value");
+ Assert.IsNotNull(propertyInfo);
+ propertyInfo.SetValue(input, 44, null); // <-- this could not happen
+
+ var fakeService = new FakeICheckForUpdates(
+ new KeyValuePair(input.Value, string.Empty));
+
+ Assert.IsNotNull(input.Value);
+
+ await new HealthCheckForUpdatesController(fakeService,
+ new FakeISpecificVersionReleaseInfo()).CheckForUpdates();
+ }
+
[TestMethod]
public async Task CheckForUpdates_HttpError()
{
@@ -102,5 +130,31 @@ public async Task CheckForUpdates_CurrentVersionIsLatest()
ObjectResult;
Assert.AreEqual(200, actionResult?.StatusCode);
}
+
+ [TestMethod]
+ public async Task SpecificVersionReleaseInfo()
+ {
+ var fakeService = new FakeICheckForUpdates(new KeyValuePair());
+ var service2 = new FakeISpecificVersionReleaseInfo(
+ new Dictionary>
+ {
+ {
+ "1.0.0",
+ new Dictionary
+ {
+ { "en", " # 1.0.0\n\n- [x] test\n- [ ] test2\n\n" }
+ }
+ }
+ }
+ );
+
+ var actionResult =
+ await new HealthCheckForUpdatesController(fakeService,
+ service2)
+ .SpecificVersionReleaseInfo("1.0.0") as JsonResult;
+
+ Assert.AreEqual(" # 1.0.0\n\n- [x] test\n- [ ] test2\n\n",
+ actionResult?.Value);
+ }
}
}
diff --git a/starsky/starskytest/starsky.foundation.platform/VersionHelpers/VersionHelpersTest.cs b/starsky/starskytest/starsky.foundation.platform/VersionHelpers/VersionHelpersTest.cs
index e06b5ce4b8..0217aab261 100644
--- a/starsky/starskytest/starsky.foundation.platform/VersionHelpers/VersionHelpersTest.cs
+++ b/starsky/starskytest/starsky.foundation.platform/VersionHelpers/VersionHelpersTest.cs
@@ -129,6 +129,13 @@ public void NonThrowError()
Assert.AreEqual(new SemVersion(0), result);
}
+ [TestMethod]
+ public void CompareTo_Null()
+ {
+ var result = new SemVersion(0).CompareTo(null);
+ Assert.AreEqual(1, result);
+ }
+
[TestMethod]
public void WithVPrefix()
{
@@ -535,5 +542,26 @@ public void Inequality_Operator_Returns_False_For_Same_Version()
// Assert
Assert.IsFalse(result);
}
+
+ [TestMethod]
+ public void Compare_FirstNull()
+ {
+ var result = SemVersion.Compare(null, new SemVersion(1));
+ Assert.AreEqual(-1, result);
+ }
+
+ [TestMethod]
+ public void Compare_SecondNull()
+ {
+ var result = SemVersion.Compare(new SemVersion(1), null);
+ Assert.AreEqual(1, result);
+ }
+
+ [TestMethod]
+ public void Compare_BothNull()
+ {
+ var result = SemVersion.Compare(null, null);
+ Assert.AreEqual(0, result);
+ }
}
}