Skip to content

Commit

Permalink
Add test for overriding BuildRequestUri
Browse files Browse the repository at this point in the history
  • Loading branch information
nozzlegear committed Dec 19, 2023
1 parent 488f80b commit f854fd0
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
30 changes: 30 additions & 0 deletions ShopifySharp.Tests/Services/ShopifyServiceTests.cs
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 4 additions & 0 deletions ShopifySharp.Tests/ShopifyService_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#nullable enable
using System;
using System.Threading;
using System.Threading.Tasks;
using ShopifySharp.Infrastructure;

namespace ShopifySharp.Tests.TestClasses;

/// <summary>
/// A test ShopifyService that overrides the <see cref="ShopifyService.BuildRequestUri(string)"/> method for testing.
/// </summary>
/// <param name="requestUri">The uri you want the overriden <see cref="ShopifyService.BuildRequestUri(string)"/> to return for testing.</param>
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");
}

0 comments on commit f854fd0

Please sign in to comment.