Skip to content

Commit e88a625

Browse files
committed
cleanup
1 parent 6be0cba commit e88a625

File tree

7 files changed

+70
-45
lines changed

7 files changed

+70
-45
lines changed

src/GitVersion.Configuration.Tests/Configuration/ConfigurationFileLocatorTests.cs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,20 @@ public void Setup()
4141
[TestCase(ConfigurationFileLocator.DefaultAlternativeFileName, ConfigurationFileLocator.DefaultAlternativeFileName)]
4242
public void ThrowsExceptionOnAmbiguousConfigFileLocation(string repoConfigFile, string workingConfigFile)
4343
{
44-
var repositoryConfigFilePath = fileSystem.SetupConfigFile(string.Empty, this.repoPath, repoConfigFile);
45-
var workingDirectoryConfigFilePath = fileSystem.SetupConfigFile(string.Empty, this.workingPath, workingConfigFile);
44+
using var repositoryConfigFilePath = this.fileSystem.SetupConfigFile(path: this.repoPath, fileName: repoConfigFile);
45+
using var workingDirectoryConfigFilePath = this.fileSystem.SetupConfigFile(path: this.workingPath, fileName: workingConfigFile);
4646

4747
var exception = Should.Throw<WarningException>(() => this.configFileLocator.Verify(this.workingPath, this.repoPath));
4848

49-
var expectedMessage = $"Ambiguous configuration file selection from '{workingDirectoryConfigFilePath}' and '{repositoryConfigFilePath}'";
49+
var expectedMessage = $"Ambiguous configuration file selection from '{workingDirectoryConfigFilePath.Value}' and '{repositoryConfigFilePath.Value}'";
5050
exception.Message.ShouldBe(expectedMessage);
5151
}
5252

5353
[TestCase(ConfigurationFileLocator.DefaultFileName)]
5454
[TestCase(ConfigurationFileLocator.DefaultAlternativeFileName)]
5555
public void NoWarnOnGitVersionYmlFile(string configurationFile)
5656
{
57-
fileSystem.SetupConfigFile(string.Empty, this.repoPath, configurationFile);
57+
using var _ = this.fileSystem.SetupConfigFile(path: this.repoPath, fileName: configurationFile);
5858

5959
Should.NotThrow(() => this.configurationProvider.ProvideForDirectory(this.repoPath));
6060
}
@@ -70,6 +70,7 @@ public class NamedConfigurationFileLocatorTests : TestBase
7070
private IFileSystem fileSystem;
7171
private IConfigurationFileLocator configFileLocator;
7272
private GitVersionOptions gitVersionOptions;
73+
private string ConfigFile => this.gitVersionOptions.ConfigurationInfo.ConfigurationFile!;
7374

7475
[SetUp]
7576
public void Setup()
@@ -88,12 +89,12 @@ public void ThrowsExceptionOnAmbiguousConfigFileLocation()
8889
this.configFileLocator = sp.GetRequiredService<IConfigurationFileLocator>();
8990
this.fileSystem = sp.GetRequiredService<IFileSystem>();
9091

91-
var repositoryConfigFilePath = SetupConfigFile(string.Empty, path: this.repoPath);
92-
var workDirConfigFilePath = SetupConfigFile(string.Empty, path: this.workingPath);
92+
using var repositoryConfigFilePath = this.fileSystem.SetupConfigFile(path: this.repoPath, fileName: ConfigFile);
93+
using var workDirConfigFilePath = this.fileSystem.SetupConfigFile(path: this.workingPath, fileName: ConfigFile);
9394

9495
var exception = Should.Throw<WarningException>(() => this.configFileLocator.Verify(this.workingPath, this.repoPath));
9596

96-
var expectedMessage = $"Ambiguous configuration file selection from '{workDirConfigFilePath}' and '{repositoryConfigFilePath}'";
97+
var expectedMessage = $"Ambiguous configuration file selection from '{workDirConfigFilePath.Value}' and '{repositoryConfigFilePath.Value}'";
9798
exception.Message.ShouldBe(expectedMessage);
9899
}
99100

@@ -106,7 +107,7 @@ public void DoNotThrowWhenWorkingAndRepoPathsAreSame()
106107
this.configFileLocator = sp.GetRequiredService<IConfigurationFileLocator>();
107108
this.fileSystem = sp.GetRequiredService<IFileSystem>();
108109

