Exemplo n.º 1
0
    private static void AssertMergeMessage(string message, string expectedVersion, IEnumerable <ICommit> parents, Config config = null)
    {
        var commit = GitToolsTestingExtensions.CreateMockCommit();

        commit.Message.Returns(message);
        commit.Parents.Returns(parents);

        var mockBranch = GitToolsTestingExtensions.CreateMockBranch(MainBranch, commit, GitToolsTestingExtensions.CreateMockCommit());

        var mockRepository = Substitute.For <IGitRepository>();

        mockRepository.Head.Returns(mockBranch);
        mockRepository.Commits.Returns(mockBranch.Commits);

        var contextBuilder = new GitVersionContextBuilder()
                             .WithConfig(config ?? new Config())
                             .WithRepository(mockRepository);

        contextBuilder.Build();
        var strategy = contextBuilder.ServicesProvider.GetServiceForType <IVersionStrategy, MergeMessageVersionStrategy>();

        var baseVersion = strategy.GetVersions().SingleOrDefault();

        if (expectedVersion == null)
        {
            baseVersion.ShouldBe(null);
        }
        else
        {
            baseVersion.ShouldNotBeNull();
            baseVersion.SemanticVersion.ToString().ShouldBe(expectedVersion);
        }
    }
Exemplo n.º 2
0
        private void AssertMergeMessage(string message, string expectedVersion, IList <ICommit> parents, Config config = null)
        {
            var commit = new MockCommit
            {
                MessageEx = message,
                ParentsEx = parents
            };

            var contextBuilder = new GitVersionContextBuilder()
                                 .WithConfig(config ?? new Config())
                                 .WithRepository(new MockRepository
            {
                Head = new MockBranch("master")
                {
                    commit,
                    new MockCommit()
                }
            });

            contextBuilder.Build();
            var strategy = contextBuilder.ServicesProvider.GetServiceForType <IVersionStrategy, MergeMessageVersionStrategy>();

            var baseVersion = strategy.GetVersions().SingleOrDefault();

            if (expectedVersion == null)
            {
                baseVersion.ShouldBe(null);
            }
            else
            {
                baseVersion.ShouldNotBeNull();
                baseVersion.SemanticVersion.ToString().ShouldBe(expectedVersion);
            }
        }
Exemplo n.º 3
0
    public void ShouldNotAllowIncrementOfVersion()
    {
        // When a branch is merged in you want to start building stable packages of that version
        // So we shouldn't bump the version
        var mockCommit = GitToolsTestingExtensions.CreateMockCommit();

        mockCommit.Message.Returns("Merge branch 'release-0.1.5'");
        mockCommit.Parents.Returns(GetParents(true));

        var mockBranch = GitToolsTestingExtensions.CreateMockBranch(MainBranch, mockCommit);
        var branches   = Substitute.For <IBranchCollection>();

        branches.GetEnumerator().Returns(_ => ((IEnumerable <IBranch>) new[] { mockBranch }).GetEnumerator());

        var mockRepository = Substitute.For <IGitRepository>();

        mockRepository.Head.Returns(mockBranch);
        mockRepository.Branches.Returns(branches);
        mockRepository.Commits.Returns(mockBranch.Commits);

        var contextBuilder = new GitVersionContextBuilder().WithRepository(mockRepository);

        contextBuilder.Build();
        var strategy = contextBuilder.ServicesProvider.GetServiceForType <IVersionStrategy, MergeMessageVersionStrategy>();

        var baseVersion = strategy.GetVersions().Single();

        baseVersion.ShouldIncrement.ShouldBe(false);
    }
Exemplo n.º 4
0
        public void ReturnsNullWhenNoNextVersionIsInConfig()
        {
            var gitVersionContext = contextBuilder.Build();

            var baseVersion = strategy.GetVersions(gitVersionContext).SingleOrDefault();

            baseVersion.ShouldBe(null);
        }
        public void ReturnsNullWhenNoNextVersionIsInConfig()
        {
            var contextBuilder = new GitVersionContextBuilder();
            var sut = new ConfigNextVersionBaseVersionStrategy();

            var baseVersion = sut.GetVersions(contextBuilder.Build()).SingleOrDefault();

            baseVersion.ShouldBe(null);
        }
        public void ReturnsNullWhenNoNextVersionIsInConfig()
        {
            var contextBuilder = new GitVersionContextBuilder();
            var sut            = new ConfigNextVersionBaseVersionStrategy();

            var baseVersion = sut.GetVersions(contextBuilder.Build()).SingleOrDefault();

            baseVersion.ShouldBe(null);
        }
