SemanticVersionTests.cs (2928B)
1 // ----------------------------------------------------------------------------- 2 // <copyright file="SemanticVersionTests.cs" company="Microsoft Corporation"> 3 // Copyright (c) Microsoft Corporation. Licensed under the MIT License. 4 // </copyright> 5 // ----------------------------------------------------------------------------- 6 7 namespace Microsoft.Management.Configuration.UnitTests.Tests 8 { 9 using System; 10 using Microsoft.Management.Configuration.Processor.Helpers; 11 using Microsoft.Management.Configuration.UnitTests.Fixtures; 12 using Microsoft.Management.Configuration.UnitTests.Helpers; 13 using Xunit; 14 using Xunit.Abstractions; 15 16 /// <summary> 17 /// Semantic version tests. 18 /// </summary> 19 [Collection("UnitTestCollection")] 20 [InProc] 21 public class SemanticVersionTests 22 { 23 private readonly UnitTestFixture fixture; 24 private readonly ITestOutputHelper log; 25 26 /// <summary> 27 /// Initializes a new instance of the <see cref="SemanticVersionTests"/> class. 28 /// </summary> 29 /// <param name="fixture">Unit test fixture.</param> 30 /// <param name="log">Log helper.</param> 31 public SemanticVersionTests(UnitTestFixture fixture, ITestOutputHelper log) 32 { 33 this.fixture = fixture; 34 this.log = log; 35 } 36 37 /// <summary> 38 /// Test version. 39 /// </summary> 40 [Fact] 41 public void SemanticVersion_Test() 42 { 43 var semanticVersion = new SemanticVersion("1.0.1"); 44 Assert.Equal("1.0.1", semanticVersion.ToString()); 45 Assert.Equal(new Version("1.0.1"), semanticVersion.Version); 46 Assert.False(semanticVersion.IsPrerelease); 47 Assert.Null(semanticVersion.PrereleaseTag); 48 } 49 50 /// <summary> 51 /// Tests prerelease version. 52 /// </summary> 53 [Fact] 54 public void PrereleaseVersion_Test() 55 { 56 var semanticVersion = new SemanticVersion("1.0.1-pre"); 57 Assert.Equal("1.0.1-pre", semanticVersion.ToString()); 58 Assert.Equal(new Version("1.0.1"), semanticVersion.Version); 59 Assert.True(semanticVersion.IsPrerelease); 60 Assert.Equal("pre", semanticVersion.PrereleaseTag); 61 } 62 63 /// <summary> 64 /// Tests GetMaximumVersion. 65 /// </summary> 66 /// <param name="input">Input.</param> 67 /// <param name="expected">Expected.</param> 68 [Theory] 69 [InlineData("1.0.1", "1.0.1")] 70 [InlineData("1.0.*", "1.0.999999999")] 71 [InlineData("*.*.1", "999999999.999999999.1")] 72 public void MaximumVersion_Test(string input, string expected) 73 { 74 var semanticVersion = new SemanticVersion(input); 75 Assert.Equal(expected, semanticVersion.ToString()); 76 } 77 } 78 }