Skip to content

Commit

Permalink
remove sync methods
Browse files Browse the repository at this point in the history
  • Loading branch information
aspriddell committed Jan 19, 2023
1 parent 44ceab7 commit 9f336fe
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 96 deletions.
80 changes: 0 additions & 80 deletions src/ApiClient_Sync.cs

This file was deleted.

9 changes: 5 additions & 4 deletions tests/Header/HeaderLevelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License. Please refer to the LICENSE file at the root of this project for details

using System;
using System.Threading.Tasks;
using DragonFruit.Data.Extensions;
using DragonFruit.Data.Tests.Requests;
using Newtonsoft.Json.Linq;
Expand All @@ -19,7 +20,7 @@ public class HeaderLevelTests : ApiTest
/// Test whether request-headers and default headers are sent together successfully
/// </summary>
[TestCase]
public void LevelSpecificHeaderTest()
public async Task LevelSpecificHeaderTest()
{
var request = new EchoRequest();

Expand All @@ -29,7 +30,7 @@ public void LevelSpecificHeaderTest()
Client.Headers[GlobalHeaderName] = globalHeaderValue;
request.WithHeader(HeaderName, requestHeaderValue);

var response = Client.Perform<JObject>(request);
var response = await Client.PerformAsync<JObject>(request);
Assert.AreEqual(requestHeaderValue, (string)response["headers"]![HeaderName]);
Assert.AreEqual(globalHeaderValue, (string)response["headers"][GlobalHeaderName]);
}
Expand All @@ -39,7 +40,7 @@ public void LevelSpecificHeaderTest()
/// with the request header taking priority
/// </summary>
[TestCase]
public void LevelOverrideHeaderTest()
public async Task LevelOverrideHeaderTest()
{
var request = new EchoRequest();

Expand All @@ -49,7 +50,7 @@ public void LevelOverrideHeaderTest()
Client.Headers[GlobalHeaderName] = globalHeaderValue;
request.WithHeader(GlobalHeaderName, requestHeaderValue);

var response = Client.Perform<JObject>(request);
var response = await Client.PerformAsync<JObject>(request);
Assert.AreEqual(requestHeaderValue, (string)response["headers"]![GlobalHeaderName]);
}
}
Expand Down
14 changes: 7 additions & 7 deletions tests/Header/HeaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
// Licensed under the MIT License. Please refer to the LICENSE file at the root of this project for details

using System;
using System.Threading.Tasks;
using DragonFruit.Data.Extensions;
using DragonFruit.Data.Tests.Requests;
using Newtonsoft.Json.Linq;
using NUnit.Framework;

#pragma warning disable 1998

namespace DragonFruit.Data.Tests.Header
{
[TestFixture]
Expand All @@ -21,31 +20,32 @@ public class HeaderTests : ApiTest
/// Test whether client headers are sent and changed successfully
/// </summary>
[TestCase]
public void HeaderTest()
public async Task HeaderTest()
{
var headerValue = Rng.Next().ToString();
var request = new EchoRequest();

Client.Headers[HeaderName] = headerValue;
var response = Client.Perform<JObject>(request);
var response = await Client.PerformAsync<JObject>(request);
Assert.AreEqual(headerValue, (string)response["headers"][HeaderName]);

headerValue = Rng.Next().ToString();
Client.Headers[HeaderName] = headerValue;
response = Client.Perform<JObject>(request);

response = await Client.PerformAsync<JObject>(request);
Assert.AreEqual(headerValue, (string)response["headers"][HeaderName]);
}

/// <summary>
/// Test whether a header sent in a request is recieved successfully
/// </summary>
[TestCase]
public void PerRequestHeaderTest()
public async Task PerRequestHeaderTest()
{
var headerValue = Rng.Next().ToString();

var request = new EchoRequest().WithHeader(HeaderName, headerValue);
var response = Client.Perform<JObject>(request);
var response = await Client.PerformAsync<JObject>(request);

Assert.AreEqual((string)response["headers"]![HeaderName], headerValue);
}
Expand Down
5 changes: 3 additions & 2 deletions tests/Requests/FileRequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.IO;
using System.Threading.Tasks;
using DragonFruit.Data.Basic;
using NUnit.Framework;

Expand All @@ -12,7 +13,7 @@ namespace DragonFruit.Data.Tests.Requests
public class FileRequestTests : ApiTest
{
[TestCase("https://github.com/ppy/osu/archive/2020.1121.0.zip", 19018589)]
public void FileDownloadTest(string path, long expectedFileSize)
public async Task FileDownloadTest(string path, long expectedFileSize)
{
var request = new BasicApiFileRequest(path, Path.GetTempPath());

Expand All @@ -30,7 +31,7 @@ public void FileDownloadTest(string path, long expectedFileSize)

try
{
Client.Perform(request, (progress, total) => TestContext.Out.WriteLine($"Progress: {progress:n0}/{total:n0} ({Convert.ToSingle(progress) / Convert.ToSingle(total):F2}%)"));
await Client.PerformAsync(request, (progress, total) => TestContext.Out.WriteLine($"Progress: {progress:n0}/{total:n0} ({Convert.ToSingle(progress) / Convert.ToSingle(total):F2}%)"));

Assert.IsTrue(File.Exists(request.Destination));
Assert.GreaterOrEqual(new FileInfo(request.Destination).Length, expectedFileSize);
Expand Down
1 change: 0 additions & 1 deletion tests/Requests/RequestFilterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public class RequestFilterTests : ApiTest
[Test]
public void TestFilteredRequests()
{
Assert.Catch<AggregateException>(() => Client.Perform(new FilteredRequest()));
Assert.CatchAsync<ArgumentException>(() => Client.PerformAsync(new InheritedRequest()));
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Requests/RequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ public async Task TestBasicRequest()
}

[Test]
public void TestSyncHttp2Request()
public async Task TestHttp2Request()
{
var request = new HttpRequestMessage(HttpMethod.Get, "https://google.com") { Version = HttpVersion.Version20 };
using var result = Client.Perform(request);
using var result = await Client.PerformAsync(request);

Assert.IsTrue(result.IsSuccessStatusCode);
Assert.AreEqual(request.Version, result.Version);
Expand Down

0 comments on commit 9f336fe

Please sign in to comment.