/// <summary> /// Constructs a SemVersionPreRelease tag /// </summary> /// <param name="releaseType">Either Alpha or Beta typically</param> /// <param name="releaseNumber">The release number to set.</param> /// <param name="incrementType"></param> public SemVersionPreRelease(string releaseType, int releaseNumber, IncrementTypeEnum incrementType) { IsValidReleaseType(releaseType); ReleaseType = releaseType; ReleaseNumber = releaseNumber; IncrementType = incrementType; }
public void BumpPatch_Success(string preRelease, IncrementTypeEnum incrementType, string expected) { SemVersionPreRelease start = new SemVersionPreRelease(preRelease); if (incrementType == IncrementTypeEnum.Patch) { start.BumpPatch(); } else if (incrementType == IncrementTypeEnum.Minor) { start.BumpMinor(); } else if (incrementType == IncrementTypeEnum.Major) { start.BumpMajor(); } else { start.BumpVersion(); } SemVersionPreRelease end = new SemVersionPreRelease(expected); Assert.AreEqual(expected, start.Tag(), "A10:"); Assert.AreEqual(end.ReleaseNumber, start.ReleaseNumber, "A20:"); Assert.AreEqual(start.ReleaseType, end.ReleaseType, "A30:"); Assert.AreEqual(end.IncrementType, start.IncrementType, "A40:"); }
/// <summary> /// Bumps the pre-release numeric component by 1 and sets the IncrementType to major. /// </summary> public void BumpMajor() { if (IncrementType < IncrementTypeEnum.Major) { IncrementType = IncrementTypeEnum.Major; } ReleaseNumber++; }
public void Tag_success(string releaseType, int numeric, IncrementTypeEnum incrementType, string expTag) { SemVersionPreRelease sem = new SemVersionPreRelease(releaseType, numeric, incrementType); Assert.AreEqual(releaseType, sem.ReleaseType, "A10:"); Assert.AreEqual(numeric, sem.ReleaseNumber, "A20:"); Assert.AreEqual(incrementType, sem.IncrementType, "A30:"); Assert.AreEqual(expTag, sem.Tag(), "A40:"); }
/// <summary> /// Increases the pre-release numeric component by 1 and sets IncrementType to Patch. /// </summary> public void BumpPatch() { if (IncrementType == IncrementTypeEnum.None) { IncrementType = IncrementTypeEnum.Patch; } ReleaseNumber++; }
/// <summary> /// Constructor /// </summary> /// <param name="preReleaseTag">An already existing pre-release tag in string format</param> public SemVersionPreRelease(string preReleaseTag) { // The normal should be alpha-0002, but there may be some that have alpha.0002, we accept either. int index = preReleaseTag.IndexOf('-'); if (index == -1) { index = preReleaseTag.IndexOf('.'); if (index == -1) { throw new ArgumentException("Unable to find the . or - in the prerelease portion of the semanticVersion [" + preReleaseTag + "]"); } } string trailer = preReleaseTag.Substring(++index); // If the trailer ends with a alphabetic character then its telling us its increment Type if (trailer.EndsWith(SEMPRE_PATCH)) { IncrementType = IncrementTypeEnum.Patch; } else if (trailer.EndsWith(SEMPRE_MINOR)) { IncrementType = IncrementTypeEnum.Minor; } else if (trailer.EndsWith(SEMPRE_MAJOR)) { IncrementType = IncrementTypeEnum.Major; } else { IncrementType = IncrementTypeEnum.None; } if (IncrementType != IncrementTypeEnum.None) { trailer = trailer.Substring(0, trailer.Length - 1); } bool isInt = int.TryParse(trailer, out int value); ControlFlow.Assert(isInt, "PreRelease tag of [" + preReleaseTag + "] does not contain an integer component after the -"); ReleaseNumber = value; ReleaseType = preReleaseTag.Substring(0, --index); IsValidReleaseType(ReleaseType); }
public void Constructor_String__Success(string preTag, bool success, string releaseType, int numValue, IncrementTypeEnum incrementType) { if (success) { Assert.DoesNotThrow(() => new SemVersionPreRelease(preTag), "A10:"); SemVersionPreRelease sem = new SemVersionPreRelease(preTag); Assert.AreEqual(releaseType, sem.ReleaseType, "A20:"); Assert.AreEqual(numValue, sem.ReleaseNumber); Assert.AreEqual(incrementType, sem.IncrementType, "A30:"); } else { Assert.Throws <Exception>(() => new SemVersionPreRelease(preTag), "A100:"); } }