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:");
        }
        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>
        /// Runs the Calculate Version process
        /// </summary>
        /// <returns></returns>
        protected override StageCompletionStatusEnum ExecuteProcess()
        {
            currentBranchName = CISession.GitProcessor.CurrentBranch.ToLower();

            GitBranchInfo comparisonBranch = null;


            string branchToFind = "";

            if (CISession.PublishTarget == PublishTargetEnum.Alpha)
            {
                branchToFind = "alpha";
            }
            if (CISession.PublishTarget == PublishTargetEnum.Beta)
            {
                branchToFind = "beta";
            }

            if (CISession.PublishTarget == PublishTargetEnum.Production)
            {
                branchToFind = CISession.GitProcessor.MainBranchName;
            }

            // Make sure branch exists.
            if (!CISession.GitBranches.TryGetValue(branchToFind, out comparisonBranch))
            {
                ControlFlow.Assert(true == false, "The destination branch [" + branchToFind + "] does not exist.  You must manually create this branch.");
            }

            // Get Main Branch info
            mainBranch = CISession.GitBranches [CISession.GitProcessor.MainBranchName];
            GitBranchInfo currentBranch = CISession.GitBranches [CISession.GitProcessor.CurrentBranch];


            // If version has been set by user manually, then we validate it and set it.
            if (CISession.ManuallySetVersion != null)
            {
                ControlFlow.Assert(CISession.ManuallySetVersion > currentBranch.LatestSemVersionOnBranch,
                                   "Manually set version must be greater than the most current version on the branch deploying to");
                string releaseType = "";

                if (CISession.PublishTarget == PublishTargetEnum.Alpha)
                {
                    releaseType = "alpha";
                }
                else if (CISession.PublishTarget == PublishTargetEnum.Beta)
                {
                    releaseType = "beta";
                }
                else if (CISession.PublishTarget == PublishTargetEnum.Production)
                {
                    newVersion            = CISession.ManuallySetVersion;
                    CISession.VersionInfo = new VersionInfo(newVersion, currentBranch.LatestCommitOnBranch.CommitHash);
                    return(StageCompletionStatusEnum.Success);
                }
                SemVersionPreRelease semPre = new SemVersionPreRelease(releaseType, 0, IncrementTypeEnum.None);
                newVersion            = new SemVersion(CISession.ManuallySetVersion.Major, CISession.ManuallySetVersion.Minor, CISession.ManuallySetVersion.Patch, semPre.Tag());
                CISession.VersionInfo = new VersionInfo(newVersion, currentBranch.LatestCommitOnBranch.CommitHash);
                AOT_Info("Success:  Manual Version Set:  " + newVersion);
                return(StageCompletionStatusEnum.Success);
            }


            // If the top commit on branch is already version tagged, then we are assuming they want to
            // finish off later steps that might not have run successfully previously.
            if ((CISession.PublishTarget == PublishTargetEnum.Production && currentBranch.Name == mainBranch.Name) || CISession.PublishTarget != PublishTargetEnum.Production)
            {
                SemVersion mostCurrentSemVerOnBranch = currentBranch.LatestCommitOnBranch.GetGreatestVersionTag();
                SemVersion zero = new SemVersion(0, 0, 0);
                if (mostCurrentSemVerOnBranch > zero)
                {
                    CISession.WasPreviouslyCommitted = true;
                    newVersion            = mostCurrentSemVerOnBranch;
                    CISession.VersionInfo = new VersionInfo(newVersion, currentBranch.LatestCommitOnBranch.CommitHash);
                    AOT_Warning("No changes require a version change.  Assuming this is a continuation of a prior post compile failure.");
                    AOT_Info("No Version Change!  Existing Version is:  " + newVersion);
                    return(StageCompletionStatusEnum.Success);
                }
            }


            // Determine the potential version bump...
            incrementPatch = (currentBranchName.StartsWith("fix") || currentBranchName.StartsWith("bug"));
            incrementMinor = (currentBranchName.StartsWith("feature") || currentBranchName.StartsWith("feat"));
            incrementMajor = (currentBranchName.StartsWith("major"));

            // Set IncrementPatch if it is not a key branch name and none of the above is set.
            if (!incrementMajor && !incrementMinor && !incrementPatch)
            {
                if (currentBranchName != "alpha" && currentBranchName != "beta" && currentBranchName != CISession.GitProcessor.MainBranchName)
                {
                    incrementPatch = true;
                }
            }

            string versionPreReleaseName = "alpha";

            if (CISession.PublishTarget == PublishTargetEnum.Beta)
            {
                versionPreReleaseName = "beta";
            }

            // Get most recent Version Tag for the desired branch type
            mostRecentBranchTypeVersion = GetMostRecentVersionTagOfBranch(currentBranch);
            //mostRecentBranchTypeVersion = CISession.GitProcessor.GetMostRecentVersionTagOfBranch(versionPreReleaseName);


            if (CISession.PublishTarget == PublishTargetEnum.Production)
            {
                CalculateMainVersion();
            }
            else if (CISession.PublishTarget == PublishTargetEnum.Alpha)
            {
                CalculateAlphaVersion(comparisonBranch);
            }
            else if (CISession.PublishTarget == PublishTargetEnum.Beta)
            {
                CalculateBetaVersion(comparisonBranch);
            }
            else
            {
                throw new ApplicationException("Publish Target of [" + CISession.PublishTarget.ToString() + "]  has no implemented functionality");
            }

            // Store the version that should be set for the build.
            CISession.VersionInfo = new VersionInfo(newVersion, currentBranch.LatestCommitOnBranch.CommitHash);

            AOT_Info("New Version is:  " + newVersion);

            return(StageCompletionStatusEnum.Success);
        }