8000 add It.Ignore for AnyMatcher by helloserve · Pull Request #790 · devlooped/moq · GitHub
[go: up one dir, main page]

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Moq/It.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ internal static MethodCallExpression IsAny(Type genericArgument)
return Expression.Call(It.isAnyMethod.MakeGenericMethod(genericArgument));
}

/// <include file='It.xdoc' path='docs/doc[@for="It.Ignore"]/*'/>
public static TValue Ignore<TValue>()
{
return Match<TValue>.Create<TValue>(null, () => It.Ignore<TValue>());
}

/// <include file='It.xdoc' path='docs/doc[@for="It.IsNotNull"]/*'/>
public static TValue IsNotNull<TValue>()
{
Expand Down
16 changes: 16 additions & 0 deletions src/Moq/It.xdoc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@
</example>
<typeparam name="TValue">Type of the value.</typeparam>
</doc>
<doc for="It.Ignore">
<summary>
Ignores any type or value.
</summary>
<remarks>
Typically used when the actual argument type for the method is
internal or private.
</remarks>
<example>
<code>
// Verifies that a call to the logger was made for severity Warning, regardless of the actual log formatter.
mock.Verify(x => x.Log(LogLevel.Warning, It.IsAny&lt;EventId&gt;(), It.IsAny&lt;object&gt;(), It.IsAny&lt;Exception&gt;(), It.Ignore&lt;Func&lt;object, Exception, string&gt;&gt;()));
</code>
</example>
<typeparam name="TValue">Type of the value.</typeparam>
</doc>
<doc for="It.IsNotNull">
<summary>
Matches any value of the given <typeparamref name="TValue"/> type, except null.
Expand Down
8 changes: 8 additions & 0 deletions src/Moq/MatcherFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ public static IMatcher[] CreateMatchers(IReadOnlyList<Expression> arguments, Par

public static IMatcher CreateMatcher(Expression argument, ParameterInfo parameter)
{
if (argument is MethodCallExpression methodCallExpression)
{
if (methodCallExpression.Method.Name == nameof(It.Ignore))
{
return AnyMatcher.Instance;
}
}

if (parameter.ParameterType.IsByRef)
{
if ((parameter.Attributes & (ParameterAttributes.In | ParameterAttributes.Out)) == ParameterAttributes.Out)
Expand Down
0