From 43ccc9e62b1d09b2fc8be8a3cf4cf879306f0aee Mon Sep 17 00:00:00 2001 From: Deyan Nenov Date: Thu, 14 Nov 2024 12:45:17 +0000 Subject: [PATCH] bug fix --- .../PackageManagerSearchElement.cs | 4 +- ...ckageManagerSearchElementViewModelTests.cs | 40 +++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/DynamoPackages/PackageManagerSearchElement.cs b/src/DynamoPackages/PackageManagerSearchElement.cs index b44d860a3e6..8e653424f46 100644 --- a/src/DynamoPackages/PackageManagerSearchElement.cs +++ b/src/DynamoPackages/PackageManagerSearchElement.cs @@ -369,13 +369,13 @@ internal static bool IsVersionCompatible(Greg.Responses.Compatibility compatibil bool isListedInVersions = compatibility.versions?.Contains(version.ToString()) ?? false; // Parse min and max values, if provided, and check for valid range - bool isWithinMinMax = true; + bool isWithinMinMax = false; if (!string.IsNullOrEmpty(compatibility.min) || !string.IsNullOrEmpty(compatibility.max)) { Version minVersion = VersionUtilities.Parse(compatibility.min); Version maxVersion = VersionUtilities.Parse(compatibility.max); - // if max is null, try to parse based on wildcard symantics + // if max is null, try to parse based on wildcard semantics if(maxVersion == null) { maxVersion = VersionUtilities.WildCardParse(compatibility.max); diff --git a/test/DynamoCoreWpfTests/PackageManager/PackageManagerSearchElementViewModelTests.cs b/test/DynamoCoreWpfTests/PackageManager/PackageManagerSearchElementViewModelTests.cs index e5907596509..96c9f48b0dc 100644 --- a/test/DynamoCoreWpfTests/PackageManager/PackageManagerSearchElementViewModelTests.cs +++ b/test/DynamoCoreWpfTests/PackageManager/PackageManagerSearchElementViewModelTests.cs @@ -1027,6 +1027,32 @@ public void TestComputeVersionNoDynamoCompatibility() Assert.IsNull(resultNoCompatibility, "Expected unknown compatibility (null) when no compatibility information is provided."); } + [Test] + public void TestComputeVersionSingleCompatibility() + { + // Arrange + var hostOnlyCompatibilityMatrix = new List + { + new Greg.Responses.Compatibility { name = "dynamo", versions = new List { "3.2.2" } } + }; + + var compatibleDynamoVersion = new Version("3.2.2"); // Compatible with Dynamo 3.2.2 + var incompatibleDynamoVersion = new Version("3.4.0"); // Incompatible with Dynamo 3.4.0 + + // Act + // Case 1: Single Dynamo version, compatible + var resultDynamoCompatibility = PackageManagerSearchElement.CalculateCompatibility( + hostOnlyCompatibilityMatrix, compatibleDynamoVersion, compatibilityMap); + + // Case 2: Single Dynamo version, incompatible + var resultNoDynamoCompatibility = PackageManagerSearchElement.CalculateCompatibility( + hostOnlyCompatibilityMatrix, incompatibleDynamoVersion, compatibilityMap); + + // Assert + Assert.IsTrue(resultDynamoCompatibility, "Expected compatible with matching Dynamo versions."); + Assert.IsFalse(resultNoDynamoCompatibility, "Expected incompatible with mismatched Dynamo versions."); + } + [Test] public void HostCompatibilityFiltersExclusivity() { @@ -1162,6 +1188,20 @@ public void IsVersionCompatible_ExactVersionInList_ReturnsTrue() Assert.IsTrue(result, "Expected compatibility to be true when version is in the list."); } + [Test] + public void IsVersionCompatible_NoCompatibleVersion_ReturnsFalse() + { + var compatibility = new Greg.Responses.Compatibility + { + versions = new List { "2.1.0", "2.3.0" } + }; + Version version = new Version("2.2.0"); + + bool result = PackageManagerSearchElement.IsVersionCompatible(compatibility, version); + + Assert.IsFalse(result, "Expected compatibility to be false when version is not in the list."); + } + [Test] public void IsVersionCompatible_MinOnly_ReturnsTrueForCompatibleVersion() {