diff --git a/ShopifySharp.Tests/Services/ShopifyServiceTests.cs b/ShopifySharp.Tests/Services/ShopifyServiceTests.cs new file mode 100644 index 000000000..8dc525861 --- /dev/null +++ b/ShopifySharp.Tests/Services/ShopifyServiceTests.cs @@ -0,0 +1,30 @@ +using System; +using FluentAssertions; +using JetBrains.Annotations; +using ShopifySharp.Tests.TestClasses; +using Xunit; + +namespace ShopifySharp.Tests.Services; + +[Trait("Category", "ShopifyService")] +[TestSubject(typeof(ShopifyService))] +public class ShopifyServiceTests +{ + #region PrepareRequest(string path) and BuildRequestUri + + [Fact] + public void BuildRequestUri_ShouldReturnOverridenUri() + { + // Setup + var expectedUri = new Uri("https://some-expected-uri.com", UriKind.Absolute); + var service = new TestBuildRequestUriShopifyService(expectedUri); + + // Act + var result = service.BuildRequestUriProxy(); + + // Assert + result.ToUri().Should().Be(expectedUri); + } + + #endregion +} diff --git a/ShopifySharp.Tests/ShopifyService_Tests.cs b/ShopifySharp.Tests/ShopifyService_Tests.cs index b4d53ce16..414d7c934 100644 --- a/ShopifySharp.Tests/ShopifyService_Tests.cs +++ b/ShopifySharp.Tests/ShopifyService_Tests.cs @@ -5,12 +5,16 @@ using System.Net.Http.Headers; using System.Threading; using System.Threading.Tasks; +using JetBrains.Annotations; using ShopifySharp.Filters; using Xunit; +// TODO: move the tests in this file to the ShopifySharp.Tests.Services.ShopifyServiceTests file + namespace ShopifySharp.Tests { [Trait("Category", "ShopifyService"), Trait("Category", "DotNetFramework"), Collection("DotNetFramework tests")] + [TestSubject(typeof(ShopifyService))] public class ShopifyService_Tests { string ReasonPhrase(HttpStatusCode code) diff --git a/ShopifySharp.Tests/TestClasses/TestBuildRequestUriShopifyService.cs b/ShopifySharp.Tests/TestClasses/TestBuildRequestUriShopifyService.cs new file mode 100644 index 000000000..4962f35a6 --- /dev/null +++ b/ShopifySharp.Tests/TestClasses/TestBuildRequestUriShopifyService.cs @@ -0,0 +1,21 @@ +#nullable enable +using System; +using System.Threading; +using System.Threading.Tasks; +using ShopifySharp.Infrastructure; + +namespace ShopifySharp.Tests.TestClasses; + +/// +/// A test ShopifyService that overrides the method for testing. +/// +/// The uri you want the overriden to return for testing. +public class TestBuildRequestUriShopifyService(Uri requestUri) : ShopifyService("some-shop-domain", "some-access-token") +{ + protected override RequestUri BuildRequestUri(string _) + { + return new RequestUri(requestUri); + } + + public RequestUri BuildRequestUriProxy() => BuildRequestUri("some-path"); +}