-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(DagApi): implement the interface #30
- Loading branch information
1 parent
09073eb
commit 76ef63e
Showing
3 changed files
with
125 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,53 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Newtonsoft.Json.Linq; | ||
using System; | ||
using System.Text; | ||
|
||
namespace Ipfs.Api | ||
{ | ||
[TestClass] | ||
public class DagApiTest | ||
{ | ||
[TestMethod] | ||
public void GetAsync() | ||
{ | ||
var ipfs = TestFixture.Ipfs; | ||
ExceptionAssert.Throws<NotImplementedException>(() => ipfs.Dag.GetAsync("cid")); | ||
} | ||
|
||
[TestMethod] | ||
public void PutAsync() | ||
{ | ||
var ipfs = TestFixture.Ipfs; | ||
ExceptionAssert.Throws<NotImplementedException>(() => ipfs.Dag.PutAsync(null, null)); | ||
} | ||
|
||
} | ||
} | ||
|
||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Newtonsoft.Json.Linq; | ||
using System; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Ipfs.Api | ||
{ | ||
[TestClass] | ||
public class DagApiTest | ||
{ | ||
class Name | ||
{ | ||
public string First { get; set; } | ||
public string Last { get; set; } | ||
} | ||
|
||
[TestMethod] | ||
public async Task PutAndGet_JSON() | ||
{ | ||
var ipfs = TestFixture.Ipfs; | ||
var expected = new JObject(); | ||
expected["a"] = "alpha"; | ||
var id = await ipfs.Dag.PutAsync(expected); | ||
Assert.IsNotNull(id); | ||
|
||
var actual = await ipfs.Dag.GetAsync(id); | ||
Assert.IsNotNull(actual); | ||
Assert.AreEqual(expected["a"], actual["a"]); | ||
|
||
var value = (string) await ipfs.Dag.GetAsync(id.Encode() + "/a"); | ||
Assert.AreEqual(expected["a"], value); | ||
} | ||
|
||
[TestMethod] | ||
public async Task PutAndGet_POCO() | ||
{ | ||
var ipfs = TestFixture.Ipfs; | ||
var expected = new Name { First = "John", Last = "Smith" }; | ||
var id = await ipfs.Dag.PutAsync(expected); | ||
Assert.IsNotNull(id); | ||
|
||
var actual = await ipfs.Dag.GetAsync<Name>(id); | ||
Assert.IsNotNull(actual); | ||
Assert.AreEqual(expected.First, actual.First); | ||
Assert.AreEqual(expected.Last, actual.Last); | ||
|
||
var value = (string)await ipfs.Dag.GetAsync(id.Encode() + "/Last"); | ||
Assert.AreEqual(expected.Last, value); | ||
} | ||
} | ||
} | ||
|