-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve default IsValidResponseToDeserialize implementation (#560)
* change default implementation of response validation method to ensure correct response content type * add tests for the default validation method * remove unnecessary comments Co-authored-by: Ivan Maximov <sungam3r@yandex.ru> * accepted response types private, formatting * make DefaultIsValidResponseToDeserialize publicly accessible Co-authored-by: Ivan Maximov <sungam3r@yandex.ru> * AcceptedResponseContentTypes as static field --------- Co-authored-by: Ivan Maximov <sungam3r@yandex.ru>
- Loading branch information
Showing
2 changed files
with
39 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
tests/GraphQL.Client.Serializer.Tests/DefaultValidationTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.Net; | ||
using System.Net.Http.Headers; | ||
using FluentAssertions; | ||
using GraphQL.Client.Http; | ||
using Xunit; | ||
|
||
namespace GraphQL.Client.Serializer.Tests; | ||
|
||
public class DefaultValidationTest | ||
{ | ||
[Theory] | ||
[InlineData(HttpStatusCode.OK, "application/json", true)] | ||
[InlineData(HttpStatusCode.OK, "application/graphql-response+json", true)] | ||
[InlineData(HttpStatusCode.BadRequest, "application/json", true)] | ||
[InlineData(HttpStatusCode.BadRequest, "text/html", false)] | ||
[InlineData(HttpStatusCode.OK, "text/html", false)] | ||
[InlineData(HttpStatusCode.Forbidden, "text/html", false)] | ||
[InlineData(HttpStatusCode.Forbidden, "application/json", false)] | ||
public void IsValidResponse_OkJson_True(HttpStatusCode statusCode, string mediaType, bool expectedResult) | ||
{ | ||
var response = new HttpResponseMessage(statusCode); | ||
response.Content.Headers.ContentType = new MediaTypeHeaderValue(mediaType); | ||
|
||
bool isValid = new GraphQLHttpClientOptions().IsValidResponseToDeserialize(response); | ||
|
||
isValid.Should().Be(expectedResult); | ||
} | ||
} |