-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathNameApiTest.cs
50 lines (44 loc) · 1.45 KB
/
NameApiTest.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
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Ipfs.Http
{
[TestClass]
public class NameApiTest
{
[TestMethod]
public void Api_Exists()
{
IpfsClient ipfs = TestFixture.Ipfs;
Assert.IsNotNull(ipfs.Name);
}
[TestMethod]
public async Task Resolve()
{
IpfsClient ipfs = TestFixture.Ipfs;
var id = await ipfs.Name.ResolveAsync("ipfs.io", recursive: true);
StringAssert.StartsWith(id, "/ipfs/");
}
[TestMethod]
public async Task Publish()
{
var ipfs = TestFixture.Ipfs;
var cs = new CancellationTokenSource(TimeSpan.FromMinutes(5));
var content = await ipfs.FileSystem.AddTextAsync("hello world");
var key = await ipfs.Key.CreateAsync("name-publish-test", "rsa", 2048);
try
{
var result = await ipfs.Name.PublishAsync(content.Id, key.Name, cancel: cs.Token);
Assert.IsNotNull(result);
StringAssert.EndsWith(result.NamePath, key.Id);
StringAssert.EndsWith(result.ContentPath, content.Id.Encode());
}
finally
{
await ipfs.Key.RemoveAsync(key.Name);
}
}
}
}