public void Should_Set_Correct_Version_When_Given_Major_Minor() { // Given var version = new SemanticVersion(1, 1); // When, Then Assert.Equal("1.1.0", version.ToString()); }
public void Should_Set_Correct_Version_When_Given_No_Arguments() { // Given var version = new SemanticVersion(); // When, Then Assert.Equal("0.0.0", version.ToString()); }
public void Should_Set_Correct_Version_When_Given_Major_Minor_Patch_Label() { // Given var version = new SemanticVersion(1, 1, 1, "test"); // When, Then Assert.Equal("1.1.1-test", version.ToString()); }
public Manifest() { // Default values MinimumHostVersion = new SemanticVersion("0.0"); Dependencies = Enumerable.Empty<Dependency>(); EventHandlers = Enumerable.Empty<EventHandler>(); Permissions = new PermissionSet(PermissionState.None); UserInterface = new UserInterface(); }
public void Should_Return_False_If_Left_Is_Null() { // Given var left = (SemanticVersion) null; var right = new SemanticVersion(); // When, Then Assert.False(left == right); }
public void Should_Return_Minor_Version() { // Given var version = new SemanticVersion(1, 1); // When, Then Assert.Equal(1, version.Minor); }
public bool Equals(SemanticVersion other) { if ((object) other == null) return false; return this == other; }
public void Should_Return_False_When_Left_And_Right_Differs() { // Given var left = new SemanticVersion(1, 0, 1, "a"); var right = new SemanticVersion(1, 2, 1, "c"); // When, Then Assert.False(left == right); }
public void Should_Throw_ArgumentOutOfRangeException_If_Setting_Negative_Value() { // Given var version = new SemanticVersion(); // When, Then Assert.Throws<ArgumentOutOfRangeException>(() => version.Patch = -1); }
public void Should_Return_Correctly_Presented_String_When_Given_A_Valid_Version() { // Given var version = new SemanticVersion(1, 2, 3, "label"); // When string v = version; // Then Assert.Equal("1.2.3-label", v); }
public void Should_Accept_Any_Positive_Integer() { // Given var version = new SemanticVersion(); // When version.Patch = 1; // Then Assert.Equal(1, version.Patch); }
public void Should_Return_The_Patch_Version() { // Given var version = new SemanticVersion(0, 0, 1); // When, Then Assert.Equal(1, version.Patch); }
public bool IsIncluded(SemanticVersion version) { if (_rules == null) return false; return _rules.All(r => r.IsIncluded(version)); }
public void Should_Return_False_When_Left_Major_Is_Greater_Than_Right_Major() { // Given var left = new SemanticVersion(2); var right = new SemanticVersion(1); // When, Then Assert.False(left < right); }
public void Should_Throw_ArgumentNullException_If_Right_Value_Is_Null() { // Given var left = new SemanticVersion(); var right = (SemanticVersion) null; // When, Then Assert.Throws<ArgumentNullException>(() => left < right); }
public void Should_Return_True_When_Major_Minor_Patch_Are_Same_And_Left_Label_Is_Less_Than_Right_Label() { // Given var left = new SemanticVersion(1, 0, 0, "a"); var right = new SemanticVersion(1, 0, 0, "b"); // When, Then Assert.True(left < right); }
public void Should_Return_True_When_Major_Are_Same_And_Left_Minor_Is_Less_Than_Right_Minor() { // Given var left = new SemanticVersion(1, 0); var right = new SemanticVersion(1, 1); // When, Then Assert.True(left < right); }
public void Should_Return_False_When_Major_Minor_Patch_Are_Same_And_Left_Has_No_Label_When_Right_Has() { // Given var left = new SemanticVersion(1, 0, 0); var right = new SemanticVersion(1, 0, 0, "a"); // When, Then Assert.False(left < right); }
public void Should_Return_False_When_Major_Minor_Are_Same_And_Left_Patch_Is_Greater_Than_Right_Patch() { // Given var left = new SemanticVersion(1, 0, 1); var right = new SemanticVersion(1, 0, 0); // When, Then Assert.False(left < right); }
public static bool TryParse(string versionRange, out SemanticVersionRange range, out Exception exception) { range = null; exception = null; try { // empty = latest version. if (String.IsNullOrEmpty(versionRange)) { range = new SemanticVersionRange(); return true; } // if it starts with a numeric character it should be a single version // 1.0 = 1.0 <= x if (Char.IsNumber(versionRange[0])) { var version = new SemanticVersion(versionRange); range = new SemanticVersionRange(new GreaterThanOrEqualsRule(version)); return true; } var isRange = versionRange.Contains(","); var lowerInclusive = versionRange[0] == '['; var upperInclusive = versionRange[versionRange.Length - 1] == ']'; // (1.0) = invalid if (!isRange && !lowerInclusive && !upperInclusive) return false; // [1.0] = x == 1.0 if (!isRange && lowerInclusive && upperInclusive) { var versionString = versionRange.Substring(1, versionRange.Length - 2); var version = new SemanticVersion(versionString); range = new SemanticVersionRange(new EqualsRule(version)); return true; } var rangeParts = versionRange.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries); // check if we have an invalid range, eg. ",1.0" or [1.0," // if we get here, we should only have ranges which contains a comma and either // [ or ( in the beginning and ) or ] in the end. if (rangeParts.Length != 2) return false; // Skip first character to get just the version var lowerVersion = rangeParts[0].Substring(1); // Skip last character to get just the version var upperVersion = rangeParts[1].Substring(0, rangeParts[1].Length - 1); // Both versions cannot be null or empty if (String.IsNullOrEmpty(lowerVersion) && String.IsNullOrEmpty(upperVersion)) return false; if (String.IsNullOrEmpty(lowerVersion)) { Rule rule; if (upperInclusive) { rule = new LessThanOrEqualsRule(upperVersion); } else { rule = new LessThanRule(upperVersion); } range = new SemanticVersionRange(rule); return true; } if (String.IsNullOrEmpty(upperVersion)) { Rule rule; if (lowerInclusive) { rule = new GreaterThanOrEqualsRule(lowerVersion); } else { rule = new GreaterThanRule(lowerVersion); } range = new SemanticVersionRange(rule); return true; } Rule upperRule; Rule lowerRule; if (upperInclusive) { upperRule = new LessThanOrEqualsRule(upperVersion); } else { upperRule = new LessThanRule(upperVersion); } if (lowerInclusive) { lowerRule = new GreaterThanOrEqualsRule(lowerVersion); } else { lowerRule = new GreaterThanRule(lowerVersion); } range = new SemanticVersionRange(lowerRule, upperRule); return true; } catch (Exception e) { range = null; exception = e; return false; } }
public void Should_Return_True_When_Left_And_Right_Are_Same_Version() { // Given var left = new SemanticVersion(1, 0, 0, "a"); var right = new SemanticVersion(1, 0, 0, "a"); // When, Then Assert.True(left == right); }