Skip to content

Commit

Permalink
Merge pull request #807 from nhart12/master
Browse files Browse the repository at this point in the history
Fix for #802 casing bug on object bound to url
  • Loading branch information
clairernovotny authored Mar 21, 2020
2 parents 90d8492 + ae0c243 commit 68c1c1d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
8 changes: 8 additions & 0 deletions Refit.Tests/RefitStubs.Net46.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,14 @@ Task IApiBindPathToObject.GetFooBars(PathBoundObject request)
return (Task)func(Client, arguments);
}

/// <inheritdoc />
Task IApiBindPathToObject.GetFooBarsWithDifferentCasing(PathBoundObject requestParams)
{
var arguments = new object[] { requestParams };
var func = requestBuilder.BuildRestResultFuncForMethod("GetFooBarsWithDifferentCasing", new Type[] { typeof(PathBoundObject) });
return (Task)func(Client, arguments);
}

/// <inheritdoc />
Task IApiBindPathToObject.GetBarsByFoo(string id, PathBoundObject request)
{
Expand Down
8 changes: 8 additions & 0 deletions Refit.Tests/RefitStubs.NetCore2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,14 @@ Task IApiBindPathToObject.GetFooBars(PathBoundObject request)
return (Task)func(Client, arguments);
}

/// <inheritdoc />
Task IApiBindPathToObject.GetFooBarsWithDifferentCasing(PathBoundObject requestParams)
{
var arguments = new object[] { requestParams };
var func = requestBuilder.BuildRestResultFuncForMethod("GetFooBarsWithDifferentCasing", new Type[] { typeof(PathBoundObject) });
return (Task)func(Client, arguments);
}

/// <inheritdoc />
Task IApiBindPathToObject.GetBarsByFoo(string id, PathBoundObject request)
{
Expand Down
26 changes: 26 additions & 0 deletions Refit.Tests/RestService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public interface IApiBindPathToObject
[Get("/foos/{request.someProperty}/bar/{request.someProperty2}")]
Task GetFooBars(PathBoundObject request);

[Get("/foos/{Requestparams.SomeProperty}/bar/{requestParams.SoMeProPerty2}")]
Task GetFooBarsWithDifferentCasing(PathBoundObject requestParams);

[Get("/foos/{id}/{request.someProperty}/bar/{request.someProperty2}")]
Task GetBarsByFoo(string id, PathBoundObject request);

Expand All @@ -65,6 +68,7 @@ public interface IApiBindPathToObject
[Get("/foos/{request.someProperty}/bar")]
Task GetBarsByFoo(PathBoundObject request);


[Get("/foos/{request.someProperty}/bar/{request.someProperty3}")]
Task GetFooBarsDerived(PathBoundDerivedObject request);

Expand Down Expand Up @@ -281,6 +285,28 @@ await fixture.GetFooBars(new PathBoundObject()
mockHttp.VerifyNoOutstandingExpectation();
}

[Fact]
public async Task GetWithPathBoundObjectDifferentCasing()
{
var mockHttp = new MockHttpMessageHandler();
mockHttp.Expect(HttpMethod.Get, "http://foo/foos/1/bar/barNone")
.WithExactQueryString("")
.Respond("application/json", "Ok");

var settings = new RefitSettings
{
HttpMessageHandlerFactory = () => mockHttp
};
var fixture = RestService.For<IApiBindPathToObject>("http://foo", settings);

await fixture.GetFooBarsWithDifferentCasing(new PathBoundObject()
{
SomeProperty = 1,
SomeProperty2 = "barNone"
});
mockHttp.VerifyNoOutstandingExpectation();
}

[Fact]
public async Task GetWithPathBoundObjectAndParameter()
{
Expand Down
2 changes: 1 addition & 1 deletion Refit/RestMethodInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ Dictionary<int, RestMethodParameterInfo> BuildParameterMap(string relativePath,
//if the param is an lets make a dictionary for all it's potential parameters
var objectParamValidationDict = parameterInfo.Where(x => x.ParameterType.GetTypeInfo().IsClass)
.SelectMany(x => GetParameterProperties(x).Select(p => Tuple.Create(x, p)))
.GroupBy(i => $"{i.Item1.Name}.{GetUrlNameForProperty(i.Item2).ToLowerInvariant()}")
.GroupBy(i => $"{i.Item1.Name}.{GetUrlNameForProperty(i.Item2)}".ToLowerInvariant())
.ToDictionary(k => k.Key, v => v.First());
foreach (var match in parameterizedParts)
{
Expand Down

0 comments on commit 68c1c1d

Please sign in to comment.