Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add parameter substitution tests #1896

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading