Skip to content

Commit 9731101

Browse files
feat(ConfigApi): implement Config.Replace #43
1 parent 0ec2e62 commit 9731101

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

src/CoreApi/ConfigApi.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ internal ConfigApi(IpfsClient ipfs)
4848
return;
4949
}
5050

51-
public Task ReplaceAsync(JObject config)
51+
public async Task ReplaceAsync(JObject config)
5252
{
53-
throw new NotImplementedException();
53+
var data = Encoding.UTF8.GetBytes(config.ToString(Formatting.None));
54+
await ipfs.UploadAsync("config/replace", CancellationToken.None, data);
5455
}
5556
}
5657

src/IpfsApi.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
</PropertyGroup>
2828

2929
<ItemGroup>
30-
<PackageReference Include="Ipfs.Core" Version="0.34.0" />
30+
<PackageReference Include="Ipfs.Core" Version="0.34.1" />
3131
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
3232
<PackageReference Include="System.Net.Http" Version="4.3.3" Condition="'$(TargetFramework)' == 'netstandard14'" />
3333
<PackageReference Include="System.Net.Http" Version="4.3.3" Condition="'$(TargetFramework)' == 'net45'" />

test/CoreApi/ConfigApiTest.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Newtonsoft.Json.Linq;
44
using System;
55
using System.Text;
6+
using System.Threading.Tasks;
67

78
namespace Ipfs.Api
89
{
@@ -68,5 +69,21 @@ public void Set_JSON_Value()
6869
Assert.AreEqual("http://example.io", ipfs.Config.GetAsync(key).Result[0]);
6970
}
7071

72+
[TestMethod]
73+
public async Task Replace_Entire_Config()
74+
{
75+
IpfsClient ipfs = TestFixture.Ipfs;
76+
var original = await ipfs.Config.GetAsync();
77+
try
78+
{
79+
var a = JObject.Parse("{ \"foo-x-bar\": 1 }");
80+
await ipfs.Config.ReplaceAsync(a);
81+
}
82+
finally
83+
{
84+
await ipfs.Config.ReplaceAsync(original);
85+
}
86+
}
87+
7188
}
7289
}

0 commit comments

Comments
 (0)