Skip to content

Commit e555332

Browse files
authored
Upgrade RestSharp from 106.15.0 to 114.0.0 (#235)
RestSharp 106.15.0 was released in 2021. We deferred the upgrade for so long that the dependency has since undergone a full architectural rewrite.
1 parent 97a5b3b commit e555332

47 files changed

Lines changed: 216 additions & 193 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/dnsimple-test/FixtureLoader.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Diagnostics;
55
using System.IO;
66
using System.Linq;
7-
using Castle.Core.Internal;
87
using Newtonsoft.Json;
98
using Newtonsoft.Json.Linq;
109
using RestSharp;
@@ -65,9 +64,9 @@ private string LoadFixture()
6564
return File.ReadAllText(path);
6665
}
6766

68-
public List<Parameter> ExtractHeaders()
67+
public List<HeaderParameter> ExtractHeaders()
6968
{
70-
var headers = new List<Parameter>();
69+
var headers = new List<HeaderParameter>();
7170

7271
foreach (var line in GetLines())
7372
{
@@ -76,7 +75,7 @@ public List<Parameter> ExtractHeaders()
7675
if (line.Contains(':'))
7776
{
7877
var header = line.Split(':');
79-
headers.Add(new Parameter(header[0], header[1], ParameterType.HttpHeader));
78+
headers.Add(new HeaderParameter(header[0], header[1]));
8079
}
8180
}
8281

src/dnsimple-test/MockDnsimpleClient.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using System.Net;
45
using dnsimple;
56
using dnsimple.Services;
67
using Newtonsoft.Json.Linq;
78
using RestSharp;
8-
using RestSharp.Extensions;
99
using ICredentials = dnsimple.ICredentials;
1010

1111
namespace dnsimple_test
@@ -82,7 +82,7 @@ public void SetUserAgent(string customUserAgent)
8282

8383
public string RequestSentTo()
8484
{
85-
return ((MockHttpService)Http).RequestUrlSent.UrlDecode();
85+
return Uri.UnescapeDataString(((MockHttpService)Http).RequestUrlSent);
8686
}
8787

8888
public Method HttpMethodUsed()
@@ -118,14 +118,16 @@ public override RequestBuilder RequestBuilder(string path)
118118
return new RequestBuilder(path);
119119
}
120120

121-
public override IRestResponse Execute(IRestRequest request)
121+
public override RestResponse Execute(RestRequest request)
122122
{
123-
RequestUrlSent = new RestClient($"{_baseUrl}/v2/").BuildUri(request).ToString();
123+
using var client = new RestClient(new Uri($"{_baseUrl}/v2/"));
124+
RequestUrlSent = client.BuildUri(request).ToString();
124125
MethodSent = request.Method;
125126
try
126127
{
127-
PayloadSent = (string)request.Parameters.Find(x =>
128-
x.ContentType.Equals("application/json")).Value;
128+
var bodyParameter = request.Parameters
129+
.FirstOrDefault(p => p.Type == ParameterType.RequestBody);
130+
PayloadSent = bodyParameter?.Value?.ToString();
129131
}
130132
catch (Exception)
131133
{
@@ -156,14 +158,16 @@ public override IRestResponse Execute(IRestRequest request)
156158

157159
public class MockResponse : RestResponse
158160
{
159-
public MockResponse(FixtureLoader loader)
161+
public MockResponse(FixtureLoader loader) : base(new RestRequest())
160162
{
161163
StatusCode = loader.ExtractStatusCode();
162164
Content = loader.ExtractJsonPayload();
163165
Headers = loader.ExtractHeaders();
166+
IsSuccessStatusCode = (int)StatusCode >= 200 && (int)StatusCode < 300;
167+
ResponseStatus = ResponseStatus.Completed;
164168
}
165169

166-
public void SetHeaders(List<Parameter> headers)
170+
public void SetHeaders(List<HeaderParameter> headers)
167171
{
168172
Headers = headers;
169173
}

src/dnsimple-test/Services/CertificatesTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ public void PurchaseLetsEncryptCertificate(long accountId,
346346
Assert.That(certificateOrdered.CreatedAt, Is.EqualTo(Convert.ToDateTime("2020-06-18T18:54:17Z")));
347347
Assert.That(certificateOrdered.UpdatedAt, Is.EqualTo(Convert.ToDateTime("2020-06-18T18:54:17Z")));
348348

349-
Assert.That(client.HttpMethodUsed(), Is.EqualTo(Method.POST));
349+
Assert.That(client.HttpMethodUsed(), Is.EqualTo(Method.Post));
350350
Assert.That(client.RequestSentTo(), Is.EqualTo(expectedUrl));
351351
});
352352
}
@@ -375,7 +375,7 @@ public void IssueLetsEncryptCertificate(long accountId,
375375
Assert.That(certificate.AlternateNames, Is.Empty);
376376
Assert.That(certificate.AuthorityIdentifier, Is.EqualTo("letsencrypt"));
377377

378-
Assert.That(client.HttpMethodUsed(), Is.EqualTo(Method.POST));
378+
Assert.That(client.HttpMethodUsed(), Is.EqualTo(Method.Post));
379379
Assert.That(client.RequestSentTo(), Is.EqualTo(expectedUrl));
380380
});
381381
}
@@ -407,7 +407,7 @@ public void PurchaseLetsEncryptCertificateRenewal(long accountId,
407407
Assert.That(renewalPurchased.CreatedAt, Is.EqualTo(Convert.ToDateTime("2020-06-18T19:56:20Z")));
408408
Assert.That(renewalPurchased.UpdatedAt, Is.EqualTo(Convert.ToDateTime("2020-06-18T19:56:20Z")));
409409

410-
Assert.That(client.HttpMethodUsed(), Is.EqualTo(Method.POST));
410+
Assert.That(client.HttpMethodUsed(), Is.EqualTo(Method.Post));
411411
Assert.That(client.RequestSentTo(), Is.EqualTo(expectedUrl));
412412
});
413413
}
@@ -440,7 +440,7 @@ public void IssueLetsEncryptCertificateRenewal(long accountId,
440440
Assert.That(renewalIssued.AlternateNames, Is.Empty);
441441
Assert.That(renewalIssued.AuthorityIdentifier, Is.EqualTo("letsencrypt"));
442442

443-
Assert.That(client.HttpMethodUsed(), Is.EqualTo(Method.POST));
443+
Assert.That(client.HttpMethodUsed(), Is.EqualTo(Method.Post));
444444
Assert.That(client.RequestSentTo(), Is.EqualTo(expectedUrl));
445445
});
446446
}

