Skip to content

Commit

Permalink
feat: add parameter substitution tests (#1896)
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Pulman <[email protected]>
  • Loading branch information
TimothyMakkison and ChrisPulman authored Oct 29, 2024
1 parent dc74700 commit ebc7954
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Refit.Tests/RestServiceExceptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,24 @@ public interface IRoundTripNotString
Task<string> GetValue(int value);
}

public interface IRoundTrippingLeadingWhitespace
{
[Get("/{ **path}")]
Task<string> GetValue(string path);
}

public interface IRoundTrippingTrailingWhitespace
{
[Get("/{** path}")]
Task<string> GetValue(string path);
}

public interface IInvalidParamSubstitution
{
[Get("/{/path}")]
Task<string> GetValue(string path);
}

public interface IUrlNoMatchingParameters
{
[Get("/{value}")]
Expand Down Expand Up @@ -125,6 +143,27 @@ public void RoundTripParameterNotStringShouldThrow()
AssertExceptionContains("has round-tripping parameter", exception);
}

[Fact]
public void RoundTripWithLeadingWhitespaceShouldThrow()
{
var exception = Assert.Throws<ArgumentException>(() => RestService.For<IRoundTrippingLeadingWhitespace>("https://api.github.com"));
AssertExceptionContains("has parameter **path, but no method parameter matches", exception);
}

[Fact]
public void RoundTripWithTrailingWhitespaceShouldThrow()
{
var exception = Assert.Throws<ArgumentException>(() => RestService.For<IRoundTrippingTrailingWhitespace>("https://api.github.com"));
AssertExceptionContains("has parameter ** path, but no method parameter matches", exception);
}

[Fact]
public void InvalidParamSubstitutionShouldNotThrow()
{
var service = RestService.For<IInvalidParamSubstitution>("https://api.github.com");
Assert.NotNull(service);
}

[Fact]
public void UrlNoMatchingParameterShouldThrow()
{
Expand Down

0 comments on commit ebc7954

Please sign in to comment.