Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle resolving invalid versions #77

Merged
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
4 changes: 1 addition & 3 deletions Firely.Fhir.Packages.Tests/Packaging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,8 @@ public void TestGeneratingIndexFiles()
[TestMethod]
[DataRow(true, 0)]
[DataRow(true, 1)]
[DataRow(true, 1)]
[DataRow(false, 0)]
[DataRow(false, 1)]
[DataRow(false, 1)]
public async Task HandleInvalidPackagesOnRestore(bool includeValidPackage, int invalidPackageCount)
{
// Arrange
Expand All @@ -69,7 +67,7 @@ public async Task HandleInvalidPackagesOnRestore(bool includeValidPackage, int i
dependencies.Add(IndexGenerationTest.HL7_CORE_PACKAGE_R4);

for (int i = 0; i < invalidPackageCount; i++)
dependencies.Add($"{packageName}{i+1}@{i+1}.{packageRange}");
dependencies.Add($"{packageName}{i + 1}@{i + 1}.{packageRange}");

var fixtureDirectory = TestHelper.InitializeTemporary("integration-test", dependencies.ToArray()).Result;

Expand Down
12 changes: 11 additions & 1 deletion Firely.Fhir.Packages.Tests/ResolvingTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;

namespace Firely.Fhir.Packages.Tests
Expand Down Expand Up @@ -50,5 +52,13 @@ public void LatestStable()

Assert.AreEqual(null, version);
}

[TestMethod]
public void ResolveInvalidSemVerVersion()
{
var target = new Versions(new string[] { "1.0.0", "1.0.2", "1.0.0-beta-1" });
var version = () => target.Resolve("current");
version.Should().Throw<ArgumentException>();
}
}
}
8 changes: 5 additions & 3 deletions Firely.Fhir.Packages/Versioning/Versions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void Append(IEnumerable<string> versions)
{
foreach (var s in versions)
{
if (TryParseVersion(s, out Version? version))
if (Version.TryParse(s, out Version? version))
{
if (version != null)
_list.Add(version);
Expand Down Expand Up @@ -91,6 +91,7 @@ public IEnumerable<Version> Stable()
/// <param name="s">string to be parsed</param>
/// <param name="v">Semver version object</param>
/// <returns>Whether the string was succesfully parsed to a SemVer version object</returns>
[System.Obsolete("Use Version.TryParse() instead")]
[System.CLSCompliant(false)]
public static bool TryParseVersion(string s, out Version? v)
{
Expand All @@ -112,7 +113,7 @@ private static void appendSorted(List<Version> list, IEnumerable<string> values)
{
foreach (var value in values)
{
if (TryParseVersion(value, out Version? version))
if (Version.TryParse(value, out Version? version))
{
if (version is not null)
list.Add(version);
Expand All @@ -128,6 +129,7 @@ private static void appendSorted(List<Version> list, IEnumerable<string> values)
/// <param name="range">Range of versions to be used during the resolving</param>
/// <param name="stable">Indication of allowing only non-preview versions</param>
/// <returns>Semver Version object if the best matching version</returns>
/// <exception cref="System.ArgumentException">Throw argument exception when an invalid pattern is supplied</exception>
[System.CLSCompliant(false)]
public Version? Resolve(string pattern, bool stable = true)
{
Expand All @@ -139,7 +141,7 @@ private static void appendSorted(List<Version> list, IEnumerable<string> values)

if (version is not null) return version;

return TryParseVersion(pattern, out version) && existsUnlisted(version)
return Version.TryParse(pattern, out version) && existsUnlisted(version)
? version
: null;
}
Expand Down