/
TreeFixture.cs
executable file
·146 lines (130 loc) · 4.27 KB
/
TreeFixture.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
using System.Linq;
using LibGit2Sharp.Tests.TestHelpers;
using NUnit.Framework;
namespace LibGit2Sharp.Tests
{
[TestFixture]
public class TreeFixture : BaseFixture
{
private const string sha = "581f9824ecaf824221bd36edf5430f2739a7c4f5";
[Test]
public void CanCompareTwoTreeEntries()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
{
var tree = repo.Lookup<Tree>(sha);
TreeEntry treeEntry1 = tree["README"];
TreeEntry treeEntry2 = tree["README"];
treeEntry1.ShouldEqual(treeEntry2);
(treeEntry1 == treeEntry2).ShouldBeTrue();
}
}
[Test]
public void CanConvertEntryToBlob()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
{
var tree = repo.Lookup<Tree>(sha);
TreeEntry treeEntry = tree["README"];
var blob = treeEntry.Target as Blob;
blob.ShouldNotBeNull();
}
}
[Test]
public void CanConvertEntryToTree()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
{
var tree = repo.Lookup<Tree>(sha);
TreeEntry treeEntry = tree["1"];
var subtree = treeEntry.Target as Tree;
subtree.ShouldNotBeNull();
}
}
[Test]
public void CanEnumerateBlobs()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
{
var tree = repo.Lookup<Tree>(sha);
tree.Files.Count().ShouldEqual(3);
}
}
[Test]
public void CanEnumerateSubTrees()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
{
var tree = repo.Lookup<Tree>(sha);
tree.Trees.Count().ShouldEqual(1);
}
}
[Test]
public void CanEnumerateTreeEntries()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
{
var tree = repo.Lookup<Tree>(sha);
tree.Count().ShouldEqual(tree.Count);
CollectionAssert.AreEqual(new[] { "1", "README", "branch_file.txt", "new.txt" }, tree.Select(te => te.Name).ToArray());
}
}
[Test]
public void CanGetEntryByName()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
{
var tree = repo.Lookup<Tree>(sha);
TreeEntry treeEntry = tree["README"];
treeEntry.Target.Sha.ShouldEqual("a8233120f6ad708f843d861ce2b7228ec4e3dec6");
treeEntry.Name.ShouldEqual("README");
}
}
[Test]
public void GettingAnUknownTreeEntryReturnsNull()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
{
var tree = repo.Lookup<Tree>(sha);
TreeEntry treeEntry = tree["I-do-not-exist"];
treeEntry.ShouldBeNull();
}
}
[Test]
public void CanGetEntryCountFromTree()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
{
var tree = repo.Lookup<Tree>(sha);
tree.Count.ShouldEqual(4);
}
}
[Test]
public void CanReadEntryAttributes()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
{
var tree = repo.Lookup<Tree>(sha);
tree["README"].Attributes.ShouldEqual(33188);
}
}
[Test]
public void CanReadTheTreeData()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
{
var tree = repo.Lookup<Tree>(sha);
tree.ShouldNotBeNull();
}
}
[Test]
public void TreeDataIsPresent()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
{
GitObject tree = repo.Lookup(sha);
tree.ShouldNotBeNull();
}
}
}
}