Skip to content

Commit 093621c

Browse files
committed
fix test
1 parent e856fe5 commit 093621c

File tree

2 files changed

+33
-14
lines changed

2 files changed

+33
-14
lines changed

src/GraphQL.Primitives/GraphQLResponse.cs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,19 @@ public bool Equals(GraphQLResponse<T>? other) {
2222
if (other == null) { return false; }
2323
if (ReferenceEquals(this, other)) { return true; }
2424
if (!EqualityComparer<T>.Default.Equals(this.Data, other.Data)) { return false; }
25-
{
26-
if (this.Errors != null && other.Errors != null) {
27-
if (!Enumerable.SequenceEqual(this.Errors, other.Errors)) { return false; }
28-
}
29-
else if (this.Errors != null && other.Errors == null) { return false; }
30-
else if (this.Errors == null && other.Errors != null) { return false; }
25+
26+
if (this.Errors != null && other.Errors != null) {
27+
if (!Enumerable.SequenceEqual(this.Errors, other.Errors)) { return false; }
28+
}
29+
else if (this.Errors != null && other.Errors == null) { return false; }
30+
else if (this.Errors == null && other.Errors != null) { return false; }
31+
32+
if (this.Extensions!= null && other.Extensions != null) {
33+
if (!Enumerable.SequenceEqual(this.Extensions, other.Extensions)) { return false; }
3134
}
35+
else if (this.Extensions != null && other.Extensions == null) { return false; }
36+
else if (this.Extensions == null && other.Extensions != null) { return false; }
37+
3238
return true;
3339
}
3440

@@ -44,6 +50,15 @@ public override int GetHashCode() {
4450
else {
4551
hashCode = (hashCode * 397) ^ 0;
4652
}
53+
54+
if (this.Extensions != null) {
55+
foreach (var element in this.Extensions) {
56+
hashCode = (hashCode * 397) ^ EqualityComparer<KeyValuePair<string,object>>.Default.GetHashCode(element);
57+
}
58+
}
59+
else {
60+
hashCode = (hashCode * 397) ^ 0;
61+
}
4762
}
4863
return hashCode;
4964
}

tests/GraphQL.Client.Serializer.Tests/BaseSerializerTest.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,18 @@ public async void DeserializeFromUtf8StreamTest(string json, GraphQLResponse<obj
4949
var jsonBytes = Encoding.UTF8.GetBytes(json);
5050
await using var ms = new MemoryStream(jsonBytes);
5151
var response = await Serializer.DeserializeFromUtf8StreamAsync<GraphQLResponse<object>>(ms, CancellationToken.None);
52-
53-
response.Should().BeEquivalentTo(expectedResponse, options => {
54-
options.ComparingByMembers<GraphQLExtensionsType>();
55-
options.ComparingByMembers<Dictionary<string, object>>();
56-
options.ComparingByMembers<KeyValuePair<string, object>>();
57-
options.AllowingInfiniteRecursion();
58-
return options;
59-
});
52+
53+
response.Data.Should().BeEquivalentTo(expectedResponse.Data);
54+
response.Errors.Should().Equal(expectedResponse.Errors);
55+
56+
if (expectedResponse.Extensions == null)
57+
response.Extensions.Should().BeNull();
58+
else {
59+
foreach (var element in expectedResponse.Extensions) {
60+
response.Extensions.Should().ContainKey(element.Key);
61+
response.Extensions[element.Key].Should().BeEquivalentTo(element.Value);
62+
}
63+
}
6064
}
6165

6266
[Fact]

0 commit comments

Comments
 (0)