109-
SetupConfigFile(string.Empty, path: this.workingPath);
110+
using var _ = this.fileSystem.SetupConfigFile(path: this.workingPath, fileName: ConfigFile);
110111

111112
Should.NotThrow(() => this.configFileLocator.Verify(this.workingPath, this.repoPath));
112113
}
@@ -120,7 +121,7 @@ public void DoNotThrowWhenWorkingAndRepoPathsAreSame_WithDifferentCasing()
120121
this.configFileLocator = sp.GetRequiredService<IConfigurationFileLocator>();
121122
this.fileSystem = sp.GetRequiredService<IFileSystem>();
122123

123-
SetupConfigFile(string.Empty, path: this.workingPath);
124+
using var _ = this.fileSystem.SetupConfigFile(path: this.workingPath, fileName: ConfigFile);
124125

125126
Should.NotThrow(() => this.configFileLocator.Verify(this.workingPath, this.repoPath));
126127
}
@@ -135,7 +136,7 @@ public void DoNotThrowWhenConfigFileIsInSubDirectoryOfRepoPath()
135136
this.configFileLocator = sp.GetRequiredService<IConfigurationFileLocator>();
136137
this.fileSystem = sp.GetRequiredService<IFileSystem>();
137138

138-
SetupConfigFile(string.Empty, path: this.workingPath);
139+
using var _ = this.fileSystem.SetupConfigFile(path: this.workingPath, fileName: ConfigFile);
139140

140141
Should.NotThrow(() => this.configFileLocator.Verify(this.workingPath, this.repoPath));
141142
}
@@ -153,7 +154,7 @@ public void NoWarnOnCustomYmlFile()
153154
this.configFileLocator = sp.GetRequiredService<IConfigurationFileLocator>();
154155
this.fileSystem = sp.GetRequiredService<IFileSystem>();
155156

156-
SetupConfigFile(string.Empty);
157+
using var _ = this.fileSystem.SetupConfigFile(path: null, fileName: ConfigFile);
157158

158159
var configurationProvider = (ConfigurationProvider)sp.GetRequiredService<IConfigurationProvider>();
159160

@@ -174,7 +175,8 @@ public void NoWarnOnCustomYmlFileOutsideRepoPath()
174175
this.configFileLocator = sp.GetRequiredService<IConfigurationFileLocator>();
175176
this.fileSystem = sp.GetRequiredService<IFileSystem>();
176177

177-
SetupConfigFile(string.Empty, path: PathHelper.Combine(PathHelper.GetTempPath(), "unrelatedPath"));
178+
string path = PathHelper.Combine(PathHelper.GetTempPath(), "unrelatedPath");
179+
using var _ = this.fileSystem.SetupConfigFile(path: path, fileName: ConfigFile);
178180

179181
var configurationProvider = (ConfigurationProvider)sp.GetRequiredService<IConfigurationProvider>();
180182

@@ -197,9 +199,6 @@ public void ThrowsExceptionOnCustomYmlFileDoesNotExist()
197199
exception.Message.ShouldBe(expectedMessage);
198200
}
199201

