8000 Set up the test environment in a Fixture base class · joncham/libgit2sharp@c35f177 · GitHub
[go: up one dir, main page]

Skip to content

Commit c35f177

Browse files
davidebbonulltoken
authored andcommitted
Set up the test environment in a Fixture base class
1 parent 1828200 commit c35f177

10 files changed

+45
-31
lines changed

LibGit2Sharp.Tests/BaseFixture.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.IO;
2+
using LibGit2Sharp.Tests.TestHelpers;
3+
4+
namespace LibGit2Sharp.Tests
5+
{
6+
public class BaseFixture
7+
{
8+
static BaseFixture()
9+
{
10+
// Do the set up in the static ctor so it only happens once
11+
SetUpTestEnvironment();
12+
}
13+
14+
private static void SetUpTestEnvironment()
15+
{
16+
var source = new DirectoryInfo(@"..\..\..\Resources");
17+
var target = new DirectoryInfo(@"Resources");
18+
19+
if (target.Exists)
20+
{
21+
target.Delete(recursive: true);
22+
}
23+
24+
DirectoryHelper.CopyFilesRecursively(source, target);
25+
26+
// The test repo under source control has its .git folder renamed to dot_git to avoid confusing git,
27+
// so we need to rename it back to .git in our copy under the target folder
28+
29+
string tempDotGit = Path.Combine(Constants.TestRepoWithWorkingDirRootPath, "dot_git");
30+
Directory.Move(tempDotGit, Constants.TestRepoWithWorkingDirPath);
31+
}
32+
}
33+
}

LibGit2Sharp.Tests/BlobFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace LibGit2Sharp.Tests
77
{
88
[TestFixture]
9-
public class BlobFixture
9+
public class BlobFixture : BaseFixture
1010
{
1111
[Test]
1212
public void CanGetBlobAsUtf8()

LibGit2Sharp.Tests/BranchFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace LibGit2Sharp.Tests
88
{
99
[TestFixture]
10-
public class BranchFixture
10+
public class BranchFixture : BaseFixture
1111
{
1212
private readonly List<string> expectedBranches = new List<string> {"packed-test", "packed", "br2", "master", "test", "deadbeef"};
1313

LibGit2Sharp.Tests/CommitFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace LibGit2Sharp.Tests
1010
{
1111
[TestFixture]
12-
public class CommitFixture
12+
public class CommitFixture : BaseFixture
1313
{
1414
private const string sha = "8496071c1b46c854b31185ea97743be6a8774479";
1515
private readonly List<string> expectedShas = new List<string> {"a4a7d", "c4780", "9fd73", "4a202", "5b5b0", "84960"};

LibGit2Sharp.Tests/IndexFixture.cs

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace LibGit2Sharp.Tests
88
{
99
[TestFixture]
10-
public class IndexFixture
10+
public class IndexFixture : BaseFixture
1111
{
1212
private readonly List<string> expectedEntries = new List<string>
1313
{
@@ -22,27 +22,6 @@ public class IndexFixture
2222
"new_tracked_file.txt"
2323
};
2424

25-
[TestFixtureSetUp]
26-
public void Setup()
27-
{
28-
const string tempDotGit = "./Resources/testrepo_wd/dot_git";
29-
30-
bool gitRepoExists = Directory.Exists(Constants.TestRepoWithWorkingDirPath);
31-
bool dotGitDirExists = Directory.Exists(tempDotGit);
32-
33-
if (gitRepoExists)
34-
{
35-
if (dotGitDirExists)
36-
{
37-
DirectoryHelper.DeleteDirectory(tempDotGit);
38-
}
39-
40-
return;
41-
}
42-
43-
Directory.Move(tempDotGit, Constants.TestRepoWithWorkingDirPath);
44-
}
45-
4625
[Test]
4726
public void CanCountEntriesInIndex()
4827
{
@@ -193,7 +172,7 @@ public void CanUnstageANewFile()
193172
const string filename = "new_untracked_file.txt";
194173
string fullPath = Path.Combine(repo.Info.WorkingDirectory, filename);
195174
File.Exists(fullPath).ShouldBeTrue();
196-
175+
197176
repo.Index.Stage(filename);
198177
repo.Index.Count.ShouldEqual(count + 1);
199178

LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
<Reference Include="System.Core" />
4343
</ItemGroup>
4444
<ItemGroup>
45+
<Compile Include="BaseFixture.cs" />
4546
<Compile Include="BlobFixture.cs" />
4647
<Compile Include="BranchFixture.cs" />
4748
<Compile Include="CommitFixture.cs" />
@@ -67,7 +68,8 @@
6768
</ItemGroup>
6869
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
6970
<PropertyGroup>
70-
<PreBuildEvent>xcopy "$(SolutionDir)Resources\*.*" "$(TargetDir)Resources" /E /I /Y /F /H &gt; NUL</PreBuildEvent>
71+
<PreBuildEvent>
72+
</PreBuildEvent>
7173
</PropertyGroup>
7274
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
7375
Other similar extension points exist, see Microsoft.Common.targets.

LibGit2Sharp.Tests/ReferenceFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace LibGit2Sharp.Tests
88
{
99
[TestFixture]
10-
public class ReferenceFixture
10+
public class ReferenceFixture : BaseFixture
1111
{
1212
private readonly List<string> expectedRefs = new List<string> { "refs/heads/packed-test", "refs/heads/packed", "refs/heads/br2", "refs/heads/master", "refs/heads/test",
1313
"refs/heads/deadbeef", "refs/tags/test", "refs/tags/e90810b", "refs/tags/lw" };

LibGit2Sharp.Tests/RepositoryFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace LibGit2Sharp.Tests
88
{
99
[TestFixture]
10-
public class RepositoryFixture
10+
public class RepositoryFixture : BaseFixture
1111
{
1212
private const string commitSha = "8496071c1b46c854b31185ea97743be6a8774479";
1313

LibGit2Sharp.Tests/TagFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace LibGit2Sharp.Tests
99
{
1010
[TestFixture]
11-
public class TagFixture
11+
public class TagFixture : BaseFixture
1212
{
1313
private readonly List<string> expectedTags = new List<string> {"test", "e90810b", "lw"};
1414

LibGit2Sharp.Tests/TreeFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace LibGit2Sharp.Tests
66
{
77
[TestFixture]
8-
public class TreeFixture
8+
public class TreeFixture : BaseFixture
99
{
1010
private const string sha = "581f9824ecaf824221bd36edf5430f2739a7c4f5";
1111

0 commit comments

Comments
 (0)
0