Refactor HTTP json response extension
MODIFY
MagicalCryptoWallet.Tests/RegTests.cs
MagicalCryptoWallet.Tests/RegTests.cs
@@ -66,8 +66,8 @@ namespace MagicalCryptoWallet.Tests
using (var client = new HttpClient() { BaseAddress = new Uri(Fixture.BackendEndPoint) })
using (var request = await client.GetAsync("/api/v1/btc/Blockchain/filters/" + firstHash))
{
- var content = await request.Content.ReadAsStringAsync();
- var filterCount = content.Split(',').Count();
+ var filters = await request.Content.ReadAsJsonAsync<List<string>>();
+ var filterCount = filters.Count();
if (filterCount >= 101)
{
break;
@@ -88,7 +88,7 @@ namespace MagicalCryptoWallet.Tests
{
Assert.True(res.IsSuccessStatusCode);
- var exchangeRates = await res.ReadAsAsync<List<ExchangeRate>>();
+ var exchangeRates = await res.Content.ReadAsJsonAsync<List<ExchangeRate>>();
Assert.Single(exchangeRates);
var rate = exchangeRates[0];
@@ -146,13 +146,4 @@ namespace MagicalCryptoWallet.Tests
}
}
}
-
- static class HttpResponseMessageExtensions
- {
- public static async Task<T> ReadAsAsync<T>(this HttpResponseMessage me)
- {
- var jsonString = await me.Content.ReadAsStringAsync();
- return JsonConvert.DeserializeObject<T>(jsonString);
- }
- }
}

Refactor HTTP json response extension