Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/DependencyManagement/InstalledDependenciesLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}