blob: 724c5d8e4cacb89341798acaa0acc6e82c47c23a (
plain)
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
|
using System.IO;
using System.Text;
using LibGit2Sharp.Tests.TestHelpers;
using NUnit.Framework;
namespace LibGit2Sharp.Tests
{
[TestFixture]
public class BlobFixture : BaseFixture
{
[Test]
public void CanGetBlobAsUtf8()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
{
var blob = repo.Lookup<Blob>("a8233120f6ad708f843d861ce2b7228ec4e3dec6");
var text = blob.ContentAsUtf8();
text.ShouldEqual("hey there\n");
}
}
[Test]
public void CanGetBlobSize()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
{
var blob = repo.Lookup<Blob>("a8233120f6ad708f843d861ce2b7228ec4e3dec6");
blob.Size.ShouldEqual(10);
}
}
[Test]
public void CanLookUpBlob()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
{
var blob = repo.Lookup<Blob>("a8233120f6ad708f843d861ce2b7228ec4e3dec6");
blob.ShouldNotBeNull();
}
}
[Test]
public void CanReadBlobContent()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
{
var blob = repo.Lookup<Blob>("a8233120f6ad708f843d861ce2b7228ec4e3dec6");
var bytes = blob.Content;
bytes.Length.ShouldEqual(10);
var content = Encoding.UTF8.GetString(bytes);
content.ShouldEqual("hey there\n");
}
}
[Test]
public void CanReadBlobStream()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
{
var blob = repo.Lookup<Blob>("a8233120f6ad708f843d861ce2b7228ec4e3dec6");
using (var tr = new StreamReader(blob.ContentStream, Encoding.UTF8))
{
var content = tr.ReadToEnd();
content.ShouldEqual("hey there\n");
}
}
}
}
}
|