2017-05-20 03:51:56 +00:00
|
|
|
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
|
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
|
|
|
|
using Xunit;
|
|
|
|
using Microsoft.DotNet.MSBuildSdkResolver;
|
|
|
|
using FluentAssertions;
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Cli.Utils.Tests
|
|
|
|
{
|
2017-05-22 17:28:12 +00:00
|
|
|
public class GivenThatWeWantToParseFXVersions
|
2017-05-20 03:51:56 +00:00
|
|
|
{
|
|
|
|
[Fact]
|
|
|
|
public void ReturnsNullWhenNoMajorSeparatorIsFound()
|
|
|
|
{
|
2017-05-22 17:28:12 +00:00
|
|
|
FXVersion fxVersion;
|
|
|
|
FXVersion.TryParse("1", out fxVersion).Should().BeFalse();
|
2017-05-20 03:51:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void ReturnsNullWhenMajorPortionIsNotANumber()
|
|
|
|
{
|
2017-05-22 17:28:12 +00:00
|
|
|
FXVersion fxVersion;
|
|
|
|
FXVersion.TryParse("a.0.0", out fxVersion).Should().BeFalse();
|
2017-05-20 03:51:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void ReturnsNullWhenNoMinorSeparatorIsFound()
|
|
|
|
{
|
2017-05-22 17:28:12 +00:00
|
|
|
FXVersion fxVersion;
|
|
|
|
FXVersion.TryParse("1.0", out fxVersion).Should().BeFalse();
|
2017-05-20 03:51:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void ReturnsNullWhenMinorPortionIsNotANumber()
|
|
|
|
{
|
2017-05-22 17:28:12 +00:00
|
|
|
FXVersion fxVersion;
|
|
|
|
FXVersion.TryParse("1.a.0", out fxVersion).Should().BeFalse();
|
2017-05-20 03:51:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void ReturnsNullWhenPatchPortionIsNotANumber()
|
|
|
|
{
|
2017-05-22 17:28:12 +00:00
|
|
|
FXVersion fxVersion;
|
|
|
|
FXVersion.TryParse("1.0.a", out fxVersion).Should().BeFalse();
|
2017-05-20 03:51:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
2017-05-22 17:28:12 +00:00
|
|
|
public void ReturnsFXVersionWhenOnlyMajorMinorPatchIsFound()
|
2017-05-20 03:51:56 +00:00
|
|
|
{
|
2017-05-22 17:28:12 +00:00
|
|
|
FXVersion fxVersion;
|
|
|
|
|
|
|
|
var result = FXVersion.TryParse("1.2.3", out fxVersion);
|
2017-05-20 03:51:56 +00:00
|
|
|
|
2017-05-22 17:28:12 +00:00
|
|
|
result.Should().BeTrue();
|
|
|
|
fxVersion.Major.Should().Be(1);
|
|
|
|
fxVersion.Minor.Should().Be(2);
|
|
|
|
fxVersion.Patch.Should().Be(3);
|
2017-05-20 03:51:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
2017-05-22 17:28:12 +00:00
|
|
|
public void ReturnsFXVersionWhenOnlyMajorMinorPatchAndPreIsFound()
|
2017-05-20 03:51:56 +00:00
|
|
|
{
|
2017-05-22 17:28:12 +00:00
|
|
|
FXVersion fxVersion;
|
2017-05-20 03:51:56 +00:00
|
|
|
|
2017-05-22 17:28:12 +00:00
|
|
|
var result = FXVersion.TryParse("1.2.3-pre", out fxVersion);
|
|
|
|
|
|
|
|
result.Should().BeTrue();
|
|
|
|
fxVersion.Major.Should().Be(1);
|
|
|
|
fxVersion.Minor.Should().Be(2);
|
|
|
|
fxVersion.Patch.Should().Be(3);
|
|
|
|
fxVersion.Pre.Should().Be("-pre");
|
2017-05-20 03:51:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
2017-05-22 17:28:12 +00:00
|
|
|
public void ReturnsFXVersionWhenMajorMinorPatchAndPreAndBuildIsFound()
|
2017-05-20 03:51:56 +00:00
|
|
|
{
|
2017-05-22 17:28:12 +00:00
|
|
|
FXVersion fxVersion;
|
|
|
|
|
|
|
|
var result = FXVersion.TryParse("1.2.3-pre+build", out fxVersion);
|
|
|
|
|
|
|
|
result.Should().BeTrue();
|
|
|
|
fxVersion.Major.Should().Be(1);
|
|
|
|
fxVersion.Minor.Should().Be(2);
|
|
|
|
fxVersion.Patch.Should().Be(3);
|
|
|
|
fxVersion.Pre.Should().Be("-pre");
|
|
|
|
fxVersion.Build.Should().Be("build");
|
2017-05-20 03:51:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|