Repository navigation
feat(mocks): add ClearCalls, PassThrough toggle and string/type/reference matchers #7018
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
809155e
feat(mocks): add ClearInvocations, CallBase toggle and string/type/re…
claude 6a84e33
Merge pull request #3 from Quattordici/claude/mocks-clear-invocations…
Quattordici e9c2819
fix(mocks): don't auto-track indexer setters with CallBase=false; doc…
Quattordici da3aa67
refactor(mocks): share CallBase=false handling, strict beats DefaultV…
Quattordici cc647e5
docs(mocks): IsOfType doc describes setup-time ArgumentException
Quattordici 4ddf8d1
docs(mocks): fix orphaned TryHandleCall docs; document ClearInvocatio…
Quattordici eb41313
refactor(mocks): rename CallBase to PassThrough and ClearInvocations …
Quattordici 3e11df2
test(mocks): cover Contains overload, wrap+strict+PassThrough; cleare…
Quattordici 25ecad2
docs(mocks): note net8 ClearCalls form; broaden IsOfType error guidance
Quattordici 76c57ba
fix(mocks): address PassThrough/ClearCalls review findings
Quattordici 157b493
Merge branch 'main' into main
Quattordici 391db11
fix(mocks): scope PassThrough=false base-call and provider handling
Quattordici 7818c18
fix(mocks): don't swallow type mismatches in static-abstract return c…
Quattordici 5e23bad
docs/test(mocks): clarify ClearCalls and Reset semantics, pin edge cases
Quattordici 3323a4e
refactor(mocks): opt-in interfaces for ClearCalls/PassThrough; Reset …
Quattordici 1bc95cb
docs(mocks): note that IsOfType/IsSameAs sentinels need a typed conve…
Quattordici 9b4bb3d
docs/test(mocks): fix doubled period, rename pass-through heading, pi…
Quattordici 3f9fb36
test(mocks): pin that ClearCalls never exposes a half-reset call history
Quattordici 60f83c2
test(mocks): make the ClearCalls race test exercise the per-member co…
Quattordici de1b02f
Merge branch 'main' into main
Quattordici 6dba86e
docs/test(mocks): document ClearCalls race and Moq sequence note; pin…
Quattordici 1ed1b40
Merge upstream main into fork main
Quattordici cb57636
docs/test(mocks): comment wrap-strict precedence; pin single-arg sett…
Quattordici ed4291c
fix(mocks): address review on matchers, ResetInvokeCount and PassThro…
thomhurst a7d7b48
fix(mocks): IsSameAs matches equal values for value types; dedupe unm…
thomhurst bb67916
fix(mocks): identify object-method overrides by symbol; align IsSameA…
thomhurst aff3117
fix(mocks): IsOfType compares nullable parameters by their underlying…
thomhurst 05d3db4
fix(mocks): pass auto-mock factory through indexer getters; honor arr…
thomhurst e8ecf43
fix(mocks): discover auto-mock factories for interfaces returned by i…
thomhurst c415775
fix(mocks): limit IsOfType array covariance to interfaces arrays impl…
thomhurst 8b83e1f
refactor(mocks): route untyped unmatched calls through shared helpers…
thomhurst d5cff53
fix(mocks): object-method bases pass through nested calls; skip inacc…
thomhurst 9a4803a
refactor(mocks): StringMatcher names its Arg factory explicitly in de…
thomhurst 9887b66
fix(mocks): object methods read auto-tracked property values when Pas…
thomhurst b657e9a
docs(mocks): note ClearCalls is not atomic against concurrent verific…
thomhurst d103ae5
docs(mocks): Mock.ClearCalls documents invoke-count reset and non-ato…
thomhurst 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
Some comments aren't visible on the classic Files Changed page.
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
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
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
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
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 |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| using TUnit.Mocks.Arguments; | ||
|
|
||
| namespace TUnit.Mocks.Matchers; | ||
|
|
||
| /// <summary> | ||
| /// Matches only the exact same object instance, ignoring any <c>Equals</c> override. | ||
| /// </summary> | ||
| internal sealed class ReferenceEqualsMatcher<T> : IArgumentMatcher<T> where T : class | ||
| { | ||
| private readonly T _expected; | ||
|
|
||
| public ReferenceEqualsMatcher(T expected) => _expected = expected ?? throw new ArgumentNullException(nameof(expected)); | ||
|
|
||
| public bool Matches(T? value) => ReferenceEquals(_expected, value); | ||
|
|
||
| public bool Matches(object? value) => ReferenceEquals(_expected, value); | ||
|
|
||
| public string Describe() => "Arg.IsSameAs(" + _expected.GetType().Name + " instance)"; | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| using TUnit.Mocks.Arguments; | ||
|
|
||
| namespace TUnit.Mocks.Matchers; | ||
|
|
||
| /// <summary> | ||
| /// Matches non-null string arguments by prefix, suffix or substring. | ||
| /// </summary> | ||
| internal sealed class StringMatcher : IArgumentMatcher<string> | ||
| { | ||
| internal enum Mode | ||
| { | ||
| StartsWith, | ||
| EndsWith, | ||
| Contains, | ||
| } | ||
|
|
||
| private readonly string _text; | ||
| private readonly Mode _mode; | ||
| private readonly StringComparison _comparison; | ||
|
|
||
| public StringMatcher(Mode mode, string text, StringComparison comparison) | ||
| { | ||
| _text = text ?? throw new ArgumentNullException(nameof(text)); | ||
|
thomhurst marked this conversation as resolved.
Outdated
|
||
| _mode = mode; | ||
| _comparison = comparison; | ||
| } | ||
|
|
||
| public bool Matches(string? value) | ||
| { | ||
| if (value is null) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| return _mode switch | ||
| { | ||
| Mode.StartsWith => value.StartsWith(_text, _comparison), | ||
| Mode.EndsWith => value.EndsWith(_text, _comparison), | ||
| _ => value.IndexOf(_text, _comparison) >= 0, | ||
| }; | ||
| } | ||
|
|
||
| public bool Matches(object? value) => value is string s && Matches(s); | ||
|
|
||
| public string Describe() => _comparison == StringComparison.Ordinal | ||
| ? $"Arg.{_mode}(\"{_text}\")" | ||
| : $"Arg.{_mode}(\"{_text}\", {_comparison})"; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.