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.
This PR contains the following updates:
4.12.0
->4.13.0
Release Notes
moq/moq4
v4.13.0
Compare Source
Changed
Improved error message that is supplied with
ArgumentException
thrown whenSetup
orVerify
are called on a protected method if the method could not be found with both the name and compatible argument types specified (@thomasfdm, #852).mock.Invocations.Clear()
now removes traces of previous invocations more thoroughly by additionally resetting all setups to an "unmatched" state. (@stakx, #854)Consistent
Callback
delegate validation regardless of whether or notCallback
is preceded by aReturns
: Validation for post-Returns
callback delegates used to be very relaxed, but is now equally strict as in the pre-Returns
case.) (@stakx, #876)Subscription to mocked events used to be handled less strictly than subscription to regular CLI events. As with the latter, subscribing to mocked events now also requires all handlers to have the same delegate type. (@stakx, #891)
Moq will throw when it detects that an argument matcher will never match anything due to the presence of an implicit conversion operator. (@michelcedric, #897, #898)
New algorithm for matching invoked methods against methods specified in setup/verification expressions. (@stakx, #904)
Added
Added support for setup and verification of the event handlers through
Setup[Add|Remove]
andVerify[Add|Remove|All]
(@lepijohnny, #825)Added support for lambda expressions while creating a mock through
new Mock<SomeType>(() => new SomeType("a", "b"))
andrepository.Create<SomeType>(() => new SomeType("a", "b"))
. This makes the process of mocking a class without a parameterless constructor simpler (compiler syntax checker...). (@frblondin, #884)Support for matching generic type arguments:
mock.Setup(m => m.Method<It.IsAnyType>(...))
. (@stakx, #908)The standard type matchers are:
It.IsAnyType
— matches any typeIt.IsSubtype<T>
— matchesT
and proper subtypes ofT
It.IsValueType
— matches only value typesYou can create your own custom type matchers:
In order to support type matchers (see bullet point above), some new overloads have been added to existing methods:
setup.Callback(new InvocationAction(invocation => ...))
,setup.Returns(new InvocationFunc(invocation => ...))
:The lambda specified in these new overloads will receive an
IInvocation
representing the current invocation from which type arguments as well as arguments can be discovered.Match.Create<T>((object argument, Type parameterType) => ..., ...)
,It.Is<T>((object argument, Type parameterType) => ...)
:Used to create custom matchers that work with type matchers. When a type matcher is used for
T
, theargument
received by the custom matchers is untyped (object
), and its actual type (or rather the type of the parameter for which the argument was passed) is provided via an additional parameterparameterType
. (@stakx, #908)Fixed
Moq does not mock explicit interface implementation and
protected virtual
correctly. (@oddbear, #657)Invocations.Clear()
does not causeVerify
to fail (@jchessir, #733)Regression:
SetupAllProperties
can no longer set up properties whose names start withItem
. (@mattzink, #870; @kaan-kaya, #869)Regression:
MockDefaultValueProvider
will no longer attempt to setCallBase
to true for mocks generated for delegates. (@dammejed, #874)Verify
throwsTargetInvocationException
instead ofMockException
when one of the recorded invocations was to an async method that threw. (@Cufeadir, #883)Moq does not distinguish between distinct events if they have the same name (@stakx, #893)
Regression in 4.12.0:
SetupAllProperties
removes indexer setups. (@stakx, #901)Parameter types are ignored when matching an invoked generic method against setups. (@stakx, #903)
For
[Value]Task<object>
,.ReturnsAsync(null)
throwsNullReferenceException
instead of producing a completed task with resultnull
(@voroninp, #909)Renovate configuration
📅 Schedule: At any time (no schedule defined).
🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.
♻️ Rebasing: Whenever PR becomes conflicted, or if you modify the PR title to begin with "
rebase!
".🔕 Ignore: Close this PR and you won't be reminded about this update again.
This PR has been generated by Renovate Bot. View repository job log here.