Skip to content

Commit ecce434

Browse files
committed
moving to DI ConfigInit (2), added IConfigInitStepFactory
1 parent 07054ed commit ecce434

31 files changed

+138
-82
lines changed

src/GitVersionCore.Tests/ConfigProviderTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ public void Setup()
3232
{
3333
fileSystem = new TestFileSystem();
3434
var log = new NullLog();
35-
configInitWizard = new ConfigInitWizard(new ConsoleAdapter(), fileSystem, log);
35+
var stepFactory = new ConfigInitStepFactory();
36+
configInitWizard = new ConfigInitWizard(new ConsoleAdapter(), stepFactory);
3637
configFileLocator = new DefaultConfigFileLocator(fileSystem, log);
3738
repoPath = DefaultRepoPath;
3839

src/GitVersionCore.Tests/DefaultConfigFileLocatorTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ public void NoWarnOnGitVersionYmlFile()
9292
var log = new NullLog();
9393
var defaultConfigFileLocator = new DefaultConfigFileLocator(fileSystem, log);
9494
var gitPreparer = new GitPreparer(log, new Arguments { TargetPath = repoPath });
95-
var configInitWizard = new ConfigInitWizard(new ConsoleAdapter(), fileSystem, log);
95+
var stepFactory = new ConfigInitStepFactory();
96+
var configInitWizard = new ConfigInitWizard(new ConsoleAdapter(), stepFactory);
9697

9798
var configurationProvider = new ConfigurationProvider(fileSystem, log, defaultConfigFileLocator, gitPreparer, configInitWizard);
9899

src/GitVersionCore.Tests/DynamicRepositoryTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ public void FindsVersionInDynamicRepo(string name, string url, string targetBran
9595
var gitVersionFinder = new GitVersionFinder(log, nextVersionCalculator);
9696

9797
var gitPreparer = new GitPreparer(log, arguments);
98-
var configInitWizard = new ConfigInitWizard(new ConsoleAdapter(), testFileSystem, log);
98+
var stepFactory = new ConfigInitStepFactory();
99+
var configInitWizard = new ConfigInitWizard(new ConsoleAdapter(), stepFactory);
99100

100101
var configurationProvider = new ConfigurationProvider(testFileSystem, log, configFileLocator, gitPreparer, configInitWizard);
101102

src/GitVersionCore.Tests/GitVersionCore.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<PackageReference Include="FluentDateTime" Version="2.0.0" />
1515
<PackageReference Include="GitTools.Testing" Version="1.2.0" />
1616
<PackageReference Include="LibGit2Sharp.NativeBinaries" Version="$(PackageVersion_LibGit2Sharp_NativeBinaries)" />
17+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.0.0" />
1718
<PackageReference Include="YamlDotNet" Version="$(PackageVersion_YamlDotNet)" />
1819
</ItemGroup>
1920
<ItemGroup>

src/GitVersionCore.Tests/GitVersionExecutorTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,8 @@ private void RepositoryScope(ILog _log, Action<EmptyRepositoryFixture, VersionVa
525525
var options = Options.Create(arguments);
526526

527527
var gitPreparer = new GitPreparer(_log, arguments);
528-
var configInitWizard = new ConfigInitWizard(new ConsoleAdapter(), fileSystem, log);
528+
var stepFactory = new ConfigInitStepFactory();
529+
var configInitWizard = new ConfigInitWizard(new ConsoleAdapter(), stepFactory);
529530
var configurationProvider = new ConfigurationProvider(fileSystem, _log, configFileLocator, gitPreparer, configInitWizard);
530531
var baseVersionCalculator = new BaseVersionCalculator(log, null);
531532
var mainlineVersionCalculator = new MainlineVersionCalculator(log, metaDataCalculator);
@@ -547,7 +548,8 @@ private GitVersionCalculator GetGitVersionCalculator(Arguments arguments)
547548
var options = Options.Create(arguments);
548549

549550
var gitPreparer = new GitPreparer(log, arguments);
550-
var configInitWizard = new ConfigInitWizard(new ConsoleAdapter(), fileSystem, log);
551+
var stepFactory = new ConfigInitStepFactory();
552+
var configInitWizard = new ConfigInitWizard(new ConsoleAdapter(), stepFactory);
551553
var configurationProvider = new ConfigurationProvider(fileSystem, log, configFileLocator, gitPreparer, configInitWizard);
552554
var baseVersionCalculator = new BaseVersionCalculator(log, null);
553555
var mainlineVersionCalculator = new MainlineVersionCalculator(log, metaDataCalculator);

src/GitVersionCore.Tests/Init/InitScenarios.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
using System.Runtime.InteropServices;
33
using GitVersion;
44
using GitVersion.Configuration;
5+
using GitVersion.Configuration.Init;
56
using GitVersion.Configuration.Init.Wizard;
7+
using GitVersion.Extensions;
68
using GitVersion.Logging;
9+
using Microsoft.Extensions.DependencyInjection;
710
using NUnit.Framework;
811
using Shouldly;
912

@@ -23,10 +26,21 @@ public void Setup()
2326
[Description("Won't run on Mono due to source information not being available for ShouldMatchApproved.")]
2427
public void CanSetNextVersion()
2528
{
26-
var log = new NullLog();
27-
var fileSystem = new TestFileSystem();
28-
var testConsole = new TestConsole("3", "2.0.0", "0");
29-
var configInitWizard = new ConfigInitWizard(testConsole, fileSystem, log);
29+
ILog log = new NullLog();
30+
IFileSystem fileSystem = new TestFileSystem();
31+
IConsole testConsole = new TestConsole("3", "2.0.0", "0");
32+
33+
var serviceCollections = new ServiceCollection();
34+
serviceCollections.AddModule(new GitVersionInitModule());
35+
36+
serviceCollections.AddSingleton(log);
37+
serviceCollections.AddSingleton(fileSystem);
38+
serviceCollections.AddSingleton(testConsole);
39+
40+
var serviceProvider = serviceCollections.BuildServiceProvider();
41+
42+
var stepFactory = new ConfigInitStepFactory(serviceProvider);
43+
var configInitWizard = new ConfigInitWizard(testConsole, stepFactory);
3044
var configFileLocator = new DefaultConfigFileLocator(fileSystem, log);
3145
var workingDirectory = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "c:\\proj" : "/proj";
3246

src/GitVersionCore.Tests/NamedConfigFileLocatorTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class NamedConfigFileLocatorTests : TestBase
2020
private IFileSystem fileSystem;
2121
private NamedConfigFileLocator configFileLocator;
2222
private ILog log;
23+
private IConfigInitStepFactory stepFactory;
2324

2425
[SetUp]
2526
public void Setup()
@@ -29,6 +30,7 @@ public void Setup()
2930
configFileLocator = new NamedConfigFileLocator("my-config.yaml", fileSystem, log);
3031
repoPath = DefaultRepoPath;
3132
workingPath = DefaultWorkingPath;
33+
stepFactory = new ConfigInitStepFactory();
3234

3335
ShouldlyConfiguration.ShouldMatchApprovedDefaults.LocateTestMethodUsingAttribute<TestAttribute>();
3436
}
@@ -59,7 +61,7 @@ public void NoWarnOnCustomYmlFile()
5961
configFileLocator = new NamedConfigFileLocator("my-config.yaml", fileSystem, log);
6062

6163
var gitPreparer = new GitPreparer(log, new Arguments { TargetPath = repoPath });
62-
var configInitWizard = new ConfigInitWizard(new ConsoleAdapter(), fileSystem, log);
64+
var configInitWizard = new ConfigInitWizard(new ConsoleAdapter(), stepFactory);
6365
var configurationProvider = new ConfigurationProvider(fileSystem, log, configFileLocator, gitPreparer, configInitWizard);
6466

6567
configurationProvider.Provide(repoPath);
@@ -79,7 +81,7 @@ public void NoWarnOnCustomYmlFileOutsideRepoPath()
7981

8082
configFileLocator = new NamedConfigFileLocator("my-config.yaml", fileSystem, log);
8183
var gitPreparer = new GitPreparer(log, new Arguments { TargetPath = repoPath });
82-
var configInitWizard = new ConfigInitWizard(new ConsoleAdapter(), fileSystem, log);
84+
var configInitWizard = new ConfigInitWizard(new ConsoleAdapter(), stepFactory);
8385
var configurationProvider = new ConfigurationProvider(fileSystem, log, configFileLocator, gitPreparer, configInitWizard);
8486

8587
configurationProvider.Provide(repoPath);

src/GitVersionCore/Configuration/Init/BuildServer/AppVeyorSetup.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ internal class AppVeyorSetup : ConfigInitWizardStep
1717
{
1818
private ProjectVisibility _projectVisibility;
1919

20-
public AppVeyorSetup(IConsole console, IFileSystem fileSystem, ILog log) : base(console, fileSystem, log)
20+
public AppVeyorSetup(IConsole console, IFileSystem fileSystem, ILog log, IConfigInitStepFactory stepFactory) : base(console, fileSystem, log, stepFactory)
2121
{
2222
}
2323

@@ -29,18 +29,19 @@ public AppVeyorSetup WithData(ProjectVisibility visibility)
2929

3030
protected override StepResult HandleResult(string result, Queue<ConfigInitWizardStep> steps, Config config, string workingDirectory)
3131
{
32+
var editConfigStep = StepFactory.CreateStep<EditConfigStep>();
3233
switch (result)
3334
{
3435
case "0":
35-
steps.Enqueue(new EditConfigStep(Console, FileSystem, Log));
36+
steps.Enqueue(editConfigStep);
3637
return StepResult.Ok();
3738
case "1":
3839
GenerateBasicConfig(workingDirectory);
39-
steps.Enqueue(new EditConfigStep(Console, FileSystem, Log));
40+
steps.Enqueue(editConfigStep);
4041
return StepResult.Ok();
4142
case "2":
4243
GenerateNuGetConfig(workingDirectory);
43-
steps.Enqueue(new EditConfigStep(Console, FileSystem, Log));
44+
steps.Enqueue(editConfigStep);
4445
return StepResult.Ok();
4546
}
4647
return StepResult.InvalidResponseSelected();

src/GitVersionCore/Configuration/Init/BuildServer/AppveyorPublicPrivate.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace GitVersion.Configuration.Init.BuildServer
66
{
77
internal class AppveyorPublicPrivate : ConfigInitWizardStep
88
{
9-
public AppveyorPublicPrivate(IConsole console, IFileSystem fileSystem, ILog log) : base(console, fileSystem, log)
9+
public AppveyorPublicPrivate(IConsole console, IFileSystem fileSystem, ILog log, IConfigInitStepFactory stepFactory) : base(console, fileSystem, log, stepFactory)
1010
{
1111
}
1212

@@ -15,13 +15,13 @@ protected override StepResult HandleResult(string result, Queue<ConfigInitWizard
1515
switch (result)
1616
{
1717
case "0":
18-
steps.Enqueue(new EditConfigStep(Console, FileSystem, Log));
18+
steps.Enqueue(StepFactory.CreateStep<EditConfigStep>());
1919
return StepResult.Ok();
2020
case "1":
21-
steps.Enqueue(new AppVeyorSetup(Console, FileSystem, Log).WithData(ProjectVisibility.Public));
21+
steps.Enqueue(StepFactory.CreateStep<AppVeyorSetup>().WithData(ProjectVisibility.Public));
2222
return StepResult.Ok();
2323
case "2":
24-
steps.Enqueue(new AppVeyorSetup(Console, FileSystem, Log).WithData(ProjectVisibility.Private));
24+
steps.Enqueue(StepFactory.CreateStep<AppVeyorSetup>().WithData(ProjectVisibility.Private));
2525
return StepResult.Ok();
2626
}
2727
return StepResult.Ok();

src/GitVersionCore/Configuration/Init/BuildServer/SetupBuildScripts.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace GitVersion.Configuration.Init.BuildServer
66
{
77
internal class SetupBuildScripts : ConfigInitWizardStep
88
{
9-
public SetupBuildScripts(IConsole console, IFileSystem fileSystem, ILog log) : base(console, fileSystem, log)
9+
public SetupBuildScripts(IConsole console, IFileSystem fileSystem, ILog log, IConfigInitStepFactory stepFactory) : base(console, fileSystem, log, stepFactory)
1010
{
1111
}
1212

@@ -15,10 +15,10 @@ protected override StepResult HandleResult(string result, Queue<ConfigInitWizard
1515
switch (result)
1616
{
1717
case "0":
18-
steps.Enqueue(new EditConfigStep(Console, FileSystem, Log));
18+
steps.Enqueue(StepFactory.CreateStep<EditConfigStep>());
1919
return StepResult.Ok();
2020
case "1":
21-
steps.Enqueue(new AppveyorPublicPrivate(Console, FileSystem, Log));
21+
steps.Enqueue(StepFactory.CreateStep<AppveyorPublicPrivate>());
2222
return StepResult.Ok();
2323
}
2424
return StepResult.Ok();

0 commit comments

Comments
 (0)