Skip to content

Commit be56c48

Browse files
committed
Enabled init steps to be tested
1 parent bcca05f commit be56c48

29 files changed

+361
-102
lines changed

src/GitVersionCore.Tests/GitVersionCore.Tests.csproj

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,22 @@
5353
<SpecificVersion>False</SpecificVersion>
5454
<HintPath>..\packages\LibGit2Sharp.0.20.1.0\lib\net40\LibGit2Sharp.dll</HintPath>
5555
</Reference>
56+
<Reference Include="Mono.Cecil, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
57+
<HintPath>..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.dll</HintPath>
58+
<Private>True</Private>
59+
</Reference>
60+
<Reference Include="Mono.Cecil.Mdb, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
61+
<HintPath>..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Mdb.dll</HintPath>
62+
<Private>True</Private>
63+
</Reference>
64+
<Reference Include="Mono.Cecil.Pdb, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
65+
<HintPath>..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Pdb.dll</HintPath>
66+
<Private>True</Private>
67+
</Reference>
68+
<Reference Include="Mono.Cecil.Rocks, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
69+
<HintPath>..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Rocks.dll</HintPath>
70+
<Private>True</Private>
71+
</Reference>
5672
<Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
5773
<SpecificVersion>False</SpecificVersion>
5874
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
@@ -68,6 +84,10 @@
6884
<Reference Include="System.Data.DataSetExtensions" />
6985
<Reference Include="System.Data" />
7086
<Reference Include="System.Xml" />
87+
<Reference Include="TestStack.ConventionTests, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
88+
<HintPath>..\packages\TestStack.ConventionTests.2.2.1\lib\net40\TestStack.ConventionTests.dll</HintPath>
89+
<Private>True</Private>
90+
</Reference>
7191
<Reference Include="YamlDotNet, Version=3.5.0.0, Culture=neutral, processorArchitecture=MSIL">
7292
<SpecificVersion>False</SpecificVersion>
7393
<HintPath>..\packages\YamlDotNet.3.5.1\lib\net35\YamlDotNet.dll</HintPath>
@@ -85,6 +105,9 @@
85105
<Compile Include="Fixtures\BaseGitFlowRepositoryFixture.cs" />
86106
<Compile Include="GitVersionContextTests.cs" />
87107
<Compile Include="Helpers\DirectoryHelper.cs" />
108+
<Compile Include="Init\InitScenarios.cs" />
109+
<Compile Include="Init\InitStepsDefaultResponsesDoNotThrow.cs" />
110+
<Compile Include="Init\TestConsole.cs" />
88111
<Compile Include="IntegrationTests\OtherScenarios.cs" />
89112
<Compile Include="IntegrationTests\PullRequestScenarios.cs" />
90113
<Compile Include="IntegrationTests\RemoteRepositoryScenarios.cs" />
@@ -135,6 +158,7 @@
135158
<Compile Include="VersionCalculation\TestMetaDataCalculator.cs" />
136159
</ItemGroup>
137160
<ItemGroup>
161+
<None Include="app.config" />
138162
<None Include="packages.config" />
139163
</ItemGroup>
140164
<ItemGroup>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace GitVersionCore.Tests.Init
2+
{
3+
using GitVersion;
4+
using GitVersion.Configuration.Init;
5+
using GitVersion.Configuration.Init.Wizard;
6+
using NUnit.Framework;
7+
using TestStack.ConventionTests;
8+
using TestStack.ConventionTests.ConventionData;
9+
10+
[TestFixture]
11+
public class InitScenarios
12+
{
13+
[Test]
14+
public void DefaultResponsesDoNotThrow()
15+
{
16+
var steps = Types.InAssemblyOf<EditConfigStep>(t => t.IsSubclassOf(typeof(ConfigInitWizardStep)) && t.IsConcreteClass());
17+
Convention.Is(new InitStepsDefaultResponsesDoNotThrow(), steps);
18+
}
19+
}
20+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
namespace GitVersionCore.Tests.Init
2+
{
3+
using System;
4+
using System.Linq;
5+
using System.Reflection;
6+
using GitVersion.Configuration.Init.Wizard;
7+
using TestStack.ConventionTests;
8+
using TestStack.ConventionTests.ConventionData;
9+
10+
public class InitStepsDefaultResponsesDoNotThrow : IConvention<Types>
11+
{
12+
public void Execute(Types data, IConventionResultContext result)
13+
{
14+
var resultProperty = typeof(ConfigInitWizardStep).GetProperty("DefaultResult", BindingFlags.NonPublic | BindingFlags.Instance);
15+
result
16+
.Is("Init steps default response should not throw",
17+
data.TypesToVerify.Where(t =>
18+
{
19+
var constructorInfo = t.GetConstructors().Single();
20+
var ctorArguments = constructorInfo.GetParameters().Select(p => p.ParameterType.IsValueType ? Activator.CreateInstance(p.ParameterType) : null).ToArray();
21+
var instance = Activator.CreateInstance(t, ctorArguments);
22+
try
23+
{
24+
resultProperty.GetValue(instance);
25+
}
26+
catch (Exception)
27+
{
28+
return true;
29+
}
30+
return false;
31+
}));
32+
}
33+
34+
public string ConventionReason { get { return "So things do not blow up"; } }
35+
}
36+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
namespace GitVersionCore.Tests.Init
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using GitVersion;
6+
7+
public class TestConsole : IConsole
8+
{
9+
readonly Queue<string> responses;
10+
11+
public TestConsole(params string[] responses)
12+
{
13+
this.responses = new Queue<string>(responses);
14+
}
15+
16+
public void WriteLine(string msg)
17+
{
18+
Logger.WriteInfo(msg + Environment.NewLine);
19+
}
20+
21+
public void WriteLine()
22+
{
23+
Logger.WriteInfo(Environment.NewLine);
24+
}
25+
26+
public void Write(string msg)
27+
{
28+
Logger.WriteInfo(msg);
29+
}
30+
31+
public string ReadLine()
32+
{
33+
return responses.Dequeue();
34+
}
35+
36+
public IDisposable UseColor(ConsoleColor consoleColor)
37+
{
38+
return new NoOpDisposable();
39+
}
40+
41+
class NoOpDisposable : IDisposable
42+
{
43+
public void Dispose() { }
44+
}
45+
}
46+
}

src/GitVersionCore.Tests/packages.config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
<package id="FluentDateTime" version="1.11.0" targetFramework="net45" />
66
<package id="Fody" version="1.28.1" targetFramework="net45" developmentDependency="true" />
77
<package id="LibGit2Sharp" version="0.20.1.0" targetFramework="net45" />
8+
<package id="Mono.Cecil" version="0.9.6.1" targetFramework="net45" />
89
<package id="NUnit" version="2.6.4" targetFramework="net45" />
910
<package id="Shouldly" version="2.5.0" targetFramework="net45" />
11+
<package id="TestStack.ConventionTests" version="2.2.1" targetFramework="net45" />
1012
<package id="YamlDotNet" version="3.5.1" targetFramework="net45" />
1113
</packages>

src/GitVersionCore/Configuration/ConfigurationProvider.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,11 @@ static string GetConfigFilePath(string workingDirectory)
110110
return Path.Combine(workingDirectory, "GitVersionConfig.yaml");
111111
}
112112

