forked from GitTools/GitVersion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpdateWixVersionFileTests.cs
88 lines (71 loc) · 3.16 KB
/
UpdateWixVersionFileTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using GitVersion.Helpers;
using GitVersion.Output.WixUpdater;
using GitVersion.OutputVariables;
namespace GitVersion.App.Tests;
[TestFixture]
[Parallelizable(ParallelScope.None)]
internal class UpdateWixVersionFileTests
{
private string wixVersionFileName;
[SetUp]
public void Setup() => this.wixVersionFileName = WixVersionFileUpdater.WixVersionFileName;
[Test]
public void WixVersionFileCreationTest()
{
using var fixture = new EmptyRepositoryFixture();
fixture.MakeATaggedCommit("1.2.3");
fixture.MakeACommit();
GitVersionHelper.ExecuteIn(fixture.RepositoryPath, arguments: " /updatewixversionfile");
Assert.That(File.Exists(PathHelper.Combine(fixture.RepositoryPath, this.wixVersionFileName)), Is.True);
}
[Test]
public void WixVersionFileVarCountTest()
{
//Make sure we have captured all the version variables by count in the Wix version file
using var fixture = new EmptyRepositoryFixture();
fixture.MakeATaggedCommit("1.2.3");
fixture.MakeACommit();
GitVersionHelper.ExecuteIn(fixture.RepositoryPath, arguments: null);
GitVersionHelper.ExecuteIn(fixture.RepositoryPath, arguments: " /updatewixversionfile");
var gitVersionVarsInWix = GetGitVersionVarsInWixFile(PathHelper.Combine(fixture.RepositoryPath, this.wixVersionFileName));
var gitVersionVars = GitVersionVariables.AvailableVariables;
Assert.That(gitVersionVarsInWix, Has.Count.EqualTo(gitVersionVars.Count()));
}
[Test]
public void WixVersionFileContentTest()
{
using var fixture = new EmptyRepositoryFixture();
fixture.MakeATaggedCommit("1.2.3");
fixture.MakeACommit();
var gitVersionExecutionResults = GitVersionHelper.ExecuteIn(fixture.RepositoryPath, arguments: null);
var vars = gitVersionExecutionResults.OutputVariables;
vars.ShouldNotBeNull();
GitVersionHelper.ExecuteIn(fixture.RepositoryPath, arguments: " /updatewixversionfile");
var gitVersionVarsInWix = GetGitVersionVarsInWixFile(PathHelper.Combine(fixture.RepositoryPath, this.wixVersionFileName));
var gitVersionVars = GitVersionVariables.AvailableVariables;
foreach (var variable in gitVersionVars)
{
vars.TryGetValue(variable, out var value);
Assert.Multiple(() =>
{
//Make sure the variable is present in the Wix file
Assert.That(gitVersionVarsInWix.ContainsKey(variable), Is.True);
//Make sure the values are equal
Assert.That(gitVersionVarsInWix[variable], Is.EqualTo(value));
});
}
}
private static Dictionary<string, string> GetGitVersionVarsInWixFile(string file)
{
var gitVersionVarsInWix = new Dictionary<string, string>();
using var reader = new XmlTextReader(file);
while (reader.Read())
{
if (reader.Name != "define")
continue;
var component = reader.Value.Split('=');
gitVersionVarsInWix[component[0]] = component[1].TrimStart('"').TrimEnd('"');
}
return gitVersionVarsInWix;
}
}