Skip to content

Commit cd69c8a

Browse files
committed
Fixed unsupported media type error message in route testing (closes #160)
1 parent ecc9938 commit cd69c8a

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/MyWebApi.Tests/BuildersTests/RoutesTests/RoutesTestBuilderTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,27 @@ public void ToShouldThrowExceptionWithWrongActionArguments()
305305
}));
306306
}
307307

308+
[Test]
309+
[ExpectedException(
310+
typeof(RouteAssertionException),
311+
ExpectedMessage = "Expected route 'api/Route/PostMethodWithModel' to match PostMethodWithModel action in RouteController but it could not be resolved: 'Unsupported Media Type'.")]
312+
public void ToShouldThrowExceptionWithUnsupportedMediaType()
313+
{
314+
MyWebApi
315+
.Routes()
316+
.ShouldMap("api/Route/PostMethodWithModel")
317+
.WithHttpMethod(HttpMethod.Post)
318+
.WithContent(
319+
@"{""Integer"": 1, ""RequiredString"": ""Test"", ""NonRequiredString"": ""AnotherTest"", ""NotValidateInteger"": 2}", MediaType.TextPlain)
320+
.To<RouteController>(c => c.PostMethodWithModel(new RequestModel
321+
{
322+
Integer = 1,
323+
RequiredString = "Test",
324+
NonRequiredString = "AnotherTest",
325+
NotValidateInteger = 2
326+
}));
327+
}
328+
308329
[Test]
309330
public void ToNotAllowedMethodShouldWorkCorrectly()
310331
{

src/MyWebApi/Utilities/RouteResolvers/InternalRouteResolver.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ public static ResolvedRouteInfo Resolve(HttpConfiguration config, HttpRequestMes
7777
UnresolvedRouteFormat,
7878
ex.Response.ReasonPhrase));
7979
}
80+
catch (AggregateException ex)
81+
{
82+
var innerException = (HttpResponseException)ex.InnerExceptions.First();
83+
resolvedRouteInfo = new ResolvedRouteInfo(string.Format(
84+
UnresolvedRouteFormat,
85+
innerException.Response.ReasonPhrase));
86+
}
8087
catch (Exception ex)
8188
{
8289
resolvedRouteInfo = new ResolvedRouteInfo(string.Format(

0 commit comments

Comments
 (0)