NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
NuGet, #45 most downloaded on NuGet
Moq is the most popular and friendly mocking framework for .NET.
Latest stable
4.21.0
Last release 1 months ago
24 Sep 2026
Release timing varies
gaps range from 4 weeks to 2.0 years
Nearly every release is documented
notes for 59 of the last 60 stable releases
10 versions withdrawn
withdrawn after publishing
127 years old
115 releases · first in 1900
Drag across the ruler to compare, or tap a release to open it.
Improve performance of It.Is matcher when used with an expression by compiling only once by @peterder72 in #1512
Full Changelog: v4.20.72...v4.21.0
The following sponsors made this release possible: @clarius, @MFB-Technologies-Inc, @sandrock, @drivenet, @Keflon, @tbolon, @rbnswartz, @jfoshee, @Mrxx99, @eajhnsn1, @Jonathan-Hickey, @KenBonny, @SimonCropp, @agileworks-eu, @arsdragonfly, @vezel-dev, @ChilliCream, @4OTC, @DominicSchell, @adalon, @torutek, @mccaffers, @SeikaLogiciel, @wizardness, @eska-gmbh, @geodata-no.
Thanks 💜
Your coding agent can read these notes before it upgrades. Set up the MCP server →
:sparkles: Implemented enhancements:
:bug: Fixed bugs:
mock.Invocations.Clear() violates self-consistency of inner mocks #1120:hammer: Other:
DefaultValueProvider extensibility #1450:twisted_rightwards_arrows: Merged:
Remove unused attribute by @kzu in #1515
Update License.txt to use SPDX identifier for automatic recognition by @georg-eckert-zeiss in #1471
Full Changelog: v4.20.70...v4.20.71
:bug: Fixed bugs:
:hammer: Other:
null #1391:twisted_rightwards_arrows: Merged:
Restore GDPR compliance and privacy by @DanWillman in #1402
Full Changelog: v4.20.69...v4.20.70
:hammer: Other:
:twisted_rightwards_arrows: Merged:
Let's make it more memorable when Moq became "safe" again.
Let's make it more memorable when Moq became "safe" again.
:hammer: Other:
:twisted_rightwards_arrows: Merged:
Remove SponsorLink since it breaks MacOS restore by @kzu in https://github.com/moq/moq/pull/1375
NOTE: in addition, there were potential privacy issues raised with regards to the SHA256 hashing of
user' email to check for sponsorship, so it won't be coming back until that's properly addressed
Full Changelog: moq/moq.spikes@v4.20.1...v4.20.2
:bug: Fixed bugs:
:hammer: Other:
Add Sponsor button to package readme 💜
Full Changelog: moq/moq.spikes@v4.20.0...v4.20.1
Add setup.Verifiable(Times times, [string failMessage]) method by @stakx in https://github.com/moq/moq/pull/1319
setup.Verifiable(Times times, [string failMessage]) method by @stakx in https://github.com/moq/moq/pull/1319Mock<T>.RaiseAsync by @stakx in https://github.com/moq/moq/pull/1313ThrowsAsync for non-generic ValueTask by @johnthcall in https://github.com/moq/moq/pull/1235mock.Protected().Verify<T>() method overload by @stakx in https://github.com/moq/moq/pull/1325Full Changelog: moq/moq.spikes@v4.18.4...v4.20.0
:hammer: Other:
:twisted_rightwards_arrows: Merged:
Add 💜 SponsorLink support by @kzu in https://github.com/moq/moq/pull/1363
Full Changelog: moq/moq.spikes@v4.20.0-beta...v4.20.0-rc
:hammer: Other:
:twisted_rightwards_arrows: Merged:
Add setup.Verifiable(Times times, [string failMessage]) method by @stakx in https://github.com/moq/moq/pull/1319
setup.Verifiable(Times times, [string failMessage]) method by @stakx in https://github.com/moq/moq/pull/1319Mock<T>.RaiseAsync by @stakx in https://github.com/moq/moq/pull/1313ThrowsAsync for non-generic ValueTask by @johnthcall in https://github.com/moq/moq/pull/1235mock.Protected().Verify<T>() method overload by @stakx in https://github.com/moq/moq/pull/1325Full Changelog: moq/moq.spikes@v4.18.4...v4.20.0-beta
<!-- Release notes generated using configuration in .github/release.yml at main -->
<!-- Release notes generated using configuration in .github/release.yml at main -->
setup.Verifiable(Times times, [string failMessage]) method by @stakx in https://github.com/moq/moq/pull/1319Mock<T>.RaiseAsync by @stakx in https://github.com/moq/moq/pull/1313ThrowsAsync for non-generic ValueTask by @johnthcall in https://github.com/moq/moq/pull/1235mock.Protected().Verify<T>() method overload by @stakx in https://github.com/moq/moq/pull/1325Full Changelog: https://github.com/moq/moq/compare/v4.18.4...v4.20.0-alpha
:sparkles: Implemented enhancements:
RaiseAsync method for raising Func<..., Task> events? #1310setup.Verifiable(Times times, [string failMessage]) method #1319 (@stakx):bug: Fixed bugs:
:hammer: Other:
System.TypeLoadException : Could not load type 'Castle.Core.Internal.CollectionExtensions' from assembly 'Castle.Core, Version=5.0.0.0 after updating to Moq 4.18.4 #1320:twisted_rightwards_arrows: Merged:
mock.Protected().Verify<T>() method overload #1325 (@stakx)Mock<T>.RaiseAsync #1313 (@stakx)ThrowsAsync for non-generic ValueTask #1235 (@johnthcall)Update package reference to Castle.Core (DynamicProxy) from version 5.1.0 to 5.1.1 (@stakx, #1317)
Castle.Core (DynamicProxy) from version 5.1.0 to 5.1.1 (@stakx, #1317):sparkles: Implemented enhancements:
:bug: Fixed bugs:
IndexOutOfRangeException #1252:hammer: Other:
MissingMethodException when using new C# language features (in parameters, init-only setters, etc.) with generic methods, or with members in generic types #1148:twisted_rightwards_arrows: Merged:
SetupAllProperties crashes when invoked on a Mock subclass (@mo-russo, #1278)
SetupAllProperties crashes when invoked on a Mock<T> subclass (@mo-russo, #1278):bug: Fixed bugs:
SetupAllProperties crashes when invoked on a Mock<T> subclass #1278:hammer: Other:
in keyword parameter does not match #1292:twisted_rightwards_arrows: Merged:
StubbedPropertiesSetup figure out type parameter in a less fragile way #1281 (@stakx)Update package reference to Castle.Core (DynamicProxy) from version 5.0.0 to 5.1.0 (@stakx, #1275)
Castle.Core (DynamicProxy) from version 5.0.0 to 5.1.0 (@stakx, #1275)System.Threading.Tasks.Extensions for netstandard2.1 and net6.0 (@tibel, #1274).Raises() with redeclared event (@howcheng, #1175)MissingMethodException when mocking interface with sealed default implementation (@pjquirk, #1209)TypeLoadException on mock when a record has a base record on .NET 6 (@tgrieger-sf, #1273):bug: Fixed bugs:
:hammer: Other:
:twisted_rightwards_arrows: Merged:
record type support #1275 (@stakx)Regression with lazy evaluation of It.Is predicates in setup expressions after updating from 4.13.1 to 4.16.1 (@b3go, #1217)
It.Is predicates in setup expressions after updating from 4.13.1 to 4.16.1 (@b3go, #1217)SetupProperty where Moq fails to match a property accessor implementation against its definition in an interface (@Naxemar, #1248).Result vs without (@cyungmann, #1253):sparkles: Implemented enhancements:
:bug: Fixed bugs:
:hammer: Other:
:twisted_rightwards_arrows: Merged:
Using [...] an old version of System.Net.Http which is vulnerable to "DoS", "Spoofing", "Privilege Escalation", "Authentication Bypass" and "Informati…
New major version of DynamicProxy (you may get better performance!), so please update with care.
Castle.Core (DynamicProxy) from version 4.4.1 to 5.0.0 (@stakx, #1257)net45 to net462net6.0 TFMSystem.Net.Http which is vulnerable to "DoS", "Spoofing", "Privilege Escalation", "Authentication Bypass" and "Information Exposure" (@sidseter, #1219)CallBase and DefaultValue.Mock configured (@IanKemp, #1249):bug: Fixed bugs:
CallBase and DefaultValue.Mock configured #1249:hammer: Other:
:twisted_rightwards_arrows: Merged:
Regression: Property stubs not working on sub mock (@aaronburro, #1240)
:bug: Fixed bugs:
:hammer: Other:
success condition parameter in When. #1237:twisted_rightwards_arrows: Merged:
SetupProperty work with recursive expressions again #1241 (@stakx)SetupSet, VerifySet methods for mock.Protected().As<>() (@tonyhallett, #1165)
SetupSet, VerifySet methods for mock.Protected().As<>() (@tonyhallett, #1165)Throws method overloads that allow specifying a function with or without parameters, to provide an exception, for example .Throws(() => new InvalidOperationException())
and Setup(x => x.GetFooAsync(It.IsAny<string>()).Result).Throws((string s) => new InvalidOperationException(s)). (@adam-knights, #1191)Castle.Core (DynamicProxy) from version 4.4.0 to 4.4.1 (@stakx, #1233)_ for It.IsAny<>() (@adamfk, #1199)mock.Protected() setup methods fail when argument is of type Expression (@tonyhallett, #1189)Protected().SetupSet() ... VerifySet (@tonyhallett, #1186)mock.Protected().As<>() (@tonyhallett, #1185)Verify fail when it should not (@evilc0, #1225)Mock.Of (@stakx, #1066)SetupAllProperties causes mocks to become race-prone (@estrizhok, #1231):bug: Fixed bugs:
Mock.Of #1066:hammer: Other:
:twisted_rightwards_arrows: Merged:
SetupAllProperties #1234 (@stakx)CallBase can now be used with interface methods that have a default interface implementation. It will call the most specific override. (@stakx, #1130)
CallBase can now be used with interface methods that have a default interface implementation. It will call the most specific override. (@stakx, #1130)It.Is lambda expressions that capture local variables. (@bfriesen, #1140)AmbiguousMatchException raised when interface has property indexer besides property in VB. (@mujdatdinc, #1129).Result property (@stakx, #1132)setup.Returns(InvocationFunc) wraps thrown exceptions in TargetInvocationException (@stakx, #1141):sparkles: Implemented enhancements:
:bug: Fixed bugs:
:hammer: Other:
.Result property #1132:twisted_rightwards_arrows: Merged:
Returns(InvocationFunc) doesn't throw TargetInvocationException #1141 (@stakx).Result setups #1133 (@stakx)AmbiguousMatchException when interface has indexer besides property #1131 (@mujdatdinc).CallBase for default interface implementations #1130 (@stakx)Ability to directly set up the .Result of tasks and value tasks, which makes setup expressions more uniform by rendering dedicated async verbs like .R
Ability to directly set up the .Result of tasks and value tasks, which makes setup expressions more uniform by rendering dedicated async verbs like .ReturnsAsync, .ThrowsAsync, etc. unnecessary:
-mock.Setup(x => x.GetFooAsync()).ReturnsAsync(foo)
+mock.Setup(x => x.GetFooAsync().Result).Returns(foo)
This is useful in places where there currently aren't any such async verbs at all:
-Mock.Of<X>(x => x.GetFooAsync() == Task.FromResult(foo))
+Mock.Of<X>(x => x.GetFooAsync().Result == foo)
This also allows recursive setups / method chaining across async calls inside a single setup expression:
-mock.Setup(x => x.GetFooAsync()).ReturnsAsync(Mock.Of<IFoo>(f => f.Bar == bar))
+mock.Setup(x => x.GetFooAsync().Result.Bar).Returns(bar)
or, with only Mock.Of:
-Mock.Of<X>(x => x.GetFooAsync() == Task.FromResult(Mock.Of<IFoo>(f => f.Bar == bar)))
+Mock.Of<X>(x => x.GetFooAsync().Result.Bar == bar)
This should work in all principal setup methods (Mock.Of, mock.Setup…, mock.Verify…). Support in mock.Protected() and for custom awaitable types may be added in the future. (@stakx, #1126)
Performance regression: Adding setups to a mock becomes slower with each setup (@CeesKaas, #1110)
Regression: mock.Verify[All] no longer marks invocations as verified if they were matched by conditional setups. (@Lyra2108, #1114)
:sparkles: Implemented enhancements:
:bug: Fixed bugs:
:hammer: Other:
:twisted_rightwards_arrows: Merged:
IAwaitableFactory) #1125 (@stakx).Verifiable() once again #1121 (@stakx)Upgraded System.Threading.Tasks.Extensions dependency to version 4.5.4 (@JeffAshton, #1108)
System.Threading.Tasks.Extensions dependency to version 4.5.4 (@JeffAshton, #1108):hammer: Other:
:twisted_rightwards_arrows: Merged:
Nothing published for this version
Mocks created by DefaultValue.Mock now inherit SetupAllProperties from their "parent" mock (like it says in the XML documentation) (@stakx, #1074)
DefaultValue.Mock now inherit SetupAllProperties from their "parent" mock (like it says in the XML documentation) (@stakx, #1074)Mock.Of<T>() no longer have their properties stubbed since version 4.14.0 (@vruss, @1071)Verify fails for recursive setups not explicitly marked as Verifiable (@killergege, #1073)Mock.Of<> fails for COM interop types that are annotated with a [CompilerGenerated] custom attribute (@killergege, #1072):sparkles: Implemented enhancements:
:bug: Fixed bugs:
:hammer: Other:
Regression since 4.14.0: setting nested non-overridable properties via Mock.Of (@mariotee, #1039)
Mock.Of (@mariotee, #1039):bug: Fixed bugs:
:hammer: Other:
Microsoft.Build.Tasks.Git.LocateRepository task failed unexpectedly." #1060:twisted_rightwards_arrows: Merged:
Regression since version 4.11.0: VerifySet fails with NullReferenceException for write-only indexers (@Epicycle23, #1036)
VerifySet fails with NullReferenceException for write-only indexers (@Epicycle23, #1036):bug: Fixed bugs:
:twisted_rightwards_arrows: Merged:
Regression: NullReferenceException on subsequent setup if expression contains null reference (@IanYates83, #1031)
NullReferenceException on subsequent setup if expression contains null reference (@IanYates83, #1031):bug: Fixed bugs:
:hammer: Other:
AttributesToAvoidReplicating? #1026:twisted_rightwards_arrows: Merged:
Regression, Part II: Verify behavior change using DefaultValue.Mock (@DesrosiersC, #1024)
Verify behavior change using DefaultValue.Mock (@DesrosiersC, #1024):bug: Fixed bugs:
:twisted_rightwards_arrows: Merged:
DefaultValue.Mock as matched #1027 (@stakx)Regression: Verify behavior change using DefaultValue.Mock (@DesrosiersC, #1024)
Verify behavior change using DefaultValue.Mock (@DesrosiersC, #1024):hammer: Other:
:twisted_rightwards_arrows: Merged:
DefaultValue.Mock should not add redundant setups for already-matched invocations #1025 (@stakx)New SetupSequence verbs .PassAsync() and .ThrowsAsync(...) for async methods with void return type (@fuzzybair, #993)
SetupSequence verbs .PassAsync() and .ThrowsAsync(...) for async methods with void return type (@fuzzybair, #993)StackOverflowException on VerifyAll when mocked method returns mocked object (@hotchkj, #1012):sparkles: Implemented enhancements:
:bug: Fixed bugs:
:hammer: Other:
:twisted_rightwards_arrows: Merged:
A mock's setups can now be inspected and individually verified via the new Mock.Setups collection and IInvocation.MatchingSetup property (@stakx, #984
A mock's setups can now be inspected and individually verified via the new Mock.Setups collection and IInvocation.MatchingSetup property (@stakx, #984-#987, #989, #995, #999)
New .Protected().Setup and Protected().Verify method overloads to deal with generic methods (@JmlSaul, #967)
Two new public methods in Times: bool Validate(int count) and string ToString() (@stakx, 975)
Attempts to mark conditionals setup as verifiable are now considered an error, since conditional setups are ignored during verification. Calls to .Verifiable() on conditional setups are no-ops and can be safely removed. (@stakx, #997)
When matching invocations against setups, captured variables nested inside expression trees are now evaluated. Their values likely matter more than their identities. (@stakx, #1000)
Regression: Restored Capture.In use in mock.Verify(expression, ...) to extract arguments of previously recorded invocations. (@vgriph, #968; @stakx, #974)
Consistency: When mocking a class C whose constructor invokes one of its virtual members, Mock.Of<C>() now operates like new Mock<C>(): a record of such invocations is retained in the mock's Invocations collection (@stakx, #980)
After updating Moq from 4.10.1 to 4.11, mocking NHibernate session throws a System.NullReferenceException (@ronenfe, #955)
:sparkles: Implemented enhancements:
Callback and Returns: Allow callback parameters to have type object where a type matcher was used #953Mock.Setups, part 4: Mock, fluent setup & inner mock discovery #989 (@stakx):bug: Fixed bugs:
:hammer: Other:
:twisted_rightwards_arrows: Merged:
Mock.Setups, part 6: Replace OriginalSetup with simpler OriginalExpression #999 (@stakx)UpgradePropertyAccessorMethods #998 (@stakx)conditionalSetup.Verifiable() an error #997 (@stakx)Mock.Setups, part 5: Simplify fluent setup & inner mock discovery #995 (@stakx)Func<IInvocation,> callback with Returns #992 (@stakx)Mock.Setups, part 3: Individual setup verification #987 (@stakx)SetupAllProperties' setups #986 (@stakx)Mock.Setups, part 2: Match status of setups & invocations #985 (@stakx)Mock.Setups, part 1: Basics #984 (@stakx)Verify(), VerifyAll() #983 (@stakx)Mock.Of<Class> shouldn't delete invocations made from Class' ctor #980 (@stakx)FluentMockVisitor #978 (@stakx)Times.Validate(count) & Times.ToString() #975 (@stakx)Capture.In working again in Verify expressions #974 (@stakx)SetupAllProperties does not recognize property as read-write if only setter is overridden (@stakx, #886)
SetupAllProperties does not recognize property as read-write if only setter is overridden (@stakx, #886)
Regression: InvalidCastException caused by Moq erroneously reusing a cached auto-mocked (DefaultValue.Mock) return value for a different generic method instantiation (@BrunoJuchli, #932)
AmbiguousMatchException when setting up the property, that hides another one (@ishatalkin, #939)
ArgumentException ("Interface not found") when setting up object.ToString on an interface mock (@vslynko, #942)
Cannot "return" to original mocked type after downcasting with Mock.Get and then upcasting with mock.As<> (@pjquirk, #943)
params arrays in recursive setup expressions are matched by reference equality instead of by structural equality (@danielcweber, #946)
mock.SetupProperty throws NullReferenceException when called for partially overridden property (@stakx, #951)
:bug: Fixed bugs:
mock.SetupProperty throws NullReferenceException when called for partially overridden property #951SetupAllProperties does not recognize property as read-write if only setter is overridden #886:hammer: Other:
:twisted_rightwards_arrows: Merged:
SetupProperty for partially overridden properties #952 (@stakx)SetupAllProperties stubs all accessors of partially overridden properties #950 (@stakx)InnerMockSetup (i.e. internal setups for cached return values) match generic args exactly instead of by assignment compatibility. #949 (@stakx)params arrays in setup/verification expressions using structural equality #948 (@stakx)mock.As<> round-tripping #945 (@stakx)InterfaceProxy #944 (@stakx)Improved error message that is supplied with ArgumentException thrown when Setup or Verify are called on a protected method if the method could not be
Improved error message that is supplied with ArgumentException thrown when Setup or Verify 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 not Callback is preceded by a Returns: 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 support for setup and verification of the event handlers through Setup[Add|Remove] and Verify[Add|Remove|All] (@lepijohnny, #825)
Added support for lambda expressions while creating a mock through new Mock<SomeType>(() => new SomeType("a", "b")) and repository.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> — matches T and proper subtypes of TIt.IsValueType — matches only value typesYou can create your own custom type matchers:
[TypeMatcher]
class Either<A, B> : ITypeMatcher
{
public bool Matches(Type type) => type == typeof(A) || type == typeof(B);
}
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, the argument 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 parameter parameterType. (@stakx, #908)
Moq does not mock explicit interface implementation and protected virtual correctly. (@oddbear, #657)
Invocations.Clear() does not cause Verify to fail (@jchessir, #733)
Regression: SetupAllProperties can no longer set up properties whose names start with Item. (@mattzink, #870; @kaan-kaya, #869)
Regression: MockDefaultValueProvider will no longer attempt to set CallBase to true for mocks generated for delegates. (@dammejed, #874)
Verify throws TargetInvocationException instead of MockException 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) throws NullReferenceException instead of producing a completed task with result null (@voroninp, #909)
:sparkles: Implemented enhancements:
:bug: Fixed bugs:
SetupAllProperties resets indexer setups #901:hammer: Other:
:twisted_rightwards_arrows: Merged:
.xdoc XML documentation files #916 (@stakx).ReturnsAsync(null) #915 (@stakx)ParamArrayMatcher #912 (@stakx)Match.Matches and It.IsAny<T> #911 (@stakx)SetupAllProperties indexer regression & refactor accessor check methods for clarity #902 (@stakx)InnerMockSetup on mock.Invocations.Clear() #899 (@stakx)SequenceSetup on mock.Invocations.Clear() #896 (@stakx).editorconfig for auto-generated files #894 (@stakx)Unwrap #885 (@stakx)ExpressionStringBuilder into StringBuilderExtensions #882 (@stakx)ExpressionStringBuilder formatting of ternary conditional operator #881 (@stakx)ExpressionStringBuilder formatting of indexer assignment #880 (@stakx)SetupAllProperties for properties named Item #878 (@stakx)Returns callback delegate validation more strict #876 (@stakx)SetupAllProperties for properties whose name starts with Item #871 (@stakx)mock.Invocations.Clear() remove traces of earlier invocations more thoroughly #854 (@stakx)Improved performance for Mock.Of and mock.SetupAllProperties() as the latter now performs property setups just-in-time, instead of as an ahead-of-time
Mock.Of<T> and mock.SetupAllProperties() as the latter now performs property setups just-in-time, instead of as an ahead-of-time batch operation. (@vanashimko, #826).Returns(…) nor .CallBase() no longer return default(T) for loose mocks, but a value that is consistent with the mock's CallBase and DefaultValue[Provider] settings. (@stakx, #849)sequenceSetup.ReturnsAsync(Func<T>) (@stakx, #841)Mock.Of, Mocks.Of, mockRepository.Of, and mockRepository.OneOf that accept a MockBehavior parameter. (@stakx, #842)Callback to a mock breaks async tests (@marcin-chwedczuk-meow, #702)mock.SetupAllProperties() now setups write-only properties for strict mocks, so that accessing such properties will not throw anymore. (@vanashimko, #836)mock.SetupAllProperties() and Mock.Of<T> fail due to inaccessible property accessors (@Mexe13, #845)VerifyNoOtherCalls causes stack overflow when mock setup returns the mocked object (@bash, #846)Capture.In() no longer captures arguments when other setup arguments do not match (@ocoanet, #844).CaptureMatch no longer invokes the capture callback when other setup arguments do not match (@ocoanet, #844).:sparkles: Implemented enhancements:
:bug: Fixed bugs:
:hammer: Other:
Callback to a mock breaks async tests #702:twisted_rightwards_arrows: Merged:
.Returns nor .CallBase more consistent #849 (@stakx)VerifyNoOtherCalls: Prevent stack overflow by remembering already verified mocks #848 (@stakx)sequenceSetup.ReturnsAsync(Func<T>) #841 (@stakx).nuspec file #832 (@stakx)Same as 4.11.0 Release Candidate 2. See changelog entries for the two pre-release versions.
Same as 4.11.0 Release Candidate 2. See changelog entries for the two pre-release versions.
Debug symbols (Moq.pdb) have moved into a separate NuGet symbol package (as per the current official guideline). If you want the Visual Studio debugge
This is a pre-release version.
Moq.pdb) have moved into a separate NuGet symbol package (as per the current official guideline). If you want the Visual Studio debugger to step into Moq's source code, disable Just My Code, enable SourceLink, and configure NuGet's symbol server. (@stakx, #789)SetupProperty (@stakx, #823):bug: Fixed bugs:
:hammer: Other:
:twisted_rightwards_arrows: Merged:
SetupProperty #824 (@stakx)default(Times) to Times.AtLeastOnce() #820 (@stakx)SetupCollection (esp. ToArrayLive) for better performance #819 (@stakx)bb1840c
This commit was signed with the committer’s verified signature .
stakx Dominique Schuppli
GPG key ID: 093A802C7C9B7B59
Verified Learn about vigilant mode .
This is a pre-release version.
stakx
It contains several minor breaking changes, and there have been extensive internal rewrites in order to fix some very long-standing bugs in relation t…
This is a pre-release version.
It contains several minor breaking changes, and there have been extensive internal rewrites in order to fix some very long-standing bugs in relation to argument matchers in fluent setup expressions.
The library now targets .NET Standard 2.0 instead of .NET Standard 1.x. This has been decided based on the official cross-platform targeting guideline and the End of Life announcement for .NET Core 1.x (@stakx, #784, #785)
Method overload resolution may change for:
mock.Protected().Setup("VoidMethod", ...)mock.Protected().Verify("VoidMethod", ...)mock.Protected().Verify<TResult>("NonVoidMethod", ...)due to a new overload: If the first argument is a bool, make sure that argument gets interpreted as part of args, not as exactParameterMatch (see also Added section below). (@stakx & @Shereef, #751, #753)
mock.Verify[All] now performs a more thorough error aggregation. Error messages of inner/recursive mocks are included in the error message using indentation to show the relationship between mocks. (@stakx, #762)
mock.Verify no longer creates setups, nor will it override existing setups, as a side-effect of using a recursive expression. (@stakx, #765)
More accurate detection of argument matchers with SetupSet and VerifySet, especially when used in fluent setup expressions or with indexers (@stakx, #767)
mock.Verify(expression) error messages now contain a full listing of all invocations that occurred across all involved mocks. Setups are no longer listed, since they are completely irrelevant in the context of call verification. (@stakx, #779, #780)
Indexers used as arguments in setup expressions are now eagerly evaluated, like all other properties already are (except when they refer to matchers) (@stakx, #794)
Update package reference to Castle.Core (DynamicProxy) from version 4.3.1 to 4.4.0 (@stakx, #797)
New method overloads:
mock.Protected().Setup("VoidMethod", exactParameterMatch, args)mock.Protected().Verify("VoidMethod", times, exactParameterMatch, args)mock.Protected().Verify<TResult>("NonVoidMethod", times, exactParameterMatch, args)having a bool exactParameterMatch parameter. Due to method overload resolution, it was easy to think this already existed when in fact it did not, leading to failing tests. (@Shereef & @stakx, #753, #751)
Ability in mock.Raise and setup.Raises to raise events on sub-objects (inner mocks) (@stakx, #772)
InvalidOperationException when specifiying setup on mock with mock containing property of type Nullable<T> (@dav1dev, #725)Verify gets confused between the same generic and non-generic signature (@lepijohnny, #749)Verify despite being "unreachable" (@stakx, #703)Verify can create setups that cause subsequent VerifyAll to fail (@stakx & @lepijohnny, #699)mock.Raise throws (@MutatedTomato, #738)Mock.Raise only raises events on root object (@hallipr, #166)It.IsAny() as the value, even if given in the indexer argument (@idigra, #696)VerifySet fails on non-trivial property setup (@TimothyHayes, #430)SetupSet 'forgets' method setup (@TimothyHayes, #432)Verify[All] fails because of lazy (instead of eager) setup argument expression evaluation (@aeslinger, #711)ArgumentOutOfRangeException when setup expression contains indexer access (@mosentok, #714)Times.Equals (@stakx, #805):sparkles: Implemented enhancements:
mock.Protected().Verify method group has no overloads with bool exactParameterMatch #752:bug: Fixed bugs:
Times.Equals is implemented incorrectly #805VerifyAll throws System.InvalidOperationException: 'Nullable object must have a value.' #711Verify despite being "unreachable" #703Verify can create setups that causes a subsequent VerifyAll to fail #699:hammer: Other:
in string parameter verifying doesn't work in some cases #808[Matcher] attribute? #770Verify #756:twisted_rightwards_arrows: Merged:
Times.Equals #806 (@stakx)MockFactory and MockRepository APIs #800 (@stakx)InvocationShape argument matchers & expressions in sync #793 (@stakx)ConstantMatcher more (but not fully) StackOverflowException-proof #792 (@stakx)MatcherAttribute #788 (@stakx)stringBuilder.AppendValueOf safer #786 (@stakx)netstandard2.0 target #784 (@stakx)ActionObserver improved support for parameterized base class ctors & additional virtual calls #782 (@stakx)It.IsAny by default #780 (@stakx)Verify(...) error message #779 (@stakx)Verify expression validation #778 (@stakx)InvocationShape should be equality-comparable #777 (@stakx)LambdaExpressionPart with InvocationShape #776 (@stakx)AmbientObserver into MatcherObserver #775 (@stakx)Raise #771 (@stakx)AmbientObserver reentrant #769 (@stakx)MatchExpression more robust #768 (@stakx)SetupSet and VerifySet expressions from delegates #767 (@stakx)IProxy interface visibility #766 (@stakx)Setup and Verify & make them recursive #765 (@stakx)System.Object members interceptable by *any* interceptor #764 (@stakx)Mock.InnerMocks with InnerMockSetup #760 (@stakx)CONTRIBUTING.md #754 (@stakx)mock.Protected().Verify overloads with additional exactParameterMatch parameter #753 (@Shereef)mock.Protected().Setup() method overload #751 (@stakx)[Matcher] attribute #732 (@stakx)NullReferenceException when using SetupSet on indexers with multiple parameters (@idigra, #694)
NullReferenceException when using SetupSet on indexers with multiple parameters (@idigra, #694)CallBase should not be allowed for delegate mocks (@tehmantra, #706)System.ValueTuple NuGet package, at no functional cost (i.e. value tuples are still supported just fine) (@stakx, #721)System.Reflection.TypeExtensions and System.Threading.Tasks.Extensions dependencies to versions 4.5.1 (@stakx, #729):sparkles: Implemented enhancements:
:bug: Fixed bugs:
CallBase should not be allowed for delegate mocks #706:hammer: Other:
net45 target causes major build issues in .NET Framework 4.7 projects #719:twisted_rightwards_arrows: Merged:
HandleTracking interception aspect into RecordInvocation #723 (@stakx)FluentMockContext to record >1 matcher per invocation #722 (@stakx)System.ValueTuple NuGet dependency #721 (@stakx)IsSpecialName for properties & indexers #718 (@stakx)MethodCallReturn into MethodCall #717 (@stakx)Mock methods non-generic #716 (@stakx)CallBase should not be allowed for delegate mocks #708 (@m-wild)Mock.DelegateInterfaceMethod #705 (@stakx)FluentMockVisitor classes #698 (@stakx)Breaking change: VerifyAll now succeeds after a call to SetupAllProperties even when not all property accessors were invoked (stakx, #684)
ExpressionCompiler: An extensibility point for setting up alternate LINQ expression tree compilation strategies (@stakx, #647)setup.CallBase() for void methods (@stakx, #664)VerifyNoOtherCalls for MockRepository (@BlythMeister, #682)VerifyNoOtherCalls take into account previous calls to parameterless Verify() and VerifyAll() (@stakx, #659)VerifyAll now succeeds after a call to SetupAllProperties even when not all property accessors were invoked (stakx, #684)out parameter detection for mocking COM interfaces with [in,out] parameters (@koutinho, #645)Returns callback methods that have been compiled from Expressions (@stakx, #654)Verify exception should report configured setups for delegate mocks (@stakx, #679)Verify exception should include complete call expression for delegate mocks (@stakx, #680)VerifyAll fail" (@stakx, #684)VerifyAll behavior" (@stakx, #684):sparkles: Implemented enhancements:
mock.Verify(m => m.Event += callback)) #49:bug: Fixed bugs:
.Callback(…) after .Returns(…) / .CallBase() causes a variety of issues #668.Throws() is specified too #667VerifyAll fail #556Action<...> instead of Expression<Action<...>> in the public API causes a variety of problems #414:hammer: Other:
:twisted_rightwards_arrows: Merged:
MockFactory.VerifyMocks do what it says it does #691 (@stakx)License.txt so GitHub recognizes it #687 (@stakx)VerifyAll ignore setups from SetupAllProperties #684 (@stakx)Verify exception should include complete call expression for delegate mocks #680 (@stakx)Verify exception should report configured setups for delegate mocks #679 (@stakx)VerifyAll + VerifyNoOtherCalls for sequence setups #672 (@stakx)Setup #671 (@stakx)setup.CallBase() for void methods #664 (@stakx)MethodCall classes non-generic #663 (@stakx)InvocationShape #662 (@stakx)MatcherFactory #661 (@stakx)VerifyNoOtherCalls take into account previous calls to parameterless Verify() and VerifyAll() #659 (@stakx)Returns #654 (@stakx)mock.ResetCalls() has been deprecated in favor of mock.Invocations.Clear() (@stakx, #633)
Mock.Invocations property to support inspection of invocations on a mock (@Tragedian, #560)Castle.Core (DynamicProxy) from version 4.3.0 to 4.3.1 (@stakx, #635)CallBase disregarded for some base methods from non-public interfaces (@stakx, #641)mock.ResetCalls() has been deprecated in favor of mock.Invocations.Clear() (@stakx, #633):sparkles: Implemented enhancements:
:bug: Fixed bugs:
:hammer: Other:
:twisted_rightwards_arrows: Merged:
System.Reflection.Emit #638 (@stakx)MockException (and deprecate IError along the way) #634 (@stakx)IInvocation and IInvocationList #633 (@stakx).StripConversion helper method #631 (@stakx).ToLambda() conversions with static typing #629 (@stakx)Breaking change: All ReturnsAsync and ThrowsAsync setup methods now consistently return a new Task on each invocation (@snrnats, #595)
ISetupSequentialResult<TResult>.Returns method overload that support delegate for deferred results (@snrnats, #594)in parameter modifier (@stakx, #624, #625)ReturnsAsync and ThrowsAsync for sequential setups of methods returning a ValueTask (@stakx, #626)ReturnsAsync and ThrowsAsync setup methods now consistently return a new Task on each invocation (@snrnats, #595)Mock.Of<T>() by approx. one order of magnitude (@informatorius, #598)Castle.Core (DynamicProxy) from version 4.2.1 to 4.3.0 (@stakx, #624)ReturnsExtensions.ThrowsAsync() can cause UnobservedTaskException (@snrnats, #595)ReturnsAsync and ThrowsAsync with delay parameter starts timer at setup (@snrnats, #595)Returns regression with null function callback (@Caraul, #602):sparkles: Implemented enhancements:
in ValueType parameters are not supported with .NET Standard / Core #605ReturnsAsync and ThrowsAsync for ValueTask<TResult> #599:bug: Fixed bugs:
:hammer: Other:
Mock.Of<T>() is much slower than new Mock<T> (up to several orders of magnitude) #547CONTRIBUTING.md #471:twisted_rightwards_arrows: Merged:
in parameter modifier is supported #625 (@stakx)ISetupSequentialResult<TResult>.Returns method overload that support delegate for deferred results #594 (@snrnats)Upgraded System.ValueTuple dependency to version 4.4.0 in order to reestablish Moq compatibility with .NET 4.7 (and later), which already include the
System.ValueTuple dependency to version 4.4.0 in order to reestablish Moq compatibility with .NET 4.7 (and later), which already include the ValueTuple types (@stakx, #591)Callback and Returns (@Caraul, #575)CallBase regression with members of additional interfaces (@stakx, #583):bug: Fixed bugs:
:hammer: Other:
:twisted_rightwards_arrows: Merged:
C# 7 tuple support for DefaultValue.Empty and DefaultValue.Mock (@stakx, #563)
DefaultValue.Empty and DefaultValue.Mock (@stakx, #563)System.Threading.Tasks.Extensions and System.ValueTuple dependencies to versions 4.3.0 as suggested by @tothdavid in order to improve Moq compatibility with .NET 4.6.1 / help prevent MissingMethodException and similar (@stakx, #571)CallBase regression with explicitly implemented interface methods (@stakx, #558):sparkles: Implemented enhancements:
:bug: Fixed bugs:
:hammer: Other:
:twisted_rightwards_arrows: Merged:
DefaultValue.Empty and DefaultValue.Mock #563 (@stakx)CallBase regression with explicitly implemented interface methods #558 (@stakx)Same as 4.8.0 Release Candidate 1, plus some significant speed improvements.
Same as 4.8.0 Release Candidate 1, plus some significant speed improvements.
SetupAllProperties now fully supports property type recursion / loops in the object graph, thanks to deferred property initialization (@stakx, #550):sparkles: Implemented enhancements:
Setup #479Setup / Returns #445ValueTask<TResult> to DefaultValue.Empty #529 (@stakx):bug: Fixed bugs:
mock.Verify and mock.VerifyAll leak internal MockVerificationException type #507SetupAllProperties tries to set up inaccessible properties #498Setup does not recognize all virtual sealed methods as uninterceptable #496add_X or remove_X are not recorded #487:hammer: Other:
MethodCall.ToString and MethodCall.Format, and whether we can drop one of them (ideally including MethodCall.SetFileInfo) #503[AssemblyVersion] to major version only (4.0.0.0) to save users from having to configure assembly version redirects #424:twisted_rightwards_arrows: Merged:
SetupAllProperties: Defer property initialization #550 (@stakx)SetupAllProperties #549 (@stakx)VerifyNoOtherCalls: fix bugs with multi-dot expressions #544 (@stakx)VerifyNoOtherCalls: Fix bugs with Mock.Of<T> #543 (@stakx)FluentMockContext #542 (@stakx)ImplementedInterfaces contraption #541 (@stakx)Mock into Mock<T> #540 (@stakx)Mock<T>.VerifyNoOtherCalls() method #539 (@stakx)ref parameters using It.Ref<TValue>.IsAny / ItExpr.Ref<TValue>.IsAny #537 (@stakx)LookupOrFallbackDefaultValueProvider base class for custom default value providers #536 (@stakx)Empty, Mock properties to DefaultValueProvider #535 (@stakx)Mock.Of setup expression #528 (@stakx)EmptyDefaultValueProvider to use dictionary lookup for special type handling #524 (@stakx)Returns more strictly #520 (@stakx)MockVerificationException and catch-throw-recatch cycle during verification #511 (@stakx)Interceptor.calls, ExpressionKey, and SetupKind #509 (@stakx)PexProtector out of the debugger's way #508 (@stakx)DefaultValue.Mock to mock Task<TMockable> and ValueTask<TMockable> #502 (@stakx)Protected().As<T>(): Fix generic method support #501 (@stakx)SetupAllProperties skip inaccessible methods #499 (@stakx)Setup recognition logic for sealed methods #497 (@stakx).Protected().As<TDuck>() to perform duck-typed setup and verification of protected members #495 (@stakx)SetupSequence method group for protected members #493 (@stakx)SetupSequence to make it thread-safe #476 (@stakx)Callback and Returns overloads for setting up methods with ref parameters #468 (@stakx)Breaking change: SetupSequence now overrides pre-existing setups like all other Setup methods do. This means that exhausted sequences no longer fall b…
This is a pre-release version.
void methods (@alexbestul, #463)SetupSequence) of protected members (@stakx, #493)ref or out parameters via two new overloads of Callback and Returns (@stakx, #468)mock.Protected().As<TAnalog>() interface (@stakx, #495, #501)ValueTask<TResult> when using the ReturnsAsync extension methods, similar to Task<TResult> (@AdamDotNet, #506)ValueTask<TResult> with DefaultValue.Empty (@stakx, #529)DefaultValue.Empty and DefaultValue.Mock:
Implement custom providers by subclassing either DefaultValueProvider or LookupOrFallbackDefaultValueProvider,
install them by setting Mock[Repository].DefaultValueProvider (@stakx, #533, #536)DefaultValue.Mock to mock Task<TMockable> and ValueTask<TMockable> (@stakx, #502)ref parameters with It.Ref<T>.IsAny (or ItExpr.Ref<T>.IsAny for protected methods) as you would with It.IsAny<T>() for regular parameters (@stakx, #537)Mock.VerifyNoOtherCalls() to check whether all expected invocations have been verified -- can be used as an alternative to MockBehavior.Strict (@stakx, #539)SetupSequence now overrides pre-existing setups like all other Setup methods do. This means that exhausted sequences no longer fall back to previous setups to produce a "default" action or return value. (@stakx, #476)Returns are validated a little more strictly than before (return type and parameter count must match with method being set up) (@stakx, #520)major.minor.0.0 to help prevent assembly version conflicts and to reduce the need for binding redirects (@stakx, #554)SetupSequence are now thread-safe (@stakx, #476)add_X, remove_X) so they can be verified (@stakx, #488)Setup throws when an attempt is made to set one up (@stakx, #497)SetupAllProperties skip inaccessible methods (@stakx, #499)IEnumerable<T> (@stakx, #510)MockVerificationException type; remove it (@stakx, #511)Mock.Of setup expression (@stakx, #528)[Matcher] has been deprecated in favor of Match.Create (@stakx, #514):sparkles: Implemented enhancements:
Mock<T>.Raise #457:hammer: Other:
:sparkles: Implemented enhancements:
:sparkles: Implemented enhancements:
:hammer: Other:
:twisted_rightwards_arrows: Merged:
Upgrade Castle Core package dependency to next released version \#470
:bug: Fixed bugs:
:hammer: Other:
:twisted_rightwards_arrows: Merged:
Upgrade to Castle.Core version 4.2.0 \#425
:bug: Fixed bugs:
:hammer: Other:
:twisted_rightwards_arrows: Merged:
:sparkles: Implemented enhancements:
:sparkles: Implemented enhancements:
:bug: Fixed bugs:
mock.SetupGet(o => o.Property).CallBase(), strict mocks throw, demanding that the setup provide a return value #448:hammer: Other:
:twisted_rightwards_arrows: Merged:
.CallBase() can set up a return value, too #450 (@stakx)SetupAllProperties work correctly for same-typed sibling properties #442 (@stakx):sparkles: Implemented enhancements:
:sparkles: Implemented enhancements:
:bug: Fixed bugs:
:hammer: Other:
:twisted_rightwards_arrows: Merged:
Times in Verify messages #420 (@stakx)ExtractProxyCall #415 (@stakx)Resources.resx #403 (@stakx)Mock<T>.Raise to raise events on child mocks #397 (@stakx)Mock.Of #396 (@stakx)CallBase is true #395 (@stakx)Interceptor more thread-safe #392 (@stakx)Possibly undocumented breaking change in 4.2.1408.0511 \#315
:sparkles: Implemented enhancements:
:bug: Fixed bugs:
:hammer: Other:
:twisted_rightwards_arrows: Merged:
Interface inheritance introduced a possible breaking change in 4.2.1408.619 \#371
:sparkles: Implemented enhancements:
:bug: Fixed bugs:
:hammer: Other:
:twisted_rightwards_arrows: Merged:
:twisted_rightwards_arrows: Merged:
:twisted_rightwards_arrows: Merged:
Moq.nuspec and package references #379 (@stakx)Clean up the mess of mixed tabs & spaces in code files \#364
:hammer: Other:
:twisted_rightwards_arrows: Merged:
It.IsAny, It.IsNotNull work for COM types #361 (@stakx)ExpressionMatcher.Matches #358 (@stakx)ThrowsAsync overload for non-generic Task #357 (@stakx)Documentation Correction around using Verify\(\) \#332
:hammer: Other:
:twisted_rightwards_arrows: Merged:
Small grammar correction in documentation \#260
:twisted_rightwards_arrows: Merged:
Passing a mock into another mock does not work for me \#174
The dependency Moq \>= 4.7.8 could not be resolved \#339
:hammer: Other:
Protected Verify doesn't accept mocks of interfaces as valid for those interfaces \#334
:hammer: Other:
:twisted_rightwards_arrows: Merged:
:twisted_rightwards_arrows: Merged:
One column per quarter.