200-
private string SetupConfigFile(string text, string? path = null)
201-
=> this.fileSystem.SetupConfigFile(text, path, this.gitVersionOptions.ConfigurationInfo.ConfigurationFile!);
202-
203202
private static IServiceProvider GetServiceProvider(GitVersionOptions gitVersionOptions, ILog? log = null) =>
204203
ConfigureServices(services =>
205204
{

src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.cs

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void OverwritesDefaultsWithProvidedConfig()
4141
increment: Major
4242
mode: ContinuousDelivery
4343
label: dev";
44-
fileSystem.SetupConfigFile(text, this.repoPath);
44+
using var _ = this.fileSystem.SetupConfigFile(path: this.repoPath, text: text);
4545
var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath);
4646

4747
configuration.NextVersion.ShouldBe("2.0.0");
@@ -59,7 +59,8 @@ public void OverwritesDefaultsWithProvidedConfig()
5959
public void CombineVersionStrategyConfigNextAndTaggedCommit()
6060
{
6161
// Arrange
62-
fileSystem.SetupConfigFile("strategies: [ConfiguredNextVersion, TaggedCommit]", this.repoPath);
62+
const string text = "strategies: [ConfiguredNextVersion, TaggedCommit]";
63+
using var _ = this.fileSystem.SetupConfigFile(path: this.repoPath, text: text);
6364

6465
// Act
6566
var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath);
@@ -76,7 +77,7 @@ public void CanRemoveLabel()
7677
branches:
7778
release:
7879
label: """"";
79-
fileSystem.SetupConfigFile(text, this.repoPath);
80+
using var _ = this.fileSystem.SetupConfigFile(path: this.repoPath, text: text);
8081
var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath);
8182

8283
configuration.NextVersion.ShouldBe("2.0.0");
@@ -91,7 +92,7 @@ public void RegexIsRequired()
9192
branches:
9293
bug:
9394
label: bugfix";
94-
fileSystem.SetupConfigFile(text, this.repoPath);
95+
using var _ = this.fileSystem.SetupConfigFile(path: this.repoPath, text: text);
9596
var ex = Should.Throw<ConfigurationException>(() => this.configurationProvider.ProvideForDirectory(this.repoPath));
9697
ex.Message.ShouldBe($"Branch configuration 'bug' is missing required configuration 'regex'{PathHelper.NewLine}" +
9798
"See https://gitversion.net/docs/reference/configuration for more info");
@@ -106,7 +107,7 @@ public void SourceBranchesValidationShouldFailWhenMatchingBranchConfigurationIsM
106107
regex: 'bug[/-]'
107108
label: bugfix
108109
source-branches: [notconfigured]";
109-
fileSystem.SetupConfigFile(text, this.repoPath);
110+
using var _ = this.fileSystem.SetupConfigFile(path: this.repoPath, text: text);
110111
var ex = Should.Throw<ConfigurationException>(() => this.configurationProvider.ProvideForDirectory(this.repoPath));
111112
ex.Message.ShouldBe($"Branch configuration 'bug' defines these 'source-branches' that are not configured: '[notconfigured]'{PathHelper.NewLine}" +
112113
"See https://gitversion.net/docs/reference/configuration for more info");
@@ -123,7 +124,7 @@ public void SourceBranchesValidationShouldSucceedForWellKnownBranches(string wel
123124
regex: 'bug[/-]'
124125
label: bugfix
125126
source-branches: [{wellKnownBranchKey}]";
126-
fileSystem.SetupConfigFile(text, this.repoPath);
127+
using var _ = this.fileSystem.SetupConfigFile(path: this.repoPath, text: text);
127128
var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath);
128129

129130
configuration.Branches["bug"].SourceBranches.ShouldBe(new List<string> { wellKnownBranchKey });
@@ -139,7 +140,7 @@ public void CanProvideConfigForNewBranch()
139140
regex: 'bug[/-]'
140141
label: bugfix
141142
source-branches: []";
142-
fileSystem.SetupConfigFile(text, this.repoPath);
143+
using var _ = this.fileSystem.SetupConfigFile(path: this.repoPath, text: text);
143144
var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath);
144145

145146
configuration.Branches["bug"].RegularExpression.ShouldBe("bug[/-]");
@@ -150,7 +151,7 @@ public void CanProvideConfigForNewBranch()
150151
public void NextVersionCanBeInteger()
151152
{
152153
const string text = "next-version: 2";
153-
fileSystem.SetupConfigFile(text, this.repoPath);
154+
using var _ = this.fileSystem.SetupConfigFile(path: this.repoPath, text: text);
154155
var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath);
155156

156157
configuration.NextVersion.ShouldBe("2.0");
@@ -160,7 +161,7 @@ public void NextVersionCanBeInteger()
160161
public void NextVersionCanHaveEnormousMinorVersion()
161162
{
162163
const string text = "next-version: 2.118998723";
163-
fileSystem.SetupConfigFile(text, this.repoPath);
164+
using var _ = this.fileSystem.SetupConfigFile(path: this.repoPath, text: text);
164165
var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath);
165166

166167
configuration.NextVersion.ShouldBe("2.118998723");
@@ -170,7 +171,7 @@ public void NextVersionCanHaveEnormousMinorVersion()
170171
public void NextVersionCanHavePatch()
171172
{
172173
const string text = "next-version: 2.12.654651698";
173-
fileSystem.SetupConfigFile(text, this.repoPath);
174+
using var _ = this.fileSystem.SetupConfigFile(path: this.repoPath, text: text);
174175
var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath);
175176

176177
configuration.NextVersion.ShouldBe("2.12.654651698");
@@ -193,7 +194,7 @@ public void CanUpdateAssemblyInformationalVersioningScheme()
193194
assembly-file-versioning-scheme: MajorMinorPatch
194195
assembly-informational-format: '{NugetVersion}'";
195196

196-
fileSystem.SetupConfigFile(text, this.repoPath);
197+
using var _ = this.fileSystem.SetupConfigFile(path: this.repoPath, text: text);
197198

198199
var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath);
199200
configuration.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinor);
@@ -209,7 +210,7 @@ public void CanUpdateAssemblyInformationalVersioningSchemeWithMultipleVariables(
209210
assembly-file-versioning-scheme: MajorMinorPatch
210211
assembly-informational-format: '{Major}.{Minor}.{Patch}'";
211212

212-
fileSystem.SetupConfigFile(text, this.repoPath);
213+
using var _ = this.fileSystem.SetupConfigFile(path: this.repoPath, text: text);
213214

214215
var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath);
215216
configuration.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinor);
@@ -227,7 +228,7 @@ public void CanUpdateAssemblyInformationalVersioningSchemeWithFullSemVer()
227228
next-version: 5.3.0
228229
branches: {}";
229230

230-
fileSystem.SetupConfigFile(text, this.repoPath);
231+
using var _ = this.fileSystem.SetupConfigFile(path: this.repoPath, text: text);
231232

232233
var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath);
233234
configuration.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinorPatch);
@@ -239,7 +240,7 @@ public void CanUpdateAssemblyInformationalVersioningSchemeWithFullSemVer()
239240
public void CanReadDefaultDocument()
240241
{
241242
const string text = "";
242-
fileSystem.SetupConfigFile(text, this.repoPath);
243+
using var _ = this.fileSystem.SetupConfigFile(path: this.repoPath, text: text);
243244
var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath);
244245
configuration.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinorPatch);
245246
configuration.AssemblyFileVersioningScheme.ShouldBe(AssemblyFileVersioningScheme.MajorMinorPatch);
@@ -266,7 +267,8 @@ public void VerifyAliases()
266267
[Test]
267268
public void NoWarnOnGitVersionYmlFile()
268269
{
269-
fileSystem.SetupConfigFile(string.Empty, this.repoPath);
270+
const string text = "";
271+
using var _ = this.fileSystem.SetupConfigFile(path: this.repoPath, text: text);
270272

271273
var stringLogger = string.Empty;
272274
void Action(string info) => stringLogger = info;
@@ -297,7 +299,7 @@ public void ShouldUseSpecifiedSourceBranchesForDevelop()
297299
mode: ContinuousDeployment
298300
source-branches: ['develop']
299301
label: dev";
300-
fileSystem.SetupConfigFile(text, this.repoPath);
302+
using var _ = this.fileSystem.SetupConfigFile(path: this.repoPath, text: text);
301303
var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath);
302304

303305
configuration.Branches["develop"].SourceBranches.ShouldBe(new List<string> { "develop" });
@@ -312,7 +314,7 @@ public void ShouldUseDefaultSourceBranchesWhenNotSpecifiedForDevelop()
312314
develop:
313315
mode: ContinuousDeployment
314316
label: dev";
315-
fileSystem.SetupConfigFile(text, this.repoPath);
317+
using var _ = this.fileSystem.SetupConfigFile(path: this.repoPath, text: text);
316318
var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath);
317319

318320
configuration.Branches["develop"].SourceBranches.ShouldBe(new List<string>());
@@ -328,7 +330,7 @@ public void ShouldUseSpecifiedSourceBranchesForFeature()
328330
mode: ContinuousDeployment
329331
source-branches: ['develop', 'release']
330332
label: dev";
331-
fileSystem.SetupConfigFile(text, this.repoPath);
333+
using var _ = this.fileSystem.SetupConfigFile(path: this.repoPath, text: text);
332334
var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath);
333335

334336
configuration.Branches["feature"].SourceBranches.ShouldBe(new List<string> { "develop", "release" });
@@ -343,7 +345,7 @@ public void ShouldUseDefaultSourceBranchesWhenNotSpecifiedForFeature()
343345
feature:
344346
mode: ContinuousDeployment
345347
label: dev";
346-
fileSystem.SetupConfigFile(text, this.repoPath);
348+
using var _ = this.fileSystem.SetupConfigFile(path: this.repoPath, text: text);
347349
var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath);
348350

349351
configuration.Branches["feature"].SourceBranches.ShouldBe(
@@ -356,7 +358,7 @@ public void ShouldNotOverrideAnythingWhenOverrideConfigIsEmpty()
356358
const string text = @"
357359
next-version: 1.2.3
358360
tag-prefix: custom-tag-prefix-from-yml";
359-
fileSystem.SetupConfigFile(text, this.repoPath);
361+
using var _ = this.fileSystem.SetupConfigFile(path: this.repoPath, text: text);
360362

361363
var expectedConfig = GitFlowConfigurationBuilder.New
362364
.WithNextVersion("1.2.3")
@@ -394,7 +396,7 @@ public void ShouldNotOverrideAnythingWhenOverrideConfigIsEmpty()
394396
public void ShouldUseDefaultTagPrefixWhenNotSetInConfigFile()
395397
{
396398
const string text = "";
397-
fileSystem.SetupConfigFile(text, this.repoPath);
399+
using var _ = this.fileSystem.SetupConfigFile(path: this.repoPath, text: text);
398400
var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath);
399401

400402
configuration.TagPrefix.ShouldBe(ConfigurationConstants.DefaultTagPrefix);
@@ -404,7 +406,7 @@ public void ShouldUseDefaultTagPrefixWhenNotSetInConfigFile()
404406
public void ShouldUseTagPrefixFromConfigFileWhenProvided()
405407
{
406408
const string text = "tag-prefix: custom-tag-prefix-from-yml";
407-
fileSystem.SetupConfigFile(text, this.repoPath);
409+
using var _ = this.fileSystem.SetupConfigFile(path: this.repoPath, text: text);
408410
var configuration = this.configurationProvider.ProvideForDirectory(this.repoPath);
409411

410412
configuration.TagPrefix.ShouldBe("custom-tag-prefix-from-yml");
@@ -414,7 +416,7 @@ public void ShouldUseTagPrefixFromConfigFileWhenProvided()
414416
public void ShouldOverrideTagPrefixWithOverrideConfigValue([Values] bool tagPrefixSetAtYmlFile)
415417
{
416418
var text = tagPrefixSetAtYmlFile ? "tag-prefix: custom-tag-prefix-from-yml" : "";
417-
fileSystem.SetupConfigFile(text, this.repoPath);
419+
using var _ = this.fileSystem.SetupConfigFile(path: this.repoPath, text: text);
418420
var overrideConfiguration = new Dictionary<object, object?>
419421
{
420422
{ "tag-prefix", "tag-prefix-from-override-configuration" }
@@ -428,7 +430,7 @@ public void ShouldOverrideTagPrefixWithOverrideConfigValue([Values] bool tagPref
428430
public void ShouldNotOverrideDefaultTagPrefixWhenNotSetInOverrideConfig()
429431
{
430432
const string text = "";
431-
fileSystem.SetupConfigFile(text, this.repoPath);
433+
using var _ = this.fileSystem.SetupConfigFile(path: this.repoPath, text: text);
432434
var overrideConfiguration = new Dictionary<object, object?>
433435
{
434436
{ "next-version", "1.0.0" }
@@ -443,7 +445,7 @@ public void ShouldNotOverrideDefaultTagPrefixWhenNotSetInOverrideConfig()
443445
public void ShouldNotOverrideTagPrefixFromConfigFileWhenNotSetInOverrideConfig()
444446
{
445447
const string text = "tag-prefix: custom-tag-prefix-from-yml";
446-
fileSystem.SetupConfigFile(text, this.repoPath);
448+
using var _ = this.fileSystem.SetupConfigFile(path: this.repoPath, text: text);
447449
var overrideConfiguration = new Dictionary<object, object?>
448450
{
449451
{ "next-version", "1.0.0" }
@@ -457,7 +459,7 @@ public void ShouldNotOverrideTagPrefixFromConfigFileWhenNotSetInOverrideConfig()
457459
public void ShouldOverrideTagPrefixFromConfigFileWhenSetInOverrideConfig()
458460
{
459461
const string text = "tag-prefix: custom-tag-prefix-from-yml";
460-
fileSystem.SetupConfigFile(text, this.repoPath);
462+
using var _ = this.fileSystem.SetupConfigFile(path: this.repoPath, text: text);
461463
var overrideConfiguration = new Dictionary<object, object?>
462464
{
463465
{ "tag-prefix", "custom-tag-prefix-from-console" }

0 commit comments

Comments
 (0)