|
| 1 | +using System.Collections.Generic; |
| 2 | +using System.IO; |
| 3 | +using System.Linq; |
| 4 | +using GitTools.Testing; |
| 5 | +using GitVersion.BuildServers; |
| 6 | +using GitVersion.MSBuildTask.Tasks; |
| 7 | +using GitVersionCore.Tests.Helpers; |
| 8 | +using GitVersionTask.Tests.Helpers; |
| 9 | +using LibGit2Sharp; |
| 10 | +using NUnit.Framework; |
| 11 | +using Shouldly; |
| 12 | + |
| 13 | +namespace GitVersion.MSBuildTask.Tests |
| 14 | +{ |
| 15 | + [TestFixture] |
| 16 | + public class GenerateGitVersionInformationTest : TestBase |
| 17 | + { |
| 18 | + [Test] |
| 19 | + public void GenerateGitVersionInformationTaskShouldCreateFile() |
| 20 | + { |
| 21 | + using var fixture = new EmptyRepositoryFixture(); |
| 22 | + fixture.MakeATaggedCommit("1.2.3"); |
| 23 | + fixture.MakeACommit(); |
| 24 | + |
| 25 | + var task = new GenerateGitVersionInformation |
| 26 | + { |
| 27 | + SolutionDirectory = fixture.RepositoryPath, |
| 28 | + ProjectFile = fixture.RepositoryPath, |
| 29 | + }; |
| 30 | + |
| 31 | + var msbuildFixture = new MsBuildFixture(); |
| 32 | + var result = msbuildFixture.Execute(task); |
| 33 | + |
| 34 | + result.Success.ShouldBe(true); |
| 35 | + result.Errors.ShouldBe(0); |
| 36 | + result.Task.GitVersionInformationFilePath.ShouldNotBeNull(); |
| 37 | + |
| 38 | + var fileContent = File.ReadAllText(result.Task.GitVersionInformationFilePath); |
| 39 | + fileContent.ShouldContain(@"FullSemVer = ""1.2.4+1"""); |
| 40 | + } |
| 41 | + |
| 42 | + [Test] |
| 43 | + public void GenerateGitVersionInformationTaskShouldCreateFileWhenRunningInBuildServer() |
| 44 | + { |
| 45 | + using var fixture = new RemoteRepositoryFixture(); |
| 46 | + fixture.Repository.MakeACommit(); |
| 47 | + fixture.Repository.MakeATaggedCommit("1.0.0"); |
| 48 | + fixture.Repository.MakeACommit(); |
| 49 | + fixture.Repository.CreateBranch("develop"); |
| 50 | + |
| 51 | + Commands.Fetch((Repository)fixture.LocalRepositoryFixture.Repository, fixture.LocalRepositoryFixture.Repository.Network.Remotes.First().Name, new string[0], new FetchOptions(), null); |
| 52 | + Commands.Checkout(fixture.LocalRepositoryFixture.Repository, fixture.Repository.Head.Tip); |
| 53 | + fixture.LocalRepositoryFixture.Repository.Branches.Remove("master"); |
| 54 | + fixture.InitializeRepo(); |
| 55 | + |
| 56 | + var task = new GenerateGitVersionInformation |
| 57 | + { |
| 58 | + SolutionDirectory = fixture.LocalRepositoryFixture.RepositoryPath, |
| 59 | + ProjectFile = fixture.LocalRepositoryFixture.RepositoryPath, |
| 60 | + }; |
| 61 | + |
| 62 | + var env = new Dictionary<string, string> |
| 63 | + { |
| 64 | + { AzurePipelines.EnvironmentVariableName, "true" } |
| 65 | + }; |
| 66 | + |
| 67 | + var msbuildFixture = new MsBuildFixture(); |
| 68 | + msbuildFixture.WithEnv(env.ToArray()); |
| 69 | + var result = msbuildFixture.Execute(task); |
| 70 | + |
| 71 | + result.Success.ShouldBe(true); |
| 72 | + result.Errors.ShouldBe(0); |
| 73 | + result.Task.GitVersionInformationFilePath.ShouldNotBeNull(); |
| 74 | + |
| 75 | + var fileContent = File.ReadAllText(result.Task.GitVersionInformationFilePath); |
| 76 | + fileContent.ShouldContain(@"FullSemVer = ""1.0.1+1"""); |
| 77 | + } |
| 78 | + } |
| 79 | +} |
0 commit comments