-
Notifications
You must be signed in to change notification settings - Fork 30
Add overload of ContainSubtree that takes a config #79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
labsin
wants to merge
4
commits into
fluentassertions:master
Choose a base branch
from
labsin:ContainSubtree-config-overload
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -27,7 +27,7 @@ static JTokenAssertions() | |
| /// Initializes a new instance of the <see cref="JTokenAssertions" /> class. | ||
| /// </summary> | ||
| /// <param name="subject">The subject</param> | ||
| /// <param name="orCreate"></param> | ||
| /// <param name="assertionChain">The assertion chain</param> | ||
| public JTokenAssertions(JToken subject, AssertionChain assertionChain) | ||
| : base(subject, assertionChain) | ||
| { | ||
|
|
@@ -437,15 +437,17 @@ public AndConstraint<JTokenAssertions> HaveCount(int expected, string because = | |
| /// <example> | ||
| /// This example asserts the values of multiple properties of a child object within a JSON document. | ||
| /// <code> | ||
| /// var json = JToken.Parse("{ success: true, data: { id: 123, type: 'my-type', name: 'Noone' } }"); | ||
| /// json.Should().ContainSubtree(JToken.Parse("{ success: true, data: { type: 'my-type', name: 'Noone' } }")); | ||
| /// var json = JToken.Parse("{ success: true, data: { id: 123, type: 'my-type', name: 'None' } }"); | ||
| /// json.Should().ContainSubtree(JToken.Parse("{ success: true, data: { type: 'my-type', name: 'None' } }")); | ||
| /// </code> | ||
| /// </example> | ||
| /// <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> | ||
| /// <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 | ||
| /// <code> | ||
| /// var json = JToken.Parse("{ id: 1, items: [ { id: 2, type: 'my-type', name: 'Alpha' }, { id: 3, type: 'other-type', name: 'Bravo' } ] }"); | ||
| /// json.Should().ContainSubtree(JToken.Parse("{ items: [ { type: 'my-type', name: 'Alpha' } ] }")); | ||
| /// </code> | ||
| /// </example> | ||
| public AndConstraint<JTokenAssertions> ContainSubtree(string subtree, string because = "", params object[] becauseArgs) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we also augment this overload with one that takes a |
||
| { | ||
| JToken subtreeToken; | ||
|
|
@@ -482,20 +484,45 @@ public AndConstraint<JTokenAssertions> ContainSubtree(string subtree, string bec | |
| /// <example> | ||
| /// This example asserts the values of multiple properties of a child object within a JSON document. | ||
| /// <code> | ||
| /// var json = JToken.Parse("{ success: true, data: { id: 123, type: 'my-type', name: 'Noone' } }"); | ||
| /// json.Should().ContainSubtree(JToken.Parse("{ success: true, data: { type: 'my-type', name: 'Noone' } }")); | ||
| /// var json = JToken.Parse("{ success: true, data: { id: 123, type: 'my-type', name: 'None' } }"); | ||
| /// json.Should().ContainSubtree(JToken.Parse("{ success: true, data: { type: 'my-type', name: 'None' } }")); | ||
| /// </code> | ||
| /// </example> | ||
| /// <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> | ||
| /// <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 | ||
| /// <code> | ||
| /// var json = JToken.Parse("{ id: 1, items: [ { id: 2, type: 'my-type', name: 'Alpha' }, { id: 3, type: 'other-type', name: 'Bravo' } ] }"); | ||
| /// json.Should().ContainSubtree(JToken.Parse("{ items: [ { type: 'my-type', name: 'Alpha' } ] }")); | ||
| /// </code> | ||
| /// </example> | ||
| public AndConstraint<JTokenAssertions> ContainSubtree(JToken subtree, string because = "", params object[] becauseArgs) | ||
| { | ||
| return BeEquivalentTo(subtree, true, options => options, because, becauseArgs); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Recursively asserts that the current <see cref="JToken"/> contains at least the properties or elements of the specified <paramref name="subtree"/>. | ||
| /// </summary> | ||
| /// <param name="subtree">The subtree to search for</param> | ||
| /// <param name="config">The options to consider while asserting values</param> | ||
| /// <param name="because"> | ||
| /// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion | ||
| /// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically. | ||
| /// </param> | ||
| /// <param name="becauseArgs"> | ||
| /// Zero or more objects to format using the placeholders in <see cref="because" />. | ||
| /// </param> | ||
| /// <remarks>Use this method to match the current <see cref="JToken"/> against an arbitrary subtree, | ||
| /// permitting it to contain any additional properties or elements. This way we can test multiple properties on a <see cref="JObject"/> at once, | ||
| /// 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> | ||
|
Comment on lines
+503
to
+517
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's also add the |
||
| public AndConstraint<JTokenAssertions> ContainSubtree(JToken subtree, | ||
| Func<IJsonAssertionOptions<object>, IJsonAssertionOptions<object>> config, | ||
| string because = "", | ||
| params object[] becauseArgs) | ||
| { | ||
| return BeEquivalentTo(subtree, true, config, because, becauseArgs); | ||
| } | ||
|
|
||
| #pragma warning disable CA1822 // Making this method static is a breaking chan | ||
| public string Format(JToken value, bool useLineBreaks = false) | ||
| { | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
Noneis not more correct thanNoone. (no one/no-one).If tools think that
Nooneis a a typo , then let's just change it to a real name like John or Joe.