Skip to content

Commit 7892afb

Browse files
committed
code cleanup
1 parent 19462e1 commit 7892afb

File tree

71 files changed

+277
-320
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+277
-320
lines changed

src/GitTools.Testing/Fixtures/RepositoryFixtureBase.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ namespace GitTools.Testing;
88
/// </summary>
99
public abstract class RepositoryFixtureBase : IDisposable
1010
{
11-
private readonly SequenceDiagram sequenceDiagram;
1211

1312
protected RepositoryFixtureBase(Func<string, IRepository> repoBuilder)
1413
: this(repoBuilder(PathHelper.GetTempPath()))
@@ -17,7 +16,7 @@ protected RepositoryFixtureBase(Func<string, IRepository> repoBuilder)
1716

1817
protected RepositoryFixtureBase(IRepository repository)
1918
{
20-
this.sequenceDiagram = new SequenceDiagram();
19+
this.SequenceDiagram = new SequenceDiagram();
2120
Repository = repository;
2221
Repository.Config.Set("user.name", "Test");
2322
Repository.Config.Set("user.email", "[email protected]");
@@ -27,7 +26,8 @@ protected RepositoryFixtureBase(IRepository repository)
2726

2827
public string RepositoryPath => Repository.Info.WorkingDirectory.TrimEnd('\\');
2928

30-
public SequenceDiagram SequenceDiagram => this.sequenceDiagram;
29+
public SequenceDiagram SequenceDiagram { get; }
30+
3131

3232
/// <summary>
3333
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
@@ -57,10 +57,10 @@ protected virtual void Dispose(bool disposing)
5757
e.Message);
5858
}
5959

60-
this.sequenceDiagram.End();
60+
this.SequenceDiagram.End();
6161
Console.WriteLine("**Visualisation of test:**");
6262
Console.WriteLine(string.Empty);
63-
Console.WriteLine(this.sequenceDiagram.GetDiagram());
63+
Console.WriteLine(this.SequenceDiagram.GetDiagram());
6464
}
6565

6666
public void Checkout(string branch) => Commands.Checkout(Repository, branch);
@@ -75,28 +75,28 @@ public void MakeATaggedCommit(string tag)
7575

7676
public void ApplyTag(string tag)
7777
{
78-
this.sequenceDiagram.ApplyTag(tag, Repository.Head.FriendlyName);
78+
this.SequenceDiagram.ApplyTag(tag, Repository.Head.FriendlyName);
7979
Repository.ApplyTag(tag);
8080
}
8181

8282
public void BranchTo(string branchName, string @as = null)
8383
{
84-
this.sequenceDiagram.BranchTo(branchName, Repository.Head.FriendlyName, @as);
84+
this.SequenceDiagram.BranchTo(branchName, Repository.Head.FriendlyName, @as);
8585
var branch = Repository.CreateBranch(branchName);
8686
Commands.Checkout(Repository, branch);
8787
}
8888

8989
public void BranchToFromTag(string branchName, string fromTag, string onBranch, string @as = null)
9090
{
91-
this.sequenceDiagram.BranchToFromTag(branchName, fromTag, onBranch, @as);
91+
this.SequenceDiagram.BranchToFromTag(branchName, fromTag, onBranch, @as);
9292
var branch = Repository.CreateBranch(branchName);
9393
Commands.Checkout(Repository, branch);
9494
}
9595

9696
public void MakeACommit()
9797
{
9898
var to = Repository.Head.FriendlyName;
99-
this.sequenceDiagram.MakeACommit(to);
99+
this.SequenceDiagram.MakeACommit(to);
100100
Repository.MakeACommit();
101101
}
102102

@@ -105,7 +105,7 @@ public void MakeACommit()
105105
/// </summary>
106106
public void MergeNoFF(string mergeSource)
107107
{
108-
this.sequenceDiagram.Merge(mergeSource, Repository.Head.FriendlyName);
108+
this.SequenceDiagram.Merge(mergeSource, Repository.Head.FriendlyName);
109109
Repository.MergeNoFF(mergeSource, Generate.SignatureNow());
110110
}
111111