113-
public static void Init(string workingDirectory, IFileSystem fileSystem)
113+
public static void Init(string workingDirectory, IFileSystem fileSystem, IConsole console)
114114
{
115115
var configFilePath = GetConfigFilePath(workingDirectory);
116-
var config = new ConfigInitWizard().Run(Provide(workingDirectory, fileSystem), workingDirectory, fileSystem);
116+
var currentConfiguration = Provide(workingDirectory, fileSystem, applyDefaults: false);
117+
var config = new ConfigInitWizard(console, fileSystem).Run(currentConfiguration, workingDirectory);
117118
if (config == null) return;
118119

119120
using (var stream = fileSystem.OpenWrite(configFilePath))
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
namespace GitVersion
2+
{
3+
using System;
4+
5+
class ConsoleAdapter : IConsole
6+
{
7+
public void WriteLine(string msg)
8+
{
9+
throw new NotImplementedException();
10+
}
11+
12+
public void WriteLine()
13+
{
14+
throw new NotImplementedException();
15+
}
16+
17+
public void Write(string msg)
18+
{
19+
throw new NotImplementedException();
20+
}
21+
22+
public string ReadLine()
23+
{
24+
throw new NotImplementedException();
25+
}
26+
27+
public IDisposable UseColor(ConsoleColor consoleColor)
28+
{
29+
var old = Console.ForegroundColor;
30+
Console.ForegroundColor = consoleColor;
31+
32+
return new DelegateDisposable(() => Console.ForegroundColor = old);
33+
}
34+
35+
class DelegateDisposable : IDisposable
36+
{
37+
readonly Action dispose;
38+
39+
public DelegateDisposable(Action dispose)
40+
{
41+
this.dispose = dispose;
42+
}
43+
44+
public void Dispose()
45+
{
46+
dispose();
47+
}
48+
}
49+
}
50+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace GitVersion
2+
{
3+
using System;
4+
5+
public interface IConsole
6+
{
7+
void WriteLine(string msg);
8+
void WriteLine();
9+
void Write(string msg);
10+
string ReadLine();
11+
IDisposable UseColor(ConsoleColor consoleColor);
12+
}
13+
}

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

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,32 @@ namespace GitVersion.Configuration.Init.BuildServer
99

1010
class AppVeyorSetup : ConfigInitWizardStep
1111
{
12-
protected override StepResult HandleResult(string result, Queue<ConfigInitWizardStep> steps, Config config, string workingDirectory, IFileSystem fileSystem)
12+
public AppVeyorSetup(IConsole console, IFileSystem fileSystem) : base(console, fileSystem)
13+
{
14+
}
15+
16+
protected override StepResult HandleResult(string result, Queue<ConfigInitWizardStep> steps, Config config, string workingDirectory)
1317
{
1418
switch (result)
1519
{
1620
case "0":
17-
steps.Enqueue(new EditConfigStep());
21+
steps.Enqueue(new EditConfigStep(Console, FileSystem));
1822
return StepResult.Ok();
1923
case "1":
20-
GenerateBasicConfig(workingDirectory, fileSystem);
21-
steps.Enqueue(new EditConfigStep());
24+
GenerateBasicConfig(workingDirectory);
25+
steps.Enqueue(new EditConfigStep(Console, FileSystem));
2226
return StepResult.Ok();
2327
case "2":
24-
GenerateNuGetConfig(workingDirectory, fileSystem);
25-
steps.Enqueue(new EditConfigStep());
28+
GenerateNuGetConfig(workingDirectory);
29+
steps.Enqueue(new EditConfigStep(Console, FileSystem));
2630
return StepResult.Ok();
2731
}
2832
return StepResult.InvalidResponseSelected();
2933
}
3034

31-
void GenerateBasicConfig(string workingDirectory, IFileSystem fileSystem)
35+
void GenerateBasicConfig(string workingDirectory)
3236
{
33-
WriteConfig(workingDirectory, fileSystem, @"install:
37+
WriteConfig(workingDirectory, FileSystem, @"install:
3438
- choco install gitversion.portable -pre -y
3539
3640
before_build:
@@ -41,9 +45,9 @@ void GenerateBasicConfig(string workingDirectory, IFileSystem fileSystem)
4145
project: <your sln file>");
4246
}
4347

44-
void GenerateNuGetConfig(string workingDirectory, IFileSystem fileSystem)
48+
void GenerateNuGetConfig(string workingDirectory)
4549
{
46-
WriteConfig(workingDirectory, fileSystem, @"install:
50+
WriteConfig(workingDirectory, FileSystem, @"install:
4751
- choco install gitversion.portable -pre -y
4852
4953
assembly_info:
@@ -69,10 +73,10 @@ void WriteConfig(string workingDirectory, IFileSystem fileSystem, string configC
6973
Logger.WriteInfo(string.Format("AppVeyor sample config file written to {0}", outputFilename));
7074
}
7175

72-
protected override string GetPrompt(Config config, string workingDirectory, IFileSystem fileSystem)
76+
protected override string GetPrompt(Config config, string workingDirectory)
7377
{
7478
var prompt = new StringBuilder();
75-
if (AppVeyorConfigExists(workingDirectory, fileSystem))
79+
if (AppVeyorConfigExists(workingDirectory, FileSystem))
7680
{
7781
prompt.AppendLine("GitVersion doesn't support modifying existing appveyor config files. We will generate appveyor.gitversion.yml instead");
7882
prompt.AppendLine();

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,25 @@
66

77
class SetupBuildScripts : ConfigInitWizardStep
88
{
9-
protected override StepResult HandleResult(string result, Queue<ConfigInitWizardStep> steps, Config config, string workingDirectory, IFileSystem fileSystem)
9+
public SetupBuildScripts(IConsole console, IFileSystem fileSystem) : base(console, fileSystem)
10+
{
11+
}
12+
13+
protected override StepResult HandleResult(string result, Queue<ConfigInitWizardStep> steps, Config config, string workingDirectory)
1014
{
1115
switch (result)
1216
{
1317
case "0":
14-
steps.Enqueue(new EditConfigStep());
18+
steps.Enqueue(new EditConfigStep(Console, FileSystem));
1519
return StepResult.Ok();
1620
case "1":
17-
steps.Enqueue(new AppVeyorSetup());
21+
steps.Enqueue(new AppVeyorSetup(Console, FileSystem));
1822
return StepResult.Ok();
1923
}
2024
return StepResult.Ok();
2125
}
2226

23-
protected override string GetPrompt(Config config, string workingDirectory, IFileSystem fileSystem)
27+
protected override string GetPrompt(Config config, string workingDirectory)
2428
{
2529
return @"What build server are you using?
2630

src/GitVersionCore/Configuration/Init/EditConfigStep.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ namespace GitVersion.Configuration.Init
88

99
public class EditConfigStep : ConfigInitWizardStep
1010
{
11-
protected override StepResult HandleResult(string result, Queue<ConfigInitWizardStep> steps, Config config, string workingDirectory, IFileSystem fileSystem)
11+
public EditConfigStep(IConsole console, IFileSystem fileSystem) : base(console, fileSystem)
12+
{
13+
}
14+
15+
protected override StepResult HandleResult(string result, Queue<ConfigInitWizardStep> steps, Config config, string workingDirectory)
1216
{
1317
switch (result)
1418
{
@@ -18,30 +22,30 @@ protected override StepResult HandleResult(string result, Queue<ConfigInitWizard
1822
return StepResult.ExitWithoutSaving();
1923

2024
case "2":
21-
steps.Enqueue(new PickBranchingStrategyStep());
25+
steps.Enqueue(new PickBranchingStrategyStep(Console, FileSystem));
2226
return StepResult.Ok();
2327

2428
case "3":
25-
steps.Enqueue(new SetNextVersion());
29+
steps.Enqueue(new SetNextVersion(Console, FileSystem));
2630
return StepResult.Ok();
2731

2832
case "4":
29-
steps.Enqueue(new ConfigureBranches());
33+
steps.Enqueue(new ConfigureBranches(Console, FileSystem));
3034
return StepResult.Ok();
3135
case "5":
32-
steps.Enqueue(new GlobalModeSetting(new EditConfigStep(), false));
36+
steps.Enqueue(new GlobalModeSetting(new EditConfigStep(Console, FileSystem), false, Console, FileSystem));
3337
return StepResult.Ok();
3438
case "6":
35-
steps.Enqueue(new AssemblyVersioningSchemeSetting());
39+
steps.Enqueue(new AssemblyVersioningSchemeSetting(Console, FileSystem));
3640
return StepResult.Ok();
3741
case "7":
38-
steps.Enqueue(new SetupBuildScripts());
42+
steps.Enqueue(new SetupBuildScripts(Console, FileSystem));
3943
return StepResult.Ok();
4044
}
4145
return StepResult.InvalidResponseSelected();
4246
}
4347

44-
protected override string GetPrompt(Config config, string workingDirectory, IFileSystem fileSystem)
48+
protected override string GetPrompt(Config config, string workingDirectory)
4549
{
4650
return string.Format(@"Which would you like to change?
4751

0 commit comments

Comments
 (0)