Skip to content

Commit dcb9ac9

Browse files
committed
Remove namespace around test classes
1 parent ee7c3f4 commit dcb9ac9

File tree

8 files changed

+196
-209
lines changed

8 files changed

+196
-209
lines changed

src/NerdBank.GitVersioning.Tests/AssemblyInfoTest.cs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,25 @@
66
using Nerdbank.GitVersioning.Tasks;
77
using Xunit;
88

9-
namespace NerdBank.GitVersioning.Tests
9+
public class AssemblyInfoTest
1010
{
11-
public class AssemblyInfoTest
11+
public AssemblyInfoTest()
1212
{
13-
public AssemblyInfoTest()
14-
{
15-
MSBuildExtensions.LoadMSBuild();
16-
}
13+
MSBuildExtensions.LoadMSBuild();
14+
}
15+
16+
[Fact]
17+
public void FSharpGenerator()
18+
{
19+
var info = new AssemblyVersionInfo();
20+
info.AssemblyCompany = "company";
21+
info.AssemblyFileVersion = "1.3.1.0";
22+
info.AssemblyVersion = "1.3.0.0";
23+
info.CodeLanguage = "f#";
1724

18-
[Fact]
19-
public void FSharpGenerator()
20-
{
21-
var info = new AssemblyVersionInfo();
22-
info.AssemblyCompany = "company";
23-
info.AssemblyFileVersion = "1.3.1.0";
24-
info.AssemblyVersion = "1.3.0.0";
25-
info.CodeLanguage = "f#";
26-
27-
var built = info.BuildCode();
25+
var built = info.BuildCode();
2826

29-
var expected = @"//------------------------------------------------------------------------------
27+
var expected = @"//------------------------------------------------------------------------------
3028
// <auto-generated>
3129
// This code was generated by a tool.
3230
// Runtime Version:4.0.30319.42000
@@ -49,7 +47,6 @@ type internal ThisAssembly() =
4947
static member internal RootNamespace = """"
5048
do()
5149
";
52-
Assert.Equal(expected, built);
53-
}
50+
Assert.Equal(expected, built);
5451
}
5552
}

src/NerdBank.GitVersioning.Tests/BuildIntegrationTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
using Microsoft.CodeAnalysis.CSharp;
1919
using Microsoft.CodeAnalysis.CSharp.Syntax;
2020
using Nerdbank.GitVersioning;
21-
using Nerdbank.GitVersioning.Tests;
2221
using Validation;
2322
using Xunit;
2423
using Xunit.Abstractions;

src/NerdBank.GitVersioning.Tests/GitExtensionsTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.Threading.Tasks;
77
using LibGit2Sharp;
88
using Nerdbank.GitVersioning;
9-
using Nerdbank.GitVersioning.Tests;
109
using Validation;
1110
using Xunit;
1211
using Xunit.Abstractions;

src/NerdBank.GitVersioning.Tests/ReleaseManagerTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Linq;
44
using LibGit2Sharp;
55
using Nerdbank.GitVersioning;
6-
using Nerdbank.GitVersioning.Tests;
76
using Xunit;
87
using Xunit.Abstractions;
98

Lines changed: 106 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,152 +1,150 @@
1-
namespace Nerdbank.GitVersioning.Tests
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.IO;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using LibGit2Sharp;
9+
using Nerdbank.GitVersioning;
10+
using Validation;
11+
using Xunit.Abstractions;
12+
13+
public abstract class RepoTestBase : IDisposable
214
{
3-
using System;
4-
using System.Collections.Generic;
5-
using System.Diagnostics;
6-
using System.IO;
7-
using System.Linq;
8-
using System.Text;
9-
using System.Threading.Tasks;
10-
using LibGit2Sharp;
11-
using Validation;
12-
using Xunit.Abstractions;
13-
14-
public abstract class RepoTestBase : IDisposable
15-
{
16-
private readonly List<string> repoDirectories = new List<string>();
15+
private readonly List<string> repoDirectories = new List<string>();
1716

18-
public RepoTestBase(ITestOutputHelper logger)
19-
{
20-
Requires.NotNull(logger, nameof(logger));
17+
public RepoTestBase(ITestOutputHelper logger)
18+
{
19+
Requires.NotNull(logger, nameof(logger));
2120

22-
this.Logger = logger;
23-
this.RepoPath = this.CreateDirectoryForNewRepo();
24-
}
21+
this.Logger = logger;
22+
this.RepoPath = this.CreateDirectoryForNewRepo();
23+
}
2524

26-
protected ITestOutputHelper Logger { get; }
25+
protected ITestOutputHelper Logger { get; }
2726

28-
protected Repository Repo { get; set; }
27+
protected Repository Repo { get; set; }
2928

30-
protected string RepoPath { get; set; }
29+
protected string RepoPath { get; set; }
3130

32-
protected Signature Signer => new Signature("a", "[email protected]", new DateTimeOffset(2015, 8, 2, 0, 0, 0, TimeSpan.Zero));
31+
protected Signature Signer => new Signature("a", "[email protected]", new DateTimeOffset(2015, 8, 2, 0, 0, 0, TimeSpan.Zero));
3332

34-
public void Dispose()
35-
{
36-
this.Dispose(true);
37-
GC.SuppressFinalize(this);
38-
}
33+
public void Dispose()
34+
{
35+
this.Dispose(true);
36+
GC.SuppressFinalize(this);
37+
}
3938

40-
protected string CreateDirectoryForNewRepo()
39+
protected string CreateDirectoryForNewRepo()
40+
{
41+
string repoPath;
42+
do
4143
{
42-
string repoPath;
43-
do
44-
{
45-
repoPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
46-
} while (Directory.Exists(repoPath));
47-
Directory.CreateDirectory(repoPath);
44+
repoPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
45+
} while (Directory.Exists(repoPath));
46+
Directory.CreateDirectory(repoPath);
4847

49-
this.repoDirectories.Add(repoPath);
50-
return repoPath;
51-
}
48+
this.repoDirectories.Add(repoPath);
49+
return repoPath;
50+
}
5251

53-
protected virtual void Dispose(bool disposing)
52+
protected virtual void Dispose(bool disposing)
53+
{
54+
if (disposing)
5455
{
55-
if (disposing)
56+
this.Repo?.Dispose();
57+
foreach (string dir in this.repoDirectories)
5658
{
57-
this.Repo?.Dispose();
58-
foreach (string dir in this.repoDirectories)
59+
try
60+
{
61+
TestUtilities.DeleteDirectory(dir);
62+
}
63+
catch (IOException)
5964
{
60-
try
61-
{
62-
TestUtilities.DeleteDirectory(dir);
63-
}
64-
catch (IOException)
65-
{
66-
// This happens in AppVeyor a lot.
67-
}
65+
// This happens in AppVeyor a lot.
6866
}
6967
}
7068
}
69+
}
7170

72-
protected void InitializeSourceControl()
71+
protected void InitializeSourceControl()
72+
{
73+
Repository.Init(this.RepoPath);
74+
this.Repo = new Repository(this.RepoPath);
75+
foreach (var file in this.Repo.RetrieveStatus().Untracked)
7376
{
74-
Repository.Init(this.RepoPath);
75-
this.Repo = new Repository(this.RepoPath);
76-
foreach (var file in this.Repo.RetrieveStatus().Untracked)
77-
{
78-
Commands.Stage(this.Repo, file.FilePath);
79-
}
80-
81-
if (this.Repo.Index.Count > 0)
82-
{
83-
this.Repo.Commit("initial commit", this.Signer, this.Signer);
84-
}
77+
Commands.Stage(this.Repo, file.FilePath);
8578
}
8679

87-
protected void AddCommits(int count = 1)
80+
if (this.Repo.Index.Count > 0)
8881
{
89-
Verify.Operation(this.Repo != null, "Repo has not been created yet.");
90-
for (int i = 1; i <= count; i++)
91-
{
92-
this.Repo.Commit($"filler commit {i}", this.Signer, this.Signer, new CommitOptions { AllowEmptyCommit = true });
93-
}
82+
this.Repo.Commit("initial commit", this.Signer, this.Signer);
9483
}
84+
}
9585

96-
protected Commit WriteVersionTxtFile(string version = "1.2", string prerelease = "", string relativeDirectory = null)
86+
protected void AddCommits(int count = 1)
87+
{
88+
Verify.Operation(this.Repo != null, "Repo has not been created yet.");
89+
for (int i = 1; i <= count; i++)
9790
{
98-
if (relativeDirectory == null)
99-
{
100-
relativeDirectory = string.Empty;
101-
}
102-
103-
string versionFilePath = Path.Combine(this.RepoPath, relativeDirectory, "version.txt");
104-
File.WriteAllText(versionFilePath, $"{version}\r\n{prerelease}");
105-
return this.CommitVersionFile(versionFilePath, $"{version}{prerelease}");
91+
this.Repo.Commit($"filler commit {i}", this.Signer, this.Signer, new CommitOptions { AllowEmptyCommit = true });
10692
}
93+
}
10794

108-
protected Commit WriteVersionFile(string version = "1.2", string prerelease = "", string relativeDirectory = null)
95+
protected Commit WriteVersionTxtFile(string version = "1.2", string prerelease = "", string relativeDirectory = null)
96+
{
97+
if (relativeDirectory == null)
10998
{
110-
var versionData = VersionOptions.FromVersion(new System.Version(version), prerelease);
111-
return this.WriteVersionFile(versionData, relativeDirectory);
99+
relativeDirectory = string.Empty;
112100
}
113101

114-
protected Commit WriteVersionFile(VersionOptions versionData, string relativeDirectory = null)
115-
{
116-
Requires.NotNull(versionData, nameof(versionData));
102+
string versionFilePath = Path.Combine(this.RepoPath, relativeDirectory, "version.txt");
103+
File.WriteAllText(versionFilePath, $"{version}\r\n{prerelease}");
104+
return this.CommitVersionFile(versionFilePath, $"{version}{prerelease}");
105+
}
117106

118-
if (relativeDirectory == null)
119-
{
120-
relativeDirectory = string.Empty;
121-
}
107+
protected Commit WriteVersionFile(string version = "1.2", string prerelease = "", string relativeDirectory = null)
108+
{
109+
var versionData = VersionOptions.FromVersion(new System.Version(version), prerelease);
110+
return this.WriteVersionFile(versionData, relativeDirectory);
111+
}
122112

123-
string versionFilePath = VersionFile.SetVersion(Path.Combine(this.RepoPath, relativeDirectory), versionData);
124-
return this.CommitVersionFile(versionFilePath, versionData.Version?.ToString());
125-
}
113+
protected Commit WriteVersionFile(VersionOptions versionData, string relativeDirectory = null)
114+
{
115+
Requires.NotNull(versionData, nameof(versionData));
126116

127-
protected Commit CommitVersionFile(string versionFilePath, string version)
117+
if (relativeDirectory == null)
128118
{
129-
Requires.NotNullOrEmpty(versionFilePath, nameof(versionFilePath));
130-
Requires.NotNullOrEmpty(versionFilePath, nameof(versionFilePath));
119+
relativeDirectory = string.Empty;
120+
}
121+
122+
string versionFilePath = VersionFile.SetVersion(Path.Combine(this.RepoPath, relativeDirectory), versionData);
123+
return this.CommitVersionFile(versionFilePath, versionData.Version?.ToString());
124+
}
125+
126+
protected Commit CommitVersionFile(string versionFilePath, string version)
127+
{
128+
Requires.NotNullOrEmpty(versionFilePath, nameof(versionFilePath));
129+
Requires.NotNullOrEmpty(versionFilePath, nameof(versionFilePath));
131130

132-
if (this.Repo != null)
131+
if (this.Repo != null)
132+
{
133+
Assumes.True(versionFilePath.StartsWith(this.RepoPath, StringComparison.OrdinalIgnoreCase));
134+
var relativeFilePath = versionFilePath.Substring(this.RepoPath.Length).TrimStart(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
135+
Commands.Stage(this.Repo, relativeFilePath);
136+
if (Path.GetExtension(relativeFilePath) == ".json")
133137
{
134-
Assumes.True(versionFilePath.StartsWith(this.RepoPath, StringComparison.OrdinalIgnoreCase));
135-
var relativeFilePath = versionFilePath.Substring(this.RepoPath.Length).TrimStart(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
136-
Commands.Stage(this.Repo, relativeFilePath);
137-
if (Path.GetExtension(relativeFilePath) == ".json")
138+
string txtFilePath = relativeFilePath.Substring(0, relativeFilePath.Length - 4) + "txt";
139+
if (!File.Exists(Path.Combine(this.RepoPath, txtFilePath)) && this.Repo.Index[txtFilePath] != null)
138140
{
139-
string txtFilePath = relativeFilePath.Substring(0, relativeFilePath.Length - 4) + "txt";
140-
if (!File.Exists(Path.Combine(this.RepoPath, txtFilePath)) && this.Repo.Index[txtFilePath] != null)
141-
{
142-
this.Repo.Index.Remove(txtFilePath);
143-
}
141+
this.Repo.Index.Remove(txtFilePath);
144142
}
145-
146-
return this.Repo.Commit($"Add/write {relativeFilePath} set to {version ?? "Inherited"}", this.Signer, this.Signer, new CommitOptions { AllowEmptyCommit = true });
147143
}
148144

149-
return null;
145+
return this.Repo.Commit($"Add/write {relativeFilePath} set to {version ?? "Inherited"}", this.Signer, this.Signer, new CommitOptions { AllowEmptyCommit = true });
150146
}
147+
148+
return null;
151149
}
152150
}

0 commit comments

Comments
 (0)