public void CalculateNotTaggedCommitVersionTest()
        {
            var baseCalculatorMock = new Mock <IBaseVersionCalculator>();
            var baseCalculator     = baseCalculatorMock.Object;

            baseCalculatorMock.Setup(c => c.CalculateVersion(It.IsAny <IVersionContext>()))
            .Returns(new BaseVersion("", new SemanticVersion(1), null, shouldIncrement: true));

            var metadatCalculatorMock = new Mock <IMetadataCalculator>();
            var metadataCalculator    = metadatCalculatorMock.Object;

            metadatCalculatorMock.Setup(m => m.CalculateMetadata(
                                            It.IsAny <IVersionContext>(),
                                            It.IsAny <ICommit>()))
            .Returns((BuildMetadata)null);

            var tagCalculatorMock = new Mock <IPreReleaseTagCalculator>();
            var tagCalculator     = tagCalculatorMock.Object;

            tagCalculatorMock.Setup(t => t.CalculateTag(
                                        It.IsAny <IVersionContext>(),
                                        It.IsAny <SemanticVersion>(),
                                        It.IsAny <string>()))
            .Returns((PreReleaseTag)null);

            var contextMock = new Mock <IVersionContext>();
            var context     = contextMock.Object;

            contextMock.Setup(c => c.Configuration).Returns(new TestEffectiveConfiguration());
            contextMock.Setup(c => c.IsCurrentCommitTagged).Returns(false);

            var versionCalculator = new NextVersionCalculator(
                baseCalculator,
                metadataCalculator,
                tagCalculator);

            var version  = versionCalculator.CalculateVersion(context);
            var expected = SemanticVersion.Parse("1.0.1");

            Assert.That(version, Is.EqualTo(expected));
        }
Esempio n. 2
0
        public SemanticVersion FindVersion(IVersionContext context)
        {
            var branchName = context.CurrentBranch.Name;
            var commit     = context.CurrentCommit == null ? "-" : context.CurrentCommit.Hash;

            Logger.WriteInfo($"Running against branch: {branchName} ({commit})");

            if (context.IsCurrentCommitTagged)
            {
                Logger.WriteInfo(
                    $"Current commit is tagged with version {context.CurrentCommitTaggedVersion}, "
                    + "version calcuation is for metadata only.");
            }

            var calculator = new NextVersionCalculator(
                new BaseVersionCalculator(context
                                          .Configuration
                                          .BaseVersionStrategies
                                          .ToArray()));

            return(calculator.CalculateVersion(context));
        }