diff --git a/ShopifySharp.Tests/ExecuteRequestCancellation_Tests.cs b/ShopifySharp.Tests/ExecuteRequestCancellation_Tests.cs index 4b38df7d..ab3d2760 100644 --- a/ShopifySharp.Tests/ExecuteRequestCancellation_Tests.cs +++ b/ShopifySharp.Tests/ExecuteRequestCancellation_Tests.cs @@ -15,43 +15,57 @@ public class ExecuteRequestCancellation_Tests { private class TestService : ShopifyService { - public TestService() : base("someurl", "sometoken") + // Use Shopify's mock.shop API as an API endpoint which doesn't require an access token. + private const string MyShopifyDomain = "https://mock.shop"; + + /// Number of seconds to delay before sending request to the mock.shop API. This is only used to ensure the + /// cancellationToken is canceled before the request is actually made. + private readonly TimeSpan _delay = TimeSpan.FromSeconds(1); + + public TestService() : base(MyShopifyDomain, "fake-token") { } - // these are what services call to execute their public API requests - public new Task ExecuteGetAsync(string path, string resultRootElt, string fields, CancellationToken cancellationToken = default) + // These are what services call to execute their public API requests + public Task ExecuteGetAsync(string path, string resultRootElt, string fields, CancellationToken cancellationToken = default) { + Thread.Sleep(_delay); return base.ExecuteGetAsync(path, resultRootElt, fields, cancellationToken); } - public new Task ExecuteGetAsync(string path, string resultRootElt, Parameterizable queryParams = null, CancellationToken cancellationToken = default) + public Task ExecuteGetAsync(string path, string resultRootElt, Parameterizable queryParams = null, CancellationToken cancellationToken = default) { + Thread.Sleep(_delay); return base.ExecuteGetAsync(path, resultRootElt, queryParams, cancellationToken); } - public new Task> ExecuteGetListAsync(string path, string resultRootElt, ListFilter filter, CancellationToken cancellationToken = default) + public Task> ExecuteGetListAsync(string path, string resultRootElt, ListFilter filter, CancellationToken cancellationToken = default) { + Thread.Sleep(_delay); return base.ExecuteGetListAsync(path, resultRootElt, filter, cancellationToken); } - public new Task ExecutePostAsync(string path, string resultRootElt, object jsonContent = null, CancellationToken cancellationToken = default) + public Task ExecutePostAsync(string path, string resultRootElt, object jsonContent = null, CancellationToken cancellationToken = default) { + Thread.Sleep(_delay); return base.ExecutePostAsync(path, resultRootElt, cancellationToken, jsonContent); } - public new Task ExecutePutAsync(string path, string resultRootElt, object jsonContent = null, CancellationToken cancellationToken = default) + public Task ExecutePutAsync(string path, string resultRootElt, object jsonContent = null, CancellationToken cancellationToken = default) { + Thread.Sleep(_delay); return base.ExecutePutAsync(path, resultRootElt, cancellationToken, jsonContent); } public new Task ExecuteDeleteAsync(string path, CancellationToken cancellationToken) { + Thread.Sleep(_delay); return base.ExecuteDeleteAsync(path, cancellationToken); } - public new Task> ExecuteRequestAsync(RequestUri uri, HttpMethod method, HttpContent content = null, CancellationToken cancellationToken = default) + public Task> ExecuteRequestAsync(RequestUri uri, HttpMethod method, HttpContent content = null, CancellationToken cancellationToken = default) { + Thread.Sleep(_delay); return base.ExecuteRequestAsync(uri, method, cancellationToken, content); } }