|
| 1 | +using System.Collections.Generic; |
1 | 2 | using System.Text.Json; |
2 | 3 | using System.Threading.Tasks; |
3 | 4 | using FakeItEasy; |
@@ -46,7 +47,6 @@ public async Task WhenQueryOrMutationErrorsAreReturned_ShouldThrowRegardlessOfUs |
46 | 47 |
|
47 | 48 | string[] expectedPath = ["query some-query", "some-expected-path1", "some-expected-path2", "some-expected-path3" ]; |
48 | 49 | var expectedPathString = JsonSerializer.Serialize(expectedPath); |
49 | | - // var expectedPathString = string.Join("\", \"", expectedPath); |
50 | 50 |
|
51 | 51 | var responseJson = |
52 | 52 | // lang=json |
@@ -101,6 +101,79 @@ public async Task WhenQueryOrMutationErrorsAreReturned_ShouldThrowRegardlessOfUs |
101 | 101 | }); |
102 | 102 | } |
103 | 103 |
|
| 104 | + [Theory] |
| 105 | + [CombinatorialData] |
| 106 | + public async Task WhenQueryOrMutationErrorsAreReturned_AndTheyMatchTheExtensionsHaveAValuePropAndAProblemsProp_ShouldThrowRegardlessOfUserErrorHandling( |
| 107 | + GraphRequestUserErrorHandling userErrorHandling) |
| 108 | + { |
| 109 | + // Setup |
| 110 | + const string expectedMessage = "some-expected-message"; |
| 111 | + const string expectedProblemPath = "some-expected-path"; |
| 112 | + const string expectedProblemExplanation = "some-expected-explanation"; |
| 113 | + const string expectedProblemMessage = "some-expected-problem-message"; |
| 114 | + const string expectedValueKey = "some-expected-value-key"; |
| 115 | + const string expectedValueValue = "some-expected-value-value"; |
| 116 | + |
| 117 | + const string responseJson = |
| 118 | + // lang=json |
| 119 | + $$""" |
| 120 | + { |
| 121 | + "{{ErrorsPropertyName}}" : [ { |
| 122 | + "message" : "{{expectedMessage}}", |
| 123 | + "locations" : [ { |
| 124 | + "line" : 7, |
| 125 | + "column" : 2 |
| 126 | + } ], |
| 127 | + "extensions" : { |
| 128 | + "value": { |
| 129 | + "{{expectedValueKey}}": "{{expectedValueValue}}" |
| 130 | + }, |
| 131 | + "problems": [{ |
| 132 | + "path" : [ "{{expectedProblemPath}}" ], |
| 133 | + "explanation" : "{{expectedProblemExplanation}}", |
| 134 | + "message" : "{{expectedProblemMessage}}" |
| 135 | + }] |
| 136 | + } |
| 137 | + } ] |
| 138 | + } |
| 139 | + """; |
| 140 | + const string expectedRequestId = "some-expected-request-id"; |
| 141 | + var response = Utils.MakeRequestResult(responseJson, x => x.RequestId = expectedRequestId); |
| 142 | + |
| 143 | + A.CallTo(_policy) |
| 144 | + .WithReturnType<Task<RequestResult<string>>>() |
| 145 | + .Returns(response); |
| 146 | + |
| 147 | + // Act |
| 148 | + var act = async () => await _sut.PostAsync(new GraphRequest |
| 149 | + { |
| 150 | + UserErrorHandling = userErrorHandling |
| 151 | + }); |
| 152 | + |
| 153 | + // Assert |
| 154 | + var exn = await act.Should() |
| 155 | + .ThrowExactlyAsync<ShopifyGraphErrorsException>() |
| 156 | + .WithMessage($"{expectedMessage}"); |
| 157 | + |
| 158 | + exn.Which.RequestId.Should().Be(expectedRequestId); |
| 159 | + exn.Which.InnerException.Should().BeNull(); |
| 160 | + exn.Which.GraphErrors.Should().SatisfyRespectively(graphError => |
| 161 | + { |
| 162 | + graphError.Message.Should().Be(expectedMessage); |
| 163 | + graphError.Path.Should().BeNullOrEmpty(); |
| 164 | + graphError.Extensions.Should().BeEquivalentTo(new GraphErrorExtensions |
| 165 | + { |
| 166 | + Value = new Dictionary<string, object>{ {expectedValueKey, expectedValueValue} }, |
| 167 | + Problems = [new GraphErrorExtensionsProblem |
| 168 | + { |
| 169 | + Explanation = expectedProblemExplanation, |
| 170 | + Message = expectedProblemMessage, |
| 171 | + Path = [expectedProblemPath] |
| 172 | + }] |
| 173 | + }); |
| 174 | + }); |
| 175 | + } |
| 176 | + |
104 | 177 | [Theory] |
105 | 178 | [CombinatorialData] |
106 | 179 | public async Task WhenQueryOrMutationErrorsAreReturned_AndTheArrayIsEmptyWithZeroErrors_ShouldNotThrow( |
|
0 commit comments