src/dnsimple-test/Services/ContactsTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public void CreateContact(long accountId, string expectedUrl)
142142
Assert.That(created.Email, Is.EqualTo(contact.Email));
143143

144144
Assert.That(client.RequestSentTo(), Is.EqualTo(expectedUrl));
145-
Assert.That(client.HttpMethodUsed(), Is.EqualTo(Method.POST));
145+
Assert.That(client.HttpMethodUsed(), Is.EqualTo(Method.Post));
146146
});
147147
}
148148

@@ -215,7 +215,7 @@ public void UpdateContact(long accountId, long contactId, string expectedUrl)
215215
Assert.That(updated.AccountId, Is.EqualTo(accountId));
216216

217217
Assert.That(client.RequestSentTo(), Is.EqualTo(expectedUrl));
218-
Assert.That(client.HttpMethodUsed(), Is.EqualTo(Method.PATCH));
218+
Assert.That(client.HttpMethodUsed(), Is.EqualTo(Method.Patch));
219219
});
220220
}
221221

@@ -233,7 +233,7 @@ public void DeleteContact(long accountId, long contactId, string expectedUrl)
233233
});
234234

235235
Assert.That(client.RequestSentTo(), Is.EqualTo(expectedUrl));
236-
Assert.That(client.HttpMethodUsed(), Is.EqualTo(Method.DELETE));
236+
Assert.That(client.HttpMethodUsed(), Is.EqualTo(Method.Delete));
237237
});
238238
}
239239

src/dnsimple-test/Services/HttpTest.cs

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using dnsimple;
66
using dnsimple.Services;
77
using dnsimple.Services.ListOptions;
8-
using Moq;
98
using Newtonsoft.Json;
109
using Newtonsoft.Json.Linq;
1110
using NUnit.Framework;
@@ -19,31 +18,23 @@ public class HttpTest
1918
[Test]
2019
public void ReturnsARequestBuilder()
2120
{
22-
var http = new HttpService(new RestClient(), new RequestBuilder());
21+
var http = new HttpService(new RestClientWrapper(), new RequestBuilder());
2322
Assert.That(http.RequestBuilder(""), Is.InstanceOf<RequestBuilder>());
24-
2523
}
2624

