diff --git a/src/DependencyManagement/InstalledDependenciesLocator.cs b/src/DependencyManagement/InstalledDependenciesLocator.cs index f1a327a3..c2f86080 100644 --- a/src/DependencyManagement/InstalledDependenciesLocator.cs +++ b/src/DependencyManagement/InstalledDependenciesLocator.cs @@ -38,7 +38,9 @@ private bool IsAcceptableVersionInstalled(string snapshotPath, DependencyManifes { case VersionSpecificationType.ExactVersion: return _storage.IsModuleVersionInstalled( - snapshotPath, dependency.Name, dependency.VersionSpecification); + snapshotPath, dependency.Name, dependency.VersionSpecification) + || _storage.IsModuleVersionInstalled( + snapshotPath, dependency.Name, StripVersionPostfix(dependency.VersionSpecification)); case VersionSpecificationType.MajorVersion: return IsMajorVersionInstalled( @@ -49,6 +51,13 @@ private bool IsAcceptableVersionInstalled(string snapshotPath, DependencyManifes } } + private string StripVersionPostfix(string versionSpecification) + { + const char PostfixSeparator = '-'; + var separatorPos = versionSpecification.IndexOf(PostfixSeparator); + return separatorPos == -1 ? versionSpecification : versionSpecification.Substring(0, separatorPos); + } + private bool IsMajorVersionInstalled(string snapshotPath, string name, string majorVersion) { var installedVersions = _storage.GetInstalledModuleVersions(snapshotPath, name, majorVersion); diff --git a/test/Unit/DependencyManagement/InstalledDependenciesLocatorTests.cs b/test/Unit/DependencyManagement/InstalledDependenciesLocatorTests.cs index 3a8df1e0..684df2b4 100644 --- a/test/Unit/DependencyManagement/InstalledDependenciesLocatorTests.cs +++ b/test/Unit/DependencyManagement/InstalledDependenciesLocatorTests.cs @@ -86,5 +86,39 @@ public void ReturnsNull_WhenExactModuleVersionIsNotInstalled() Assert.Null(result); } + + // Any version with a postfix starting with '-' will be considered a preview version. + // Preview versions may be installed into a folder with the base version name, without the postfix + // (for example '4.0.2-preview' may be installed into a folder with the name '4.0.2'), + // so we need to take this into account and look for both. + [Theory] + [InlineData("-preview")] + [InlineData("-alfa")] + [InlineData("-prerelease")] + [InlineData("-anything")] + public void ReturnsLatestSnapshotPath_WhenPreviewVersionInstalled(string postfix) + { + var baseVersion = "4.0.2"; + var fullVersion = baseVersion + postfix; + + DependencyManifestEntry[] dependencyManifestEntries = + { + new DependencyManifestEntry("A", VersionSpecificationType.ExactVersion, fullVersion) + }; + + _mockStorage.Setup(_ => _.GetDependencies()).Returns(dependencyManifestEntries); + + _mockStorage.Setup(_ => _.GetLatestInstalledSnapshot()).Returns("snapshot"); + + // No exact match... + _mockStorage.Setup(_ => _.IsModuleVersionInstalled("snapshot", "A", fullVersion)).Returns(false); + // ...but the base version is here + _mockStorage.Setup(_ => _.IsModuleVersionInstalled("snapshot", "A", baseVersion)).Returns(true); + + var installedDependenciesLocator = new InstalledDependenciesLocator(_mockStorage.Object); + var result = installedDependenciesLocator.GetPathWithAcceptableDependencyVersionsInstalled(); + + Assert.Equal("snapshot", result); + } } }