Beispiel #1
0
        public void VerifyNullGuard2()
        {
            var commit = GitToolsTestingExtensions.CreateMockCommit();
            var sut    = new ShaVersionFilter(new[] { commit.Sha });

            Should.Throw <ArgumentNullException>(() => sut.Exclude(null, out _));
        }
Beispiel #2
0
        public void CanInheritVersioningMode(VersioningMode mode)
        {
            using var fixture = new EmptyRepositoryFixture();

            var config = new ConfigurationBuilder()
                         .Add(new Config {
                VersioningMode = mode
            })
                         .Build();

            const string branchName = "master";

            var mockCommit = GitToolsTestingExtensions.CreateMockCommit();
            var mockBranch = GitToolsTestingExtensions.CreateMockBranch(branchName, 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 context = GetGitVersionContext(fixture.RepositoryPath, mockRepository, branchName, config);

            context.Configuration.VersioningMode.ShouldBe(mode);
        }
Beispiel #3
0
        public void WhenShaMismatchShouldNotExclude()
        {
            var commit  = GitToolsTestingExtensions.CreateMockCommit();
            var version = new BaseVersion("dummy", false, new SemanticVersion(1), commit, string.Empty);
            var sut     = new ShaVersionFilter(new[] { "mismatched" });

            sut.Exclude(version, out var reason).ShouldBeFalse();
            reason.ShouldBeNull();
        }
Beispiel #4
0
        public void WhenShaMatchShouldExcludeWithReason()
        {
            var commit  = GitToolsTestingExtensions.CreateMockCommit();
            var version = new BaseVersion("dummy", false, new SemanticVersion(1), commit, string.Empty);
            var sut     = new ShaVersionFilter(new[] { commit.Sha });

            sut.Exclude(version, out var reason).ShouldBeTrue();
            reason.ShouldNotBeNullOrWhiteSpace();
        }
Beispiel #5
0
        public void WhenShaMismatchShouldNotExclude()
        {
            var commit   = GitToolsTestingExtensions.CreateMockCommit();
            var version  = new BaseVersion("dummy", false, new SemanticVersion(1), commit, string.Empty);
            var pastDate = DateTimeOffset.UtcNow.AddYears(-1);
            var sut      = new MinDateVersionFilter(pastDate);

            sut.Exclude(version, out var reason).ShouldBeFalse();
            reason.ShouldBeNull();
        }
Beispiel #6
0
        public void WhenCommitShouldExcludeWithReason()
        {
            var commit     = GitToolsTestingExtensions.CreateMockCommit();
            var version    = new BaseVersion("dummy", false, new SemanticVersion(1), commit, string.Empty);
            var futureDate = DateTimeOffset.UtcNow.AddYears(1);
            var sut        = new MinDateVersionFilter(futureDate);

            sut.Exclude(version, out var reason).ShouldBeTrue();
            reason.ShouldNotBeNullOrWhiteSpace();
        }
Beispiel #7
0
        public void UsesFirstBranchConfigWhenMultipleMatch()
        {
            using var fixture = new EmptyRepositoryFixture();

            var branchConfig = new BranchConfig
            {
                VersioningMode = VersioningMode.Mainline,
                Increment      = IncrementStrategy.None,
                PreventIncrementOfMergedBranchVersion = false,
                TrackMergeTarget      = false,
                TracksReleaseBranches = false,
                IsReleaseBranch       = false,
                SourceBranches        = new HashSet <string>()
            };
            var config = new ConfigurationBuilder()
                         .Add(new Config
            {
                VersioningMode = VersioningMode.ContinuousDelivery,
                Branches       =
                {
                    { "release/latest", new BranchConfig(branchConfig)
                            {
                                Increment = IncrementStrategy.None, Regex = "release/latest"
                            } },
                    { "release", new BranchConfig(branchConfig)
                            {
                                Increment = IncrementStrategy.Patch, Regex = "releases?[/-]"
                            } }
                }
            })
                         .Build();

            var releaseLatestBranch  = GitToolsTestingExtensions.CreateMockBranch("release/latest", GitToolsTestingExtensions.CreateMockCommit());
            var releaseVersionBranch = GitToolsTestingExtensions.CreateMockBranch("release/1.0.0", GitToolsTestingExtensions.CreateMockCommit());

            var branches = Substitute.For <IBranchCollection>();

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

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

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

            var latestContext = GetGitVersionContext(fixture.RepositoryPath, mockRepository, releaseLatestBranch.Name.Canonical, config);

            latestContext.Configuration.Increment.ShouldBe(IncrementStrategy.None);

            mockRepository.Head.Returns(releaseVersionBranch);
            var versionContext = GetGitVersionContext(fixture.RepositoryPath, mockRepository, releaseVersionBranch.Name.Canonical, config);

            versionContext.Configuration.Increment.ShouldBe(IncrementStrategy.Patch);
        }
        private GitVersionContextBuilder AddBranch(string branchName)
        {
            var mockCommit = GitToolsTestingExtensions.CreateMockCommit();
            var mockBranch = GitToolsTestingExtensions.CreateMockBranch(branchName, mockCommit);

            var branches = repository.Branches.ToList();

            branches.Add(mockBranch);
            repository.Branches.GetEnumerator().Returns(_ => ((IEnumerable <IBranch>)branches).GetEnumerator());
            repository.Head.Returns(mockBranch);
            return(this);
        }
        private static IGitRepository CreateRepository()
        {
            var mockCommit = GitToolsTestingExtensions.CreateMockCommit();
            var mockBranch = GitToolsTestingExtensions.CreateMockBranch("master", mockCommit);
            var branches   = Substitute.For <IBranchCollection>();

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

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

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

            return(mockRepository);
        }
Beispiel #10
0
        public void UsesBranchSpecificConfigOverTopLevelDefaults()
        {
            using var fixture = new EmptyRepositoryFixture();

            const string branchName = "develop";
            var          config     = new ConfigurationBuilder()
                                      .Add(new Config
            {
                VersioningMode = VersioningMode.ContinuousDelivery,
                Branches       =
                {
                    {
                        branchName, new BranchConfig
                        {
                            VersioningMode = VersioningMode.ContinuousDeployment,
                            Tag            = "alpha"
                        }
                    }
                }
            })
                                      .Build();

            var master  = GitToolsTestingExtensions.CreateMockBranch("master", GitToolsTestingExtensions.CreateMockCommit());
            var develop = GitToolsTestingExtensions.CreateMockBranch(branchName, GitToolsTestingExtensions.CreateMockCommit());

            var branches = Substitute.For <IBranchCollection>();

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

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

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

            var context = GetGitVersionContext(fixture.RepositoryPath, mockRepository, branchName, config);

            context.Configuration.Tag.ShouldBe("alpha");
        }