Exemplo n.º 7
0
    private static IBaseVersionCalculator GetBaseVersionCalculator(Action <GitVersionContextBuilder> contextBuilderAction)
    {
        var contextBuilder = new GitVersionContextBuilder();

        contextBuilderAction.Invoke(contextBuilder);

        contextBuilder.Build();
        contextBuilder.ServicesProvider.ShouldNotBeNull();
        return(contextBuilder.ServicesProvider.GetRequiredService <IBaseVersionCalculator>());
    }
        public void NextVersionCanHavePatch()
        {
            var contextBuilder = new GitVersionContextBuilder()
                .WithConfig(new Config
                {
                    NextVersion = "2.12.654651698"
                });
            var sut = new ConfigNextVersionBaseVersionStrategy();

            var baseVersion = sut.GetVersions(contextBuilder.Build()).Single();

            baseVersion.SemanticVersion.ToString().ShouldBe("2.12.654651698");
        }
        public void NextVersionCanHaveEnormousMinorVersion()
        {
            var contextBuilder = new GitVersionContextBuilder()
                .WithConfig(new Config
                {
                    NextVersion = "2.118998723"
                });
            var sut = new ConfigNextVersionBaseVersionStrategy();

            var baseVersion = sut.GetVersions(contextBuilder.Build()).Single();

            baseVersion.SemanticVersion.ToString().ShouldBe("2.118998723.0");
        }
        public void NextVersionCanHavePatch()
        {
            var contextBuilder = new GitVersionContextBuilder()
                                 .WithConfig(new Config
            {
                NextVersion = "2.12.654651698"
            });
            var sut = new ConfigNextVersionBaseVersionStrategy();

            var baseVersion = sut.GetVersions(contextBuilder.Build()).Single();

            baseVersion.SemanticVersion.ToString().ShouldBe("2.12.654651698");
        }
        public void NextVersionCanHaveEnormousMinorVersion()
        {
            var contextBuilder = new GitVersionContextBuilder()
                                 .WithConfig(new Config
            {
                NextVersion = "2.118998723"
            });
            var sut = new ConfigNextVersionBaseVersionStrategy();

            var baseVersion = sut.GetVersions(contextBuilder.Build()).Single();

            baseVersion.SemanticVersion.ToString().ShouldBe("2.118998723.0");
        }
        public void NextVersionCanBeInteger()
        {
            var contextBuilder = new GitVersionContextBuilder()
                                 .WithConfig(new Config
            {
                NextVersion = "2"
            });
            var sut = new ConfigNextVersionVersionStrategy();

            var baseVersion = sut.GetVersions(contextBuilder.Build()).Single();

            baseVersion.SemanticVersion.ToString().ShouldBe("2.0.0");
        }
        public void ShouldNotBeIncremented()
        {
            var contextBuilder = new GitVersionContextBuilder()
                .WithConfig(new Config
                {
                    NextVersion = "1.0.0"
                });
            var sut = new ConfigNextVersionBaseVersionStrategy();

            var baseVersion = sut.GetVersions(contextBuilder.Build()).Single();

            baseVersion.ShouldIncrement.ShouldBe(false);
            baseVersion.SemanticVersion.ToString().ShouldBe("1.0.0");
        }
        private static BaseVersion GetBaseVersion(Config config = null)
        {
            var contextBuilder = new GitVersionContextBuilder();

            if (config != null)
            {
                contextBuilder = contextBuilder.WithConfig(config);
            }

            contextBuilder.Build();
            var strategy = contextBuilder.ServicesProvider.GetServiceForType <IVersionStrategy, ConfigNextVersionVersionStrategy>();

            return(strategy.GetVersions().SingleOrDefault());
        }
        public void ShouldNotBeIncremented()
        {
            var contextBuilder = new GitVersionContextBuilder()
                                 .WithConfig(new Config
            {
                NextVersion = "1.0.0"
            });
            var sut = new ConfigNextVersionBaseVersionStrategy();

            var baseVersion = sut.GetVersions(contextBuilder.Build()).Single();

            baseVersion.ShouldIncrement.ShouldBe(false);
            baseVersion.SemanticVersion.ToString().ShouldBe("1.0.0");
        }
Exemplo n.º 16
0
        public void ShouldNotAllowIncrementOfVersion()
        {
            // When a branch is merged in you want to start building stable packages of that version
            // So we shouldn't bump the version
            var contextBuilder = new GitVersionContextBuilder().WithRepository(new MockRepository
            {
                Head = new MockBranch("master")
                {
                    new MockCommit
                    {
                        MessageEx = "Merge branch 'release-0.1.5'",
                        ParentsEx = GetParents(true)
                    }
                }
            });

            contextBuilder.Build();
            var strategy = contextBuilder.ServicesProvider.GetServiceForType <IVersionStrategy, MergeMessageVersionStrategy>();

            var baseVersion = strategy.GetVersions().Single();

            baseVersion.ShouldIncrement.ShouldBe(false);
        }