Skip to content

Commit 5a2fb17

Browse files
DanielRoseJakeGinnivan
authored andcommitted
Fix unit tests.
The GitVersionContextBuilder does not create an actual repository, causing exceptions.
1 parent d2f4d34 commit 5a2fb17

File tree

1 file changed

+44
-30
lines changed

1 file changed

+44
-30
lines changed

src/GitVersionCore.Tests/VersionCalculation/NextVersionCalculatorTests.cs

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -58,47 +58,61 @@ public void AppliesBranchPreReleaseTag()
5858
[Test]
5959
public void PreReleaseTagCanUseBranchName()
6060
{
61-
var baseCalculator = new TestBaseVersionCalculator(false, new SemanticVersion(1), new MockCommit());
62-
var semanticVersionBuildMetaData = new SemanticVersionBuildMetaData(2, "develop", "b1a34e", DateTimeOffset.Now);
63-
var sut = new NextVersionCalculator(baseCalculator, new TestMetaDataCalculator(semanticVersionBuildMetaData));
64-
var config = new Config();
65-
config.Branches.Add("custom", new BranchConfig
61+
var config = new Config
6662
{
67-
Regex = "custom/",
68-
Tag = "useBranchName"
69-
});
70-
var context = new GitVersionContextBuilder()
71-
.WithConfig(config)
72-
.WithDevelopBranch()
73-
.AddBranch("custom/foo")
74-
.Build();
63+
NextVersion = "1.0.0",
64+
Branches = new Dictionary<string, BranchConfig>
65+
{
66+
{
67+
"custom", new BranchConfig
68+
{
69+
Regex = "custom/",
70+
Tag = "useBranchName"
71+
}
72+
}
73+
}
74+
};
7575

76-
var version = sut.FindVersion(context);
76+
using (var fixture = new EmptyRepositoryFixture())
77+
{
78+
fixture.MakeACommit();
79+
fixture.BranchTo("develop");
80+
fixture.MakeACommit();
81+
fixture.BranchTo("custom/foo");
82+
fixture.MakeACommit();
7783

78-
version.ToString("f").ShouldBe("1.0.0-foo.1+2");
84+
fixture.AssertFullSemver(config, "1.0.0-foo.1+2");
85+
}
7986
}
8087

8188
[Test]
8289
public void PreReleaseTagCanUseBranchNameVariable()
8390
{
84-
var baseCalculator = new TestBaseVersionCalculator(false, new SemanticVersion(1), new MockCommit());
85-
var semanticVersionBuildMetaData = new SemanticVersionBuildMetaData(2, "develop", "b1a34e", DateTimeOffset.Now);
86-
var sut = new NextVersionCalculator(baseCalculator, new TestMetaDataCalculator(semanticVersionBuildMetaData));
87-
var config = new Config();
88-
config.Branches.Add("custom", new BranchConfig
91+
var config = new Config
8992
{
90-
Regex = "custom/",
91-
Tag = "alpha.{BranchName}"
92-
});
93-
var context = new GitVersionContextBuilder()
94-
.WithConfig(config)
95-
.WithDevelopBranch()
96-
.AddBranch("custom/foo")
97-
.Build();
93+
NextVersion = "1.0.0",
94+
Branches = new Dictionary<string, BranchConfig>
95+
{
96+
{
97+
"custom", new BranchConfig
98+
{
99+
Regex = "custom/",
100+
Tag = "alpha.{BranchName}"
101+
}
102+
}
103+
}
104+
};
98105

99-
var version = sut.FindVersion(context);
106+
using (var fixture = new EmptyRepositoryFixture())
107+
{
108+
fixture.MakeACommit();
109+
fixture.BranchTo("develop");
110+
fixture.MakeACommit();
111+
fixture.BranchTo("custom/foo");
112+
fixture.MakeACommit();
100113

101-
version.ToString("f").ShouldBe("1.0.0-alpha.foo.1+2");
114+
fixture.AssertFullSemver(config, "1.0.0-alpha.foo.1+2");
115+
}
102116
}
103117

104118
[Test]

0 commit comments

Comments
 (0)