-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into code-cleanup
- Loading branch information
Showing
8 changed files
with
98 additions
and
17 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
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
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
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
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
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
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,11 @@ | ||
namespace GraphQL | ||
{ | ||
public interface IGraphQLResponse | ||
{ | ||
object Data { get; } | ||
|
||
GraphQLError[]? Errors { get; set; } | ||
|
||
Map? Extensions { get; set; } | ||
} | ||
} |
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,62 @@ | ||
using System.Collections.Generic; | ||
using FluentAssertions; | ||
using FluentAssertions.Execution; | ||
using GraphQL.Client.Serializer.Newtonsoft; | ||
using GraphQL.Client.Serializer.SystemTextJson; | ||
using Newtonsoft.Json; | ||
using Xunit; | ||
|
||
namespace GraphQL.Client.Serializer.Tests | ||
{ | ||
public class ConsistencyTests | ||
{ | ||
[Fact] | ||
public void MapConvertersShouldBehaveConsistent() | ||
{ | ||
const string json = @"{ | ||
""array"": [ | ||
""some stuff"", | ||
""something else"" | ||
], | ||
""string"": ""this is a string"", | ||
""boolean"": true, | ||
""number"": 1234.567, | ||
""nested object"": { | ||
""prop1"": false | ||
}, | ||
""arrayOfObjects"": [ | ||
{""number"": 1234.567}, | ||
{""number"": 567.8} | ||
] | ||
}"; | ||
|
||
var newtonsoftSerializer = new NewtonsoftJsonSerializer(); | ||
var systemTextJsonSerializer = new SystemTextJsonSerializer(); | ||
|
||
var newtonsoftMap = JsonConvert.DeserializeObject<Map>(json, newtonsoftSerializer.JsonSerializerSettings); | ||
var systemTextJsonMap = System.Text.Json.JsonSerializer.Deserialize<Map>(json, systemTextJsonSerializer.Options); | ||
|
||
|
||
using(new AssertionScope()) | ||
{ | ||
CompareMaps(newtonsoftMap, systemTextJsonMap); | ||
} | ||
|
||
newtonsoftMap.Should().BeEquivalentTo(systemTextJsonMap, options => options | ||
.RespectingRuntimeTypes()); | ||
} | ||
|
||
private void CompareMaps(Dictionary<string, object> first, Dictionary<string, object> second) | ||
{ | ||
foreach (var keyValuePair in first) | ||
{ | ||
second.Should().ContainKey(keyValuePair.Key); | ||
second[keyValuePair.Key].Should().BeOfType(keyValuePair.Value.GetType()); | ||
if(keyValuePair.Value is Dictionary<string, object> map) | ||
CompareMaps(map, (Dictionary<string, object>)second[keyValuePair.Key]); | ||
else | ||
keyValuePair.Value.Should().BeEquivalentTo(second[keyValuePair.Key]); | ||
} | ||
} | ||
} | ||
} |