Prefer specifying exact status code instead of using "IsSuccess"
MODIFY
MagicalCryptoWallet.Tests/ExternalApiTests.cs
MagicalCryptoWallet.Tests/ExternalApiTests.cs
@@ -7,6 +7,7 @@ using NBitcoin;
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading;
@@ -98,7 +99,7 @@ namespace MagicalCryptoWallet.Tests
using (var client = new HttpClient())
using (var res = await client.GetAsync(uri))
{
- if (res.IsSuccessStatusCode)
+ if (res.StatusCode == HttpStatusCode.OK)
{
return true;
}

MODIFY
MagicalCryptoWallet.Tests/RegTests.cs
MagicalCryptoWallet.Tests/RegTests.cs
@@ -71,7 +71,7 @@ namespace MagicalCryptoWallet.Tests
using (var client = new TorHttpClient(new Uri(RegTestFixture.BackendEndPoint)))
using (var response = await client.SendAsync(HttpMethod.Get, "/api/v1/btc/Blockchain/exchange-rates"))
{
- Assert.True(response.IsSuccessStatusCode);
+ Assert.True(response.StatusCode == HttpStatusCode.OK);
var exchangeRates = await response.Content.ReadAsJsonAsync<List<ExchangeRate>>();
Assert.Single(exchangeRates);
@@ -99,7 +99,7 @@ namespace MagicalCryptoWallet.Tests
using (var response = await client.SendAsync(HttpMethod.Post, "/api/v1/btc/Blockchain/broadcast", content))
{
- Assert.False(response.IsSuccessStatusCode);
+ Assert.NotEqual(HttpStatusCode.OK, response.StatusCode);
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
}
}
@@ -115,7 +115,7 @@ namespace MagicalCryptoWallet.Tests
using (var client = new TorHttpClient(new Uri(RegTestFixture.BackendEndPoint)))
using (var response = await client.SendAsync(HttpMethod.Post, "/api/v1/btc/Blockchain/broadcast", content))
{
- Assert.True(response.IsSuccessStatusCode);
+ Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal("\"Transaction is already in the blockchain.\"", await response.Content.ReadAsStringAsync());
}
}
@@ -127,7 +127,7 @@ namespace MagicalCryptoWallet.Tests
using (var client = new TorHttpClient(new Uri(RegTestFixture.BackendEndPoint)))
using (var response = await client.SendAsync(HttpMethod.Post, "/api/v1/btc/Blockchain/broadcast", content))
{
- Assert.False(response.IsSuccessStatusCode);
+ Assert.NotEqual(HttpStatusCode.OK, response.StatusCode);
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
Assert.Equal("\"Invalid hex.\"", await response.Content.ReadAsStringAsync());
}
@@ -1028,7 +1028,7 @@ namespace MagicalCryptoWallet.Tests
await Assert.ThrowsAsync<ArgumentNullException>(async () => await wallet.BuildTransactionAsync(null, null, 0));
// toSend cannot have a null element
- await Assert.ThrowsAsync<ArgumentException>(async () => await wallet.BuildTransactionAsync(null, new[] { (WalletService.Operation)null }, 0));
+ await Assert.ThrowsAsync<ArgumentNullException>(async () => await wallet.BuildTransactionAsync(null, new[] { (WalletService.Operation)null }, 0));
// toSend cannot have a zero elements
await Assert.ThrowsAsync<ArgumentException>(async () => await wallet.BuildTransactionAsync(null, new WalletService.Operation[0], 0));

MODIFY
MagicalCryptoWallet/Extensions/TorHttpClientExtensions.cs
MagicalCryptoWallet/Extensions/TorHttpClientExtensions.cs
+using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using MagicalCryptoWallet.TorSocks5;
@@ -11,7 +12,7 @@ public static class TorHttpClientExtensions
while(retry-- > 0)
{
response = await client.SendAsync(method, relativeUri, content);
- if(response.IsSuccessStatusCode)
+ if(response.StatusCode == HttpStatusCode.OK)
{
break;
}

MODIFY
MagicalCryptoWallet/Services/WalletService.cs
MagicalCryptoWallet/Services/WalletService.cs
@@ -543,7 +543,7 @@ namespace MagicalCryptoWallet.Services
using (var torClient = new TorHttpClient(IndexDownloader.Client.DestinationUri, IndexDownloader.Client.TorSocks5EndPoint, isolateStream: true))
using (var response = await torClient.SendAndRetryAsync(HttpMethod.Get, $"/api/v1/btc/blockchain/fees/{feeTarget}"))
{
- if (!response.IsSuccessStatusCode)
+ if (response.StatusCode != HttpStatusCode.OK)
throw new HttpRequestException($"Couldn't query network fees. Reason: {response.StatusCode.ToReasonString()}");
using (var content = response.Content)

MODIFY
MagicalCryptoWallet/WebClients/BlockCypher/BlockCypherClient.cs
MagicalCryptoWallet/WebClients/BlockCypher/BlockCypherClient.cs
@@ -6,6 +6,7 @@ using Nito.AsyncEx;
using System;
using System.Collections.Generic;
using System.Globalization;
+using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading;
@@ -48,7 +49,7 @@ namespace MagicalCryptoWallet.WebClients.BlockCypher
using (HttpResponseMessage response =
await HttpClient.GetAsync("", HttpCompletionOption.ResponseContentRead, cancel))
{
- if (!response.IsSuccessStatusCode) throw new HttpRequestException(response.StatusCode.ToString());
+ if (response.StatusCode != HttpStatusCode.OK) throw new HttpRequestException(response.StatusCode.ToString());
string jsonString = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<BlockCypherGeneralInformation>(jsonString);

MODIFY
MagicalCryptoWallet/WebClients/SmartBit/SmartBitClient.cs
MagicalCryptoWallet/WebClients/SmartBit/SmartBitClient.cs
@@ -5,6 +5,7 @@ using Newtonsoft.Json.Linq;
using Nito.AsyncEx;
using System;
using System.Collections.Generic;
+using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading;
@@ -53,7 +54,7 @@ namespace MagicalCryptoWallet.WebClients.SmartBit
HttpResponseMessage response =
await HttpClient.PostAsync("blockchain/pushtx", content, cancel);
- if (!response.IsSuccessStatusCode) throw new HttpRequestException(response.StatusCode.ToString());
+ if (response.StatusCode != HttpStatusCode.OK) throw new HttpRequestException(response.StatusCode.ToString());
string responseString = await response.Content.ReadAsStringAsync();
AssertSuccess(responseString);
}
@@ -66,7 +67,7 @@ namespace MagicalCryptoWallet.WebClients.SmartBit
await HttpClient.GetAsync("exchange-rates", HttpCompletionOption.ResponseContentRead, cancel))
{
- if (!response.IsSuccessStatusCode) throw new HttpRequestException(response.StatusCode.ToString());
+ if (response.StatusCode != HttpStatusCode.OK) throw new HttpRequestException(response.StatusCode.ToString());
string responseString = await response.Content.ReadAsStringAsync();
AssertSuccess(responseString);

Prefer specifying exact status code instead of using "IsSuccess"