Skip to content

Commit 23566f6

Browse files
committed
moving to DI ConfigurationProvider, GitPreparer
1 parent a077247 commit 23566f6

13 files changed

+372
-259
lines changed

src/GitVersionCore.Tests/ConfigProviderTests.cs

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class ConfigProviderTests : TestBase
2323
private string repoPath;
2424
private IFileSystem fileSystem;
2525
private IConfigFileLocator configFileLocator;
26+
private IConfigurationProvider configurationProvider;
2627

2728
[SetUp]
2829
public void Setup()
@@ -32,6 +33,9 @@ public void Setup()
3233
configFileLocator = new DefaultConfigFileLocator(fileSystem, log);
3334
repoPath = DefaultRepoPath;
3435

36+
var gitPreparer = new GitPreparer(log, new Arguments { TargetPath = repoPath });
37+
configurationProvider = new ConfigurationProvider(fileSystem, log, configFileLocator, gitPreparer);
38+
3539
ShouldlyConfiguration.ShouldMatchApprovedDefaults.LocateTestMethodUsingAttribute<TestAttribute>();
3640
}
3741

@@ -53,7 +57,7 @@ public void CanReadOldDocument()
5357
tag: rc
5458
";
5559
SetupConfigFileContent(text);
56-
var error = Should.Throw<OldConfigurationException>(() => ConfigurationProvider.Provide(repoPath, configFileLocator));
60+
var error = Should.Throw<OldConfigurationException>(() => configurationProvider.Provide(repoPath));
5761
error.Message.ShouldContainWithoutWhitespace(@"GitVersion configuration file contains old configuration, please fix the following errors:
5862
GitVersion branch configs no longer are keyed by regexes, update:
5963
dev(elop)?(ment)?$ -> develop
@@ -66,15 +70,15 @@ assemblyVersioningScheme has been replaced by assembly-versioning-scheme
6670
[Test]
6771
public void OverwritesDefaultsWithProvidedConfig()
6872
{
69-
var defaultConfig = ConfigurationProvider.Provide(repoPath, configFileLocator);
73+
var defaultConfig = configurationProvider.Provide(repoPath);
7074
const string text = @"
7175
next-version: 2.0.0
7276
branches:
7377
develop:
7478
mode: ContinuousDeployment
7579
tag: dev";
7680
SetupConfigFileContent(text);
77-
var config = ConfigurationProvider.Provide(repoPath, configFileLocator);
81+
var config = configurationProvider.Provide(repoPath);
7882

7983
config.NextVersion.ShouldBe("2.0.0");
8084
config.Branches["develop"].Increment.ShouldBe(defaultConfig.Branches["develop"].Increment);
@@ -87,7 +91,7 @@ public void AllBranchesModeWhenUsingMainline()
8791
{
8892
const string text = @"mode: Mainline";
8993
SetupConfigFileContent(text);
90-
var config = ConfigurationProvider.Provide(repoPath, configFileLocator);
94+
var config = configurationProvider.Provide(repoPath);
9195
var branches = config.Branches.Select(x => x.Value);
9296
branches.All(branch => branch.VersioningMode == VersioningMode.Mainline).ShouldBe(true);
9397
}
@@ -101,7 +105,7 @@ public void CanRemoveTag()
101105
release:
102106
tag: """"";
103107
SetupConfigFileContent(text);
104-
var config = ConfigurationProvider.Provide(repoPath, configFileLocator);
108+
var config = configurationProvider.Provide(repoPath);
105109

106110
config.NextVersion.ShouldBe("2.0.0");
107111
config.Branches["release"].Tag.ShouldBe(string.Empty);
@@ -116,7 +120,7 @@ public void RegexIsRequired()
116120
bug:
117121
tag: bugfix";
118122
SetupConfigFileContent(text);
119-
var ex = Should.Throw<GitVersionConfigurationException>(() => ConfigurationProvider.Provide(repoPath, configFileLocator));
123+
var ex = Should.Throw<GitVersionConfigurationException>(() => configurationProvider.Provide(repoPath));
120124
ex.Message.ShouldBe("Branch configuration 'bug' is missing required configuration 'regex'\n\n" +
121125
"See http://gitversion.readthedocs.io/en/latest/configuration/ for more info");
122126
}
@@ -131,7 +135,7 @@ public void SourceBranchIsRequired()
131135
regex: 'bug[/-]'
132136
tag: bugfix";
133137
SetupConfigFileContent(text);
134-
var ex = Should.Throw<GitVersionConfigurationException>(() => ConfigurationProvider.Provide(repoPath, configFileLocator));
138+
var ex = Should.Throw<GitVersionConfigurationException>(() => configurationProvider.Provide(repoPath));
135139
ex.Message.ShouldBe("Branch configuration 'bug' is missing required configuration 'source-branches'\n\n" +
136140
"See http://gitversion.readthedocs.io/en/latest/configuration/ for more info");
137141
}
@@ -147,7 +151,7 @@ public void CanProvideConfigForNewBranch()
147151
tag: bugfix
148152
source-branches: []";
149153
SetupConfigFileContent(text);
150-
var config = ConfigurationProvider.Provide(repoPath, configFileLocator);
154+
var config = configurationProvider.Provide(repoPath);
151155

152156
config.Branches["bug"].Regex.ShouldBe("bug[/-]");
153157
config.Branches["bug"].Tag.ShouldBe("bugfix");
@@ -158,7 +162,7 @@ public void NextVersionCanBeInteger()
158162
{
159163
const string text = "next-version: 2";
160164
SetupConfigFileContent(text);
161-
var config = ConfigurationProvider.Provide(repoPath, configFileLocator);
165+
var config = configurationProvider.Provide(repoPath);
162166

163167
config.NextVersion.ShouldBe("2.0");
164168
}
@@ -168,7 +172,7 @@ public void NextVersionCanHaveEnormousMinorVersion()
168172
{
169173
const string text = "next-version: 2.118998723";
170174
SetupConfigFileContent(text);
171-
var config = ConfigurationProvider.Provide(repoPath, configFileLocator);
175+
var config = configurationProvider.Provide(repoPath);
172176

173177
config.NextVersion.ShouldBe("2.118998723");
174178
}
@@ -178,7 +182,7 @@ public void NextVersionCanHavePatch()
178182
{
179183
const string text = "next-version: 2.12.654651698";
180184
SetupConfigFileContent(text);
181-
var config = ConfigurationProvider.Provide(repoPath, configFileLocator);
185+
var config = configurationProvider.Provide(repoPath);
182186

183187
config.NextVersion.ShouldBe("2.12.654651698");
184188
}
@@ -189,7 +193,7 @@ public void NextVersionCanHavePatch()
189193
[Description("Won't run on Mono due to source information not being available for ShouldMatchApproved.")]
190194
public void CanWriteOutEffectiveConfiguration()
191195
{
192-
var config = ConfigurationProvider.GetEffectiveConfigAsString(repoPath, configFileLocator);
196+
var config = configurationProvider.GetEffectiveConfigAsString(repoPath);
193197

194198
config.ShouldMatchApproved();
195199
}
@@ -204,7 +208,7 @@ public void CanUpdateAssemblyInformationalVersioningScheme()
204208

205209
SetupConfigFileContent(text);
206210

207-
var config = ConfigurationProvider.Provide(repoPath, configFileLocator);
211+
var config = configurationProvider.Provide(repoPath);
208212
config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinor);
209213
config.AssemblyFileVersioningScheme.ShouldBe(AssemblyFileVersioningScheme.MajorMinorPatch);
210214
config.AssemblyInformationalFormat.ShouldBe("{NugetVersion}");
@@ -220,7 +224,7 @@ public void CanUpdateAssemblyInformationalVersioningSchemeWithMultipleVariables(
220224

221225
SetupConfigFileContent(text);
222226

223-
var config = ConfigurationProvider.Provide(repoPath, configFileLocator);
227+
var config = configurationProvider.Provide(repoPath);
224228
config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinor);
225229
config.AssemblyFileVersioningScheme.ShouldBe(AssemblyFileVersioningScheme.MajorMinorPatch);
226230
config.AssemblyInformationalFormat.ShouldBe("{Major}.{Minor}.{Patch}");
@@ -239,7 +243,7 @@ public void CanUpdateAssemblyInformationalVersioningSchemeWithFullSemVer()
239243

240244
SetupConfigFileContent(text);
241245

242-
var config = ConfigurationProvider.Provide(repoPath, configFileLocator);
246+
var config = configurationProvider.Provide(repoPath);
243247
config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinorPatch);
244248
config.AssemblyFileVersioningScheme.ShouldBe(AssemblyFileVersioningScheme.MajorMinorPatch);
245249
config.AssemblyInformationalFormat.ShouldBe("{FullSemVer}");
@@ -250,7 +254,7 @@ public void CanReadDefaultDocument()
250254
{
251255
const string text = "";
252256
SetupConfigFileContent(text);
253-
var config = ConfigurationProvider.Provide(repoPath, configFileLocator);
257+
var config = configurationProvider.Provide(repoPath);
254258
config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinorPatch);
255259
config.AssemblyFileVersioningScheme.ShouldBe(AssemblyFileVersioningScheme.MajorMinorPatch);
256260
config.AssemblyInformationalFormat.ShouldBe(null);
@@ -284,8 +288,11 @@ public void NoWarnOnGitVersionYmlFile()
284288
var log = new Log(logAppender);
285289

286290
var defaultConfigFileLocator = new DefaultConfigFileLocator(fileSystem, log);
291+
var gitPreparer = new GitPreparer(log, new Arguments { TargetPath = repoPath });
292+
293+
configurationProvider = new ConfigurationProvider(fileSystem, log, defaultConfigFileLocator, gitPreparer);
287294

288-
ConfigurationProvider.Provide(repoPath, defaultConfigFileLocator);
295+
configurationProvider.Provide(repoPath);
289296

290297
stringLogger.Length.ShouldBe(0);
291298
}
@@ -314,7 +321,7 @@ public void ShouldUseSpecifiedSourceBranchesForDevelop()
314321
source-branches: ['develop']
315322
tag: dev";
316323
SetupConfigFileContent(text);
317-
var config = ConfigurationProvider.Provide(repoPath, configFileLocator);
324+
var config = configurationProvider.Provide(repoPath);
318325

319326
config.Branches["develop"].SourceBranches.ShouldBe(new List<string> { "develop" });
320327
}
@@ -329,7 +336,7 @@ public void ShouldUseDefaultSourceBranchesWhenNotSpecifiedForDevelop()
329336
mode: ContinuousDeployment
330337
tag: dev";
331338
SetupConfigFileContent(text);
332-
var config = ConfigurationProvider.Provide(repoPath, configFileLocator);
339+
var config = configurationProvider.Provide(repoPath);
333340

334341
config.Branches["develop"].SourceBranches.ShouldBe(new List<string>());
335342
}
@@ -345,7 +352,7 @@ public void ShouldUseSpecifiedSourceBranchesForFeature()
345352
source-branches: ['develop', 'release']
346353
tag: dev";
347354
SetupConfigFileContent(text);
348-
var config = ConfigurationProvider.Provide(repoPath, configFileLocator);
355+
var config = configurationProvider.Provide(repoPath);
349356

350357
config.Branches["feature"].SourceBranches.ShouldBe(new List<string> { "develop", "release" });
351358
}
@@ -360,7 +367,7 @@ public void ShouldUseDefaultSourceBranchesWhenNotSpecifiedForFeature()
360367
mode: ContinuousDeployment
361368
tag: dev";
362369
SetupConfigFileContent(text);
363-
var config = ConfigurationProvider.Provide(repoPath, configFileLocator);
370+
var config = configurationProvider.Provide(repoPath);
364371

365372
config.Branches["feature"].SourceBranches.ShouldBe(
366373
new List<string> { "develop", "master", "release", "feature", "support", "hotfix" });

src/GitVersionCore.Tests/DefaultConfigFileLocatorTests.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,12 @@ public void NoWarnOnGitVersionYmlFile()
8888

8989
var output = WithDefaultConfigFileLocator(configFileLocator =>
9090
{
91-
ConfigurationProvider.Provide(repoPath, configFileLocator);
91+
var log = new NullLog();
92+
var defaultConfigFileLocator = new DefaultConfigFileLocator(fileSystem, log);
93+
var gitPreparer = new GitPreparer(log, new Arguments { TargetPath = repoPath });
94+
var configurationProvider = new ConfigurationProvider(fileSystem, log, defaultConfigFileLocator, gitPreparer);
95+
96+
configurationProvider.Provide(repoPath);
9297
});
9398

9499
output.Length.ShouldBe(0);

src/GitVersionCore.Tests/DynamicRepositoryTests.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,13 @@ public void FindsVersionInDynamicRepo(string name, string url, string targetBran
8585

8686
var metaDataCalculator = new MetaDataCalculator();
8787
var gitVersionFinder = new GitVersionFinder(log, metaDataCalculator);
88-
var executeCore = new GitVersionCalculator(testFileSystem, log, configFileLocator, buildServerResolver, gitVersionCache, gitVersionFinder, metaDataCalculator);
8988

90-
var versionVariables = executeCore.CalculateVersionVariables(arguments);
89+
var gitPreparer = new GitPreparer(log, arguments);
90+
var configurationProvider = new ConfigurationProvider(testFileSystem, log, configFileLocator, gitPreparer);
91+
92+
var gitVersionCalculator = new GitVersionCalculator(testFileSystem, log, configFileLocator, configurationProvider, buildServerResolver, gitVersionCache, gitVersionFinder, metaDataCalculator, gitPreparer);
93+
94+
var versionVariables = gitVersionCalculator.CalculateVersionVariables(arguments);
9195

9296
Assert.AreEqual(expectedFullSemVer, versionVariables.FullSemVer);
9397
}

0 commit comments

Comments
 (0)