Skip to content

Commit 336bd3e

Browse files
committed
Add more code coverage requested in review
#2044 (comment)
1 parent 83b09f2 commit 336bd3e

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

Refit.Tests/RequestBuilder.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,6 +1773,12 @@ Task<string> FetchSomeStuffWithHardcodedAndOtherQueryParameters(
17731773
[Get("/foo?q=app_metadata.id:\"{id}\"")]
17741774
Task<string> FetchSomeStuffWithDoubleQuotesInUrl(int id);
17751775

1776+
[Get("/foo/bar/({id})")]
1777+
Task<string> GetWithTrainingParenthesis(int id);
1778+
1779+
[Get("/foo/bar/{id}/")]
1780+
Task<string> GetWithTrailingSlash(int id);
1781+
17761782
[Post("/foo/bar/{id}")]
17771783
[Headers("Content-Type: literally/anything")]
17781784
Task<string> PostSomeStuffWithHardCodedContentTypeHeader(int id, [Body] string content);
@@ -2604,13 +2610,30 @@ public void QueryParamWhichEndsInDoubleQuotesShouldNotBeTruncated()
26042610
var factory = fixture.BuildRequestFactoryForMethod(
26052611
"FetchSomeStuffWithDoubleQuotesInUrl"
26062612
);
2607-
var output = factory(new object[] { 42 });
2613+
var output = factory([42]);
26082614

2609-
var uri = new Uri(new Uri("http://api"), output.RequestUri);
2615+
var uri = new Uri(new Uri("http://api"), output.RequestUri!);
26102616

26112617
Assert.Equal("/foo?q=app_metadata.id%3A%2242%22", uri.PathAndQuery);
26122618
}
26132619

2620+
[Theory]
2621+
[InlineData("GetWithTrainingParenthesis", ")", "/foo/bar/(1)")]
2622+
[InlineData("GetWithTrailingSlash", "/", "/foo/bar/1/")]
2623+
public void ShouldCaptureLastCharacterWhenRouteEndsWithConstant(string methodToTest, string constantChar, string contains)
2624+
{
2625+
var fixture = new RequestBuilderImplementation<IDummyHttpApi>();
2626+
var factory = fixture.BuildRequestFactoryForMethod(
2627+
methodToTest
2628+
);
2629+
var output = factory(["1"]);
2630+
2631+
var uri = new Uri(new Uri("http://api/"), output.RequestUri!);
2632+
2633+
Assert.EndsWith(constantChar, uri.PathAndQuery, StringComparison.Ordinal);
2634+
Assert.Contains(contains, uri.PathAndQuery, StringComparison.Ordinal);
2635+
}
2636+
26142637
[Fact]
26152638
public void ParameterizedQueryParamsShouldBeInUrlAndValuesEncodedWhenMixedReplacementAndQueryBadId()
26162639
{

Refit/RestMethodInfo.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -401,12 +401,12 @@ ParameterInfo[] parameterInfo
401401
}
402402
}
403403

404+
if (index >= relativePath.Length) return (ret, fragmentList);
405+
404406
// add trailing string
405-
if (index < relativePath.Length)
406-
{
407-
var trailingConstant = relativePath.Substring(index, relativePath.Length - index);
408-
fragmentList.Add(ParameterFragment.Constant(trailingConstant));
409-
}
407+
var trailingConstant = relativePath.Substring(index);
408+
fragmentList.Add(ParameterFragment.Constant(trailingConstant));
409+
410410
return (ret, fragmentList);
411411
}
412412

0 commit comments

Comments
 (0)