2725
[Test]
2826
public void InvalidRequest()
2927
{
30-
var client = new Mock<IRestClient>();
31-
var response = new Mock<IRestResponse>();
32-
var request = new Mock<IRestRequest>();
33-
var http = new HttpService(client.Object, new RequestBuilder());
34-
35-
response.SetupProperty(mock => mock.StatusCode,
36-
HttpStatusCode.Unauthorized);
37-
response.Setup(mock => mock.IsSuccessful).Returns(false);
38-
response.Setup(mock => mock.Content)
39-
.Returns("{\"message\": \"Authentication failed\"}");
40-
41-
client.Setup(mock => mock.Execute(request.Object))
42-
.Returns(response.Object);
28+
var response = new RestResponse(new RestRequest())
29+
{
30+
StatusCode = HttpStatusCode.Unauthorized,
31+
Content = "{\"message\": \"Authentication failed\"}",
32+
ResponseStatus = ResponseStatus.Completed,
33+
};
4334

4435
Assert.Throws(Is.TypeOf<AuthenticationException>()
4536
.And.Message.EqualTo("Authentication failed"),
46-
delegate { http.Execute(request.Object); });
37+
delegate { HttpService.HandleExceptions(response); });
4738
}
4839

4940
[Test]
@@ -144,18 +135,18 @@ public void BuildsRequestWithPath()
144135
[Test]
145136
public void Resets()
146137
{
147-
_builder.Method(Method.HEAD);
138+
_builder.Method(Method.Head);
148139

149140
Assert.That(_builder.Reset().Request, Is.Null);
150141
}
151142

152143
[Test]
153144
public void SetsTheMethod()
154145
{
155-
_builder.Method(Method.POST);
146+
_builder.Method(Method.Post);
156147
var request = _builder.Request;
157148

158-
Assert.That(request.Method, Is.EqualTo(Method.POST));
149+
Assert.That(request.Method, Is.EqualTo(Method.Post));
159150
}
160151

161152
[Test]

src/dnsimple-test/Services/OAuth2Test.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ public class OAuth2Test
1515
private static void SetupMockHttpService(Mock<HttpService> http,
1616
IMock<RestResponse> mockRestResponse)
1717
{
18-
var response = new RestResponse();
19-
response.Content = mockRestResponse.Object.Content;
18+
var response = new RestResponse(new RestRequest())
19+
{
20+
Content = mockRestResponse.Object.Content,
21+
};
2022
http.Setup(mock =>
2123
mock.RequestBuilder(It.IsAny<string>()))
2224
.Returns(new RequestBuilder(""));
@@ -31,8 +33,8 @@ private static void SetupMockHttpService(Mock<HttpService> http,
3133
[Test]
3234
public void ExchangeAuthorizationForToken()
3335
{
34-
var http = new Mock<HttpService>(new RestClient(), new RequestBuilder());
35-
var mockRestResponse = new Mock<RestResponse>();
36+
var http = new Mock<HttpService>(new RestClientWrapper(), new RequestBuilder());
37+
var mockRestResponse = new Mock<RestResponse>(new RestRequest());
3638
var oauthService = new OAuth2Service(http.Object);
3739

3840
mockRestResponse.Object.Content =

src/dnsimple-test/Services/RegistrarAutoRenewalTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public void EnableDomainAutoRenewal(long accountId, string domain, string expect
2727
client.Registrar.EnableDomainAutoRenewal(accountId, domain);
2828
});
2929
Assert.That(client.RequestSentTo(), Is.EqualTo(expectedUrl));
30-
Assert.That(client.HttpMethodUsed(), Is.EqualTo(Method.PUT));
30+
Assert.That(client.HttpMethodUsed(), Is.EqualTo(Method.Put));
3131
});
3232
}
3333

@@ -45,7 +45,7 @@ public void DisableDomainAutoRenewal(long accountId, string domain, string expec
4545
client.Registrar.DisableDomainAutoRenewal(accountId, domain);
4646
});
4747
Assert.That(client.RequestSentTo(), Is.EqualTo(expectedUrl));
48-
Assert.That(client.HttpMethodUsed(), Is.EqualTo(Method.DELETE));
48+
Assert.That(client.HttpMethodUsed(), Is.EqualTo(Method.Delete));
4949
});
5050
}
5151
}

