You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Src/FluentAssertions.Json/JTokenAssertions.cs
+107Lines changed: 107 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,5 @@
1
1
usingSystem.Diagnostics;
2
+
usingSystem.Linq;
2
3
usingFluentAssertions.Collections;
3
4
usingFluentAssertions.Json.Common;
4
5
usingFluentAssertions.Execution;
@@ -283,6 +284,112 @@ public AndConstraint<JTokenAssertions> HaveCount(int expected, string because =
283
284
}
284
285
}
285
286
287
+
/// <summary>
288
+
/// Recursively asserts that the current <see cref="JToken"/> contains at least the properties or elements of the specified <see cref="JToken"/>.
289
+
/// </summary>
290
+
/// <param name="subtree">The subtree to search for</param>
291
+
/// <param name="because">
292
+
/// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
293
+
/// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
294
+
/// </param>
295
+
/// <param name="becauseArgs">
296
+
/// Zero or more objects to format using the placeholders in <see cref="because" />.
297
+
/// </param>
298
+
/// <remarks>Use this method to match the current <see cref="JToken"/> against an arbitrary subtree,
299
+
/// permitting it to contain any additional properties or elements. This way we can test multiple properties on a <see cref="JObject"/> at once,
300
+
/// or test if a <see cref="JArray"/> contains any items that match a set of properties, assert that a JSON document has a given shape, etc. </remarks>
301
+
/// <example>
302
+
/// This example asserts the values of multiple properties of a child object within a JSON document.
/// <example>This example asserts that a <see cref="JArray"/> within a <see cref="JObject"/> has at least one element with at least the given properties</example>
.FailWith("Expected JSON document to contain subtree {0} {reason}, but some elements were missing.",subtree);// todo: report exact cause of failure, eg. name of the missing property, etc.
319
+
320
+
returnnewAndConstraint<JTokenAssertions>(this);
321
+
}
322
+
323
+
/// <summary>
324
+
/// Recursively asserts that the current <see cref="JToken"/> contains at least the properties or elements of the specified <see cref="JToken"/>.
325
+
/// </summary>
326
+
/// <param name="subtree">The subtree to search for</param>
327
+
/// <param name="because">
328
+
/// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
329
+
/// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
330
+
/// </param>
331
+
/// <param name="becauseArgs">
332
+
/// Zero or more objects to format using the placeholders in <see cref="because" />.
333
+
/// </param>
334
+
/// <remarks>Use this method to match the current <see cref="JToken"/> against an arbitrary subtree,
335
+
/// permitting it to contain any additional properties or elements. This way we can test multiple properties on a <see cref="JObject"/> at once,
336
+
/// or test if a <see cref="JArray"/> contains any items that match a set of properties, assert that a JSON document has a given shape, etc. </remarks>
337
+
/// <example>
338
+
/// This example asserts the values of multiple properties of a child object within a JSON document.
/// <example>This example asserts that a <see cref="JArray"/> within a <see cref="JObject"/> has at least one element with at least the given properties</example>
0 commit comments