|
| 1 | +namespace GitVersionExe.Tests |
| 2 | +{ |
| 3 | + using System.IO; |
| 4 | + using System.Linq; |
| 5 | + using NUnit.Framework; |
| 6 | + |
| 7 | + using GitVersion; |
| 8 | + using GitTools.Testing; |
| 9 | + using System.Collections.Generic; |
| 10 | + using System.Xml; |
| 11 | + |
| 12 | + [TestFixture] |
| 13 | + [Parallelizable(ParallelScope.None)] |
| 14 | + class UpdateWixVersionFileTests |
| 15 | + { |
| 16 | + private string WixVersionFileName; |
| 17 | + |
| 18 | + [SetUp] |
| 19 | + public void Setup() |
| 20 | + { |
| 21 | + WixVersionFileName = WixVersionFileUpdater.GetWixVersionFileName(); |
| 22 | + } |
| 23 | + |
| 24 | + [Test] |
| 25 | + [Category("NoMono")] |
| 26 | + [Description("Doesn't work on Mono/Unix because of the path heuristics that needs to be done there in order to figure out whether the first argument actually is a path.")] |
| 27 | + public void WixVersionFileCreationTest() |
| 28 | + { |
| 29 | + using (var fixture = new EmptyRepositoryFixture()) |
| 30 | + { |
| 31 | + fixture.MakeATaggedCommit("1.2.3"); |
| 32 | + fixture.MakeACommit(); |
| 33 | + |
| 34 | + GitVersionHelper.ExecuteIn(fixture.RepositoryPath, arguments: " -updatewixversionfile"); |
| 35 | + Assert.IsTrue(File.Exists(Path.Combine(fixture.RepositoryPath, WixVersionFileName))); |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + [Test] |
| 40 | + [Category("NoMono")] |
| 41 | + [Description("Doesn't work on Mono/Unix because of the path heuristics that needs to be done there in order to figure out whether the first argument actually is a path.")] |
| 42 | + public void WixVersionFileVarCountTest() |
| 43 | + { |
| 44 | + //Make sure we have captured all the version variables by count in the Wix version file |
| 45 | + using (var fixture = new EmptyRepositoryFixture()) |
| 46 | + { |
| 47 | + fixture.MakeATaggedCommit("1.2.3"); |
| 48 | + fixture.MakeACommit(); |
| 49 | + |
| 50 | + var gitVersionExecutionResults = GitVersionHelper.ExecuteIn(fixture.RepositoryPath, arguments: null); |
| 51 | + VersionVariables vars = gitVersionExecutionResults.OutputVariables; |
| 52 | + |
| 53 | + GitVersionHelper.ExecuteIn(fixture.RepositoryPath, arguments: " -updatewixversionfile"); |
| 54 | + |
| 55 | + var gitVersionVarsInWix = GetGitVersionVarsInWixFile(Path.Combine(fixture.RepositoryPath, WixVersionFileName)); |
| 56 | + var gitVersionVars = VersionVariables.AvailableVariables; |
| 57 | + |
| 58 | + Assert.AreEqual(gitVersionVars.Count(), gitVersionVarsInWix.Count); |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + [Test] |
| 63 | + [Category("NoMono")] |
| 64 | + [Description("Doesn't work on Mono/Unix because of the path heuristics that needs to be done there in order to figure out whether the first argument actually is a path.")] |
| 65 | + public void WixVersionFileContentTest() |
| 66 | + { |
| 67 | + using (var fixture = new EmptyRepositoryFixture()) |
| 68 | + { |
| 69 | + fixture.MakeATaggedCommit("1.2.3"); |
| 70 | + fixture.MakeACommit(); |
| 71 | + |
| 72 | + var gitVersionExecutionResults = GitVersionHelper.ExecuteIn(fixture.RepositoryPath, arguments: null); |
| 73 | + VersionVariables vars = gitVersionExecutionResults.OutputVariables; |
| 74 | + |
| 75 | + GitVersionHelper.ExecuteIn(fixture.RepositoryPath, arguments: " -updatewixversionfile"); |
| 76 | + |
| 77 | + var gitVersionVarsInWix = GetGitVersionVarsInWixFile(Path.Combine(fixture.RepositoryPath, WixVersionFileName)); |
| 78 | + var gitVersionVars = VersionVariables.AvailableVariables; |
| 79 | + |
| 80 | + foreach (var variable in gitVersionVars) |
| 81 | + { |
| 82 | + string value = null; |
| 83 | + vars.TryGetValue(variable, out value); |
| 84 | + //Make sure the variable is present in the Wix file |
| 85 | + Assert.IsTrue(gitVersionVarsInWix.ContainsKey(variable)); |
| 86 | + //Make sure the values are equal |
| 87 | + Assert.AreEqual(value, gitVersionVarsInWix[variable]); |
| 88 | + } |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | + private Dictionary<string, string> GetGitVersionVarsInWixFile(string file) |
| 93 | + { |
| 94 | + var gitVersionVarsInWix = new Dictionary<string, string>(); |
| 95 | + using (var reader = new XmlTextReader(file)) |
| 96 | + { |
| 97 | + while (reader.Read()) |
| 98 | + { |
| 99 | + if (reader.Name == "define") |
| 100 | + { |
| 101 | + string[] component = reader.Value.Split('='); |
| 102 | + gitVersionVarsInWix[component[0]] = component[1].TrimStart('"').TrimEnd('"'); |
| 103 | + } |
| 104 | + } |
| 105 | + } |
| 106 | + return gitVersionVarsInWix; |
| 107 | + } |
| 108 | + } |
| 109 | +} |
0 commit comments