src/dnsimple-test/Services/RegistrarDelegationTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public void ChangeDomainDelegation(long accountId, string domain,
9999
Assert.That(newDelegation.Data, Is.EqualTo(delegation));
100100

101101
Assert.That(client.RequestSentTo(), Is.EqualTo(expectedUrl));
102-
Assert.That(client.HttpMethodUsed(), Is.EqualTo(Method.PUT));
102+
Assert.That(client.HttpMethodUsed(), Is.EqualTo(Method.Put));
103103
});
104104
}
105105

@@ -130,7 +130,7 @@ public void ChangeDomainDelegationToVanity(long accountId, string domain, string
130130
Assert.That(vanityDelegation.First().UpdatedAt, Is.EqualTo(UpdatedAt));
131131

132132
Assert.That(client.RequestSentTo(), Is.EqualTo(expectedUrl));
133-
Assert.That(client.HttpMethodUsed(), Is.EqualTo(Method.PUT));
133+
Assert.That(client.HttpMethodUsed(), Is.EqualTo(Method.Put));
134134
});
135135
}
136136

@@ -150,7 +150,7 @@ public void ChangeDomainDelegationFromVanity(long accountId, string domain, stri
150150
});
151151

152152
Assert.That(client.RequestSentTo(), Is.EqualTo(expectedUrl));
153-
Assert.That(client.HttpMethodUsed(), Is.EqualTo(Method.DELETE));
153+
Assert.That(client.HttpMethodUsed(), Is.EqualTo(Method.Delete));
154154
});
155155
}
156156
}

src/dnsimple-test/Services/RegistrarTransferLockTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void EnableDomainTransferLock(long accountId, string domain, string expec
2929
Assert.That(transferLockStatus.Enabled, Is.True);
3030

3131
Assert.That(client.RequestSentTo(), Is.EqualTo(expectedUrl));
32-
Assert.That(client.HttpMethodUsed(), Is.EqualTo(Method.POST));
32+
Assert.That(client.HttpMethodUsed(), Is.EqualTo(Method.Post));
3333
});
3434
}
3535

@@ -46,7 +46,7 @@ public void DisableDomainTransferLock(long accountId, string domain, string expe
4646
Assert.That(transferLockStatus.Enabled, Is.False);
4747

4848
Assert.That(client.RequestSentTo(), Is.EqualTo(expectedUrl));
49-
Assert.That(client.HttpMethodUsed(), Is.EqualTo(Method.DELETE));
49+
Assert.That(client.HttpMethodUsed(), Is.EqualTo(Method.Delete));
5050
});
5151
}
5252

@@ -62,7 +62,7 @@ public void GetDomainTransferLock(long accountId, string domain, string expected
6262
Assert.That(transferLockStatus.Enabled, Is.True);
6363

6464
Assert.That(client.RequestSentTo(), Is.EqualTo(expectedUrl));
65-
Assert.That(client.HttpMethodUsed(), Is.EqualTo(Method.GET));
65+
Assert.That(client.HttpMethodUsed(), Is.EqualTo(Method.Get));
6666
});
6767
}
6868
}

src/dnsimple-test/Services/RegistrarWhoisPrivacyTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public void EnableWhoisPrivacy(long accountId, string domain, string expectedUrl
3232
Assert.That(privacy.Enabled, Is.True);
3333

3434
Assert.That(client.RequestSentTo(), Is.EqualTo(expectedUrl));
35-
Assert.That(client.HttpMethodUsed(), Is.EqualTo(Method.PUT));
35+
Assert.That(client.HttpMethodUsed(), Is.EqualTo(Method.Put));
3636
});
3737
}
3838

@@ -51,7 +51,7 @@ public void PurchaseAndEnableWhoisPrivacy(long accountId, string domain, string
5151
Assert.That(privacy.Enabled, Is.Null);
5252

5353
Assert.That(client.RequestSentTo(), Is.EqualTo(expectedUrl));
54-
Assert.That(client.HttpMethodUsed(), Is.EqualTo(Method.PUT));
54+
Assert.That(client.HttpMethodUsed(), Is.EqualTo(Method.Put));
5555
});
5656
}
5757

@@ -70,7 +70,7 @@ public void DisableWhoisPrivacy(long accountId, string domain, string expectedUr
7070
Assert.That(privacy.Enabled, Is.False);
7171

7272
Assert.That(client.RequestSentTo(), Is.EqualTo(expectedUrl));
73-
Assert.That(client.HttpMethodUsed(), Is.EqualTo(Method.DELETE));
73+
Assert.That(client.HttpMethodUsed(), Is.EqualTo(Method.Delete));
7474
});
7575
}
7676
}

0 commit comments

Comments
 (0)