src/GitTools.Testing/Generate.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ public static Signature SignatureNow()
1919
/// <summary>
2020
/// Creates a libgit2sharp signature at the specified time
2121
/// </summary>
22-
public static Signature Signature(DateTimeOffset dateTimeOffset) => new("A. U. Thor", "[email protected]", dateTimeOffset);
22+
private static Signature Signature(DateTimeOffset dateTimeOffset) => new("A. U. Thor", "[email protected]", dateTimeOffset);
2323
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace GitTools.Testing.Internal;
2+
3+
public static class ObjectExtensions
4+
{
5+
public static void Deconstruct<TKey, TValue>(
6+
this KeyValuePair<TKey, TValue> kvp,
7+
out TKey key,
8+
out TValue value)
9+
{
10+
key = kvp.Key;
11+
value = kvp.Value;
12+
}
13+
}

src/GitTools.Testing/Internal/ProcessHelper.cs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ public static int Run(Action<string> output, Action<string> errorOutput, TextRea
8181
if (output == null)
8282
throw new ArgumentNullException(nameof(output));
8383

84-
workingDirectory ??= Environment.CurrentDirectory;
85-
8684
var psi = new ProcessStartInfo
8785
{
8886
UseShellExecute = false,
@@ -96,23 +94,31 @@ public static int Run(Action<string> output, Action<string> errorOutput, TextRea
9694
FileName = exe,
9795
Arguments = args
9896
};
99-
foreach (var environmentalVariable in environmentalVariables)
97+
foreach (var (key, value) in environmentalVariables)
10098
{
101-
if (psi.EnvironmentVariables.ContainsKey(environmentalVariable.Key))
99+
var psiEnvironmentVariables = psi.EnvironmentVariables;
100+
if (psiEnvironmentVariables.ContainsKey(key) && string.IsNullOrEmpty(value))
102101
{
103-
psi.EnvironmentVariables[environmentalVariable.Key] = environmentalVariable.Value;
102+
psiEnvironmentVariables.Remove(key);
104103
}
105-
else
104+
else if (psiEnvironmentVariables.ContainsKey(key))
106105
{
107-
psi.EnvironmentVariables.Add(environmentalVariable.Key, environmentalVariable.Value);
106+
psiEnvironmentVariables[key] = value;
108107
}
109-
if (psi.EnvironmentVariables.ContainsKey(environmentalVariable.Key) && environmentalVariable.Value == null)
108+
else
110109
{
111-
psi.EnvironmentVariables.Remove(environmentalVariable.Key);
110+
psiEnvironmentVariables.Add(key, value);
112111
}
113112
}
114113

115114
using var process = Start(psi);
115+
116+
if (process is null)
117+
{
118+
// FIX ME: What error code do you want to return?
119+
return -1;
120+
}
121+
116122
using var mreOut = new ManualResetEvent(false);
117123
using var mreErr = new ManualResetEvent(false);
118124
process.EnableRaisingEvents = true;
@@ -160,7 +166,7 @@ private enum NativeErrorCode
160166
}
161167

162168
[Flags]
163-
public enum ErrorModes
169+
private enum ErrorModes
164170
{
165171
Default = 0x0,
166172
FailCriticalErrors = 0x1,
@@ -169,7 +175,7 @@ public enum ErrorModes
169175
NoOpenFileErrorBox = 0x8000
170176
}
171177

172-
private struct ChangeErrorMode : IDisposable
178+
private readonly struct ChangeErrorMode : IDisposable
173179
{
174180
private readonly int oldMode;
175181

src/GitVersion.App.Tests/ArgumentParserTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,10 @@ public void OutputFileArgumentCanBeParsed(string args, string outputFile)
201201
[Test]
202202
public void UrlAndBranchNameCanBeParsed()
203203
{
204-
var arguments = this.argumentParser.ParseArguments("targetDirectoryPath -url http://github.com/Particular/GitVersion.git -b somebranch");
204+
var arguments = this.argumentParser.ParseArguments("targetDirectoryPath -url https://github.com/Particular/GitVersion.git -b someBranch");
205205
arguments.TargetPath.ShouldBe("targetDirectoryPath");
206-
arguments.TargetUrl.ShouldBe("http://github.com/Particular/GitVersion.git");
207-
arguments.TargetBranch.ShouldBe("somebranch");
206+
arguments.TargetUrl.ShouldBe("https://github.com/Particular/GitVersion.git");
207+
arguments.TargetBranch.ShouldBe("someBranch");
208208
arguments.IsHelp.ShouldBe(false);
209209
}
210210

@@ -255,7 +255,7 @@ public void UpdateAssemblyInfoFalse(string command)
255255
}
256256

257257
[TestCase("-updateAssemblyInfo Assembly.cs Assembly1.cs -ensureassemblyinfo")]
258-
public void CreateMulitpleAssemblyInfoProtected(string command)
258+
public void CreateMultipleAssemblyInfoProtected(string command)
259259
{
260260
var exception = Assert.Throws<WarningException>(() => this.argumentParser.ParseArguments(command));
261261
exception.Message.ShouldBe("Can't specify multiple assembly info files when using /ensureassemblyinfo switch, either use a single assembly info file or do not specify /ensureassemblyinfo and create assembly info files manually");
@@ -642,7 +642,7 @@ public void NofetchTrueWhenDefined()
642642
}
643643

644644
[Test]
645-
public void NonormilizeTrueWhenDefined()
645+
public void NoNormalizeTrueWhenDefined()
646646
{
647647
var arguments = this.argumentParser.ParseArguments("-nonormalize");
648648
arguments.NoNormalize.ShouldBe(true);

src/GitVersion.App.Tests/ExecCmdLineArgumentTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public void LogPathContainsForwardSlash()
2727
fixture.MakeATaggedCommit("1.2.3");
2828
fixture.MakeACommit();
2929

30-
var result = GitVersionHelper.ExecuteIn(fixture.RepositoryPath, arguments: @" /l ""/tmp/path""", logToFile: false);
30+
var result = GitVersionHelper.ExecuteIn(fixture.RepositoryPath, @" /l ""/tmp/path""", false);
3131

3232
result.ExitCode.ShouldBe(0);
3333
result.Output.ShouldContain(@"""MajorMinorPatch"": ""1.2.4""");
@@ -43,7 +43,7 @@ public void CheckBuildServerVerbosityConsole(string verbosityArg, string expecte
4343
fixture.MakeATaggedCommit("1.2.3");
4444
fixture.MakeACommit();
4545

46-
var result = GitVersionHelper.ExecuteIn(fixture.RepositoryPath, arguments: $@" {verbosityArg} -output buildserver /l ""/tmp/path""", logToFile: false);
46+
var result = GitVersionHelper.ExecuteIn(fixture.RepositoryPath, $@" {verbosityArg} -output buildserver /l ""/tmp/path""", false);
4747

4848
result.ExitCode.ShouldBe(0);
4949
result.Output.ShouldContain(expectedOutput);
@@ -52,7 +52,7 @@ public void CheckBuildServerVerbosityConsole(string verbosityArg, string expecte
5252
[Test]
5353
public void WorkingDirectoryWithoutGitFolderFailsWithInformativeMessage()
5454
{
55-
var result = GitVersionHelper.ExecuteIn(System.Environment.SystemDirectory, arguments: null, logToFile: false);
55+
var result = GitVersionHelper.ExecuteIn(System.Environment.SystemDirectory, null, false);
5656

5757
result.ExitCode.ShouldNotBe(0);
5858
result.Output.ShouldContain("Cannot find the .git directory");
@@ -63,7 +63,7 @@ public void WorkingDirectoryWithoutCommitsFailsWithInformativeMessage()
6363
{
6464
using var fixture = new EmptyRepositoryFixture();
6565

66-
var result = GitVersionHelper.ExecuteIn(fixture.RepositoryPath, arguments: null, logToFile: false);
66+
var result = GitVersionHelper.ExecuteIn(fixture.RepositoryPath, null, false);
6767

6868
result.ExitCode.ShouldNotBe(0);
6969
result.Output.ShouldContain("No commits found on the current branch.");

src/GitVersion.App.Tests/Helpers/ArgumentBuilder.cs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,58 +4,58 @@ namespace GitVersion.App.Tests;
44

55
public class ArgumentBuilder
66
{
7-
public ArgumentBuilder(string workingDirectory) => this.workingDirectory = workingDirectory;
7+
public ArgumentBuilder(string workingDirectory) => this.WorkingDirectory = workingDirectory;
88

99
public ArgumentBuilder(string workingDirectory, string exec, string execArgs, string projectFile, string projectArgs, string logFile)
1010
{
11-
this.workingDirectory = workingDirectory;
11+
this.WorkingDirectory = workingDirectory;
1212
this.exec = exec;
1313
this.execArgs = execArgs;
1414
this.projectFile = projectFile;
1515
this.projectArgs = projectArgs;
16-
this.logFile = logFile;
16+
this.LogFile = logFile;
1717
}
1818

1919
public ArgumentBuilder(string workingDirectory, string additionalArguments, string logFile)
2020
{
21-
this.workingDirectory = workingDirectory;
21+
this.WorkingDirectory = workingDirectory;
2222
this.additionalArguments = additionalArguments;
23-
this.logFile = logFile;
23+
this.LogFile = logFile;
2424
}
2525

26-
public string WorkingDirectory => this.workingDirectory;
26+
public string WorkingDirectory { get; }
2727

28-
public string LogFile => this.logFile;
28+
public string LogFile { get; }
2929

3030
public override string ToString()
3131
{
3232
var arguments = new StringBuilder();
3333

34-
arguments.AppendFormat(" /targetpath \"{0}\"", this.workingDirectory);
34+
arguments.Append($" /targetpath \"{this.WorkingDirectory}\"");
3535

3636
if (!this.exec.IsNullOrWhiteSpace())
3737
{
38-
arguments.AppendFormat(" /exec \"{0}\"", this.exec);
38+
arguments.Append($" /exec \"{this.exec}\"");
3939
}
4040

4141
if (!this.execArgs.IsNullOrWhiteSpace())
4242
{
43-
arguments.AppendFormat(" /execArgs \"{0}\"", this.execArgs);
43+
arguments.Append($" /execArgs \"{this.execArgs}\"");
4444
}
4545

4646
if (!this.projectFile.IsNullOrWhiteSpace())
4747
{
48-
arguments.AppendFormat(" /proj \"{0}\"", this.projectFile);
48+
arguments.Append($" /proj \"{this.projectFile}\"");
4949
}
5050

5151
if (!this.projectArgs.IsNullOrWhiteSpace())
5252
{
53-
arguments.AppendFormat(" /projargs \"{0}\"", this.projectArgs);
53+
arguments.Append($" /projargs \"{this.projectArgs}\"");
5454
}
5555

56-
if (!this.logFile.IsNullOrWhiteSpace())
56+
if (!this.LogFile.IsNullOrWhiteSpace())
5757
{
58-
arguments.AppendFormat(" /l \"{0}\"", this.logFile);
58+
arguments.Append($" /l \"{this.LogFile}\"");
5959
}
6060

6161
arguments.Append(this.additionalArguments);
@@ -66,8 +66,6 @@ public override string ToString()
6666
private readonly string additionalArguments;
6767
private readonly string exec;
6868
private readonly string execArgs;
69-
private readonly string logFile;
7069
private readonly string projectArgs;
7170
private readonly string projectFile;
72-
private readonly string workingDirectory;
7371
}

src/GitVersion.App.Tests/Helpers/GitVersionHelper.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ params KeyValuePair<string, string>[] environments
5050
{ SpaceAutomation.EnvironmentVariableName, null }
5151
};
5252

53-
foreach (var environment in environments)
53+
foreach (var (key, value) in environments)
5454
{
55-
if (environmentalVariables.ContainsKey(environment.Key))
55+
if (environmentalVariables.ContainsKey(key))
5656
{
57-
environmentalVariables[environment.Key] = environment.Value;
57+
environmentalVariables[key] = value;
5858
}
5959
else
6060
{
61-
environmentalVariables.Add(environment.Key, environment.Value);
61+
environmentalVariables.Add(key, value);
6262
}
6363
}
6464

src/GitVersion.App.Tests/Helpers/ProgramFixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ public ProgramFixture(string workingDirectory = "")
4040

4141
public void WithEnv(params KeyValuePair<string, string>[] envs)
4242
{
43-
foreach (var env in envs)
43+
foreach (var (key, value) in envs)
4444
{
45-
this.environment.SetEnvironmentVariable(env.Key, env.Value);
45+
this.environment.SetEnvironmentVariable(key, value);
4646
}
4747
}
4848

src/GitVersion.App.Tests/UpdateWixVersionFileTests.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,14 @@ public void WixVersionFileContentTest()
7171
private static Dictionary<string, string> GetGitVersionVarsInWixFile(string file)
7272
{
7373
var gitVersionVarsInWix = new Dictionary<string, string>();
74-
using (var reader = new XmlTextReader(file))
74+
using var reader = new XmlTextReader(file);
75+
while (reader.Read())
7576
{
76-
while (reader.Read())
77-
{
78-
if (reader.Name == "define")
79-
{
80-
var component = reader.Value.Split('=');
81-
gitVersionVarsInWix[component[0]] = component[1].TrimStart('"').TrimEnd('"');
82-
}
83-
}
77+
if (reader.Name != "define")
78+
continue;
79+
80+
var component = reader.Value.Split('=');
81+
gitVersionVarsInWix[component[0]] = component[1].TrimStart('"').TrimEnd('"');
8482
}
8583
return gitVersionVarsInWix;
8684
}

0 commit comments

Comments
 (0)