All notable changes to this project will be documented in this file.
The format is loosely based on Keep a Changelog.
Mock<T>.RaiseAsync
method for raising "async" events, i.e. events that use aFunc<..., Task>
orFunc<..., ValueTask>
delegate. (@stakx, #1313)setup.Verifiable(Times times, [string failMessage])
method to specify the expected number of calls upfront.mock.Verify[All]
can then be used to check whether the setup was called that many times. The upper bound (maximum allowed number of calls) will be checked right away, i.e. whenever a setup gets called. (@stakx, #1319)- Add
ThrowsAsync
methods for non-genericValueTask
(@johnthcall, #1235)
- Verifying a protected generic method that returns a value is broken (@nthornton2010, #1314)
- Update package reference to
Castle.Core
(DynamicProxy) from version 5.1.0 to 5.1.1 (@stakx, #1317)
SetupAllProperties
crashes when invoked on aMock<T>
subclass (@mo-russo, #1278)
- Update package reference to
Castle.Core
(DynamicProxy) from version 5.0.0 to 5.1.0 (@stakx, #1275) - Removed dependency on
System.Threading.Tasks.Extensions
fornetstandard2.1
andnet6.0
(@tibel, #1274)
- "Expression is not an event add" when using
.Raises()
with redeclared event (@howcheng, #1175) MissingMethodException
when mocking interface with sealed default implementation (@pjquirk, #1209)- Throws
TypeLoadException
on mock when a record has a base record on .NET 6 (@tgrieger-sf, #1273)
- Regression with lazy evaluation of
It.Is
predicates in setup expressions after updating from 4.13.1 to 4.16.1 (@b3go, #1217) - Regression with
SetupProperty
where Moq fails to match a property accessor implementation against its definition in an interface (@Naxemar, #1248) - Difference in behavior when mocking async method using
.Result
vs without (@cyungmann, #1253)
New major version of DynamicProxy (you may get better performance!), so please update with care.
- Update package reference to
Castle.Core
(DynamicProxy) from version 4.4.1 to 5.0.0 (@stakx, #1257) - Adjusted our target frameworks to match DynamicProxy's (see their discussion about which frameworks to target):
- minimum .NET Framework version raised from
net45
tonet462
- additional
net6.0
TFM
- minimum .NET Framework version raised from
- Can't set up "private protected" properties (@RobSiklos, #1170)
- Using [...] an old version of
System.Net.Http
which is vulnerable to "DoS", "Spoofing", "Privilege Escalation", "Authentication Bypass" and "Information Exposure" (@sidseter, #1219) - Failure when invoking a method with by-ref parameter & mockable return type on a mock with
CallBase
andDefaultValue.Mock
configured (@IanKemp, #1249)
- Regression: Property stubs not working on sub mock (@aaronburro, #1240)
SetupSet
,VerifySet
methods formock.Protected().As<>()
(@tonyhallett, #1165)- New
Throws
method overloads that allow specifying a function with or without parameters, to provide an exception, for example.Throws(() => new InvalidOperationException())
andSetup(x => x.GetFooAsync(It.IsAny<string>()).Result).Throws((string s) => new InvalidOperationException(s))
. (@adam-knights, #1191)
- Update package reference to
Castle.Core
(DynamicProxy) from version 4.4.0 to 4.4.1 (@stakx, #1233)
- The guard against unmatchable matchers (added in #900) was too strict; relaxed it to enable an alternative user-code shorthand
_
forIt.IsAny<>()
(@adamfk, #1199) mock.Protected()
setup methods fail when argument is of typeExpression
(@tonyhallett, #1189)- Parameter is invalid in
Protected().SetupSet()
...VerifySet
(@tonyhallett, #1186) - Virtual properties and automocking not working for
mock.Protected().As<>()
(@tonyhallett, #1185) - Issue mocking VB.NET class with overloaded property/indexer in base class (@myurashchyk, #1153)
- Equivalent arrays don't test equal when returned from a method, making
Verify
fail when it should not (@evilc0, #1225) - Property setups are ignored on mocks instantiated using
Mock.Of
(@stakx, #1066) SetupAllProperties
causes mocks to become race-prone (@estrizhok, #1231)
This version was skipped due to an intermittent NuGet publishing issue.
CallBase
can now be used with interface methods that have a default interface implementation. It will call the most specific override. (@stakx, #1130)
- Improved error message formatting of
It.Is
lambda expressions that capture local variables. (@bfriesen, #1140)
AmbiguousMatchException
raised when interface has property indexer besides property in VB. (@mujdatdinc, #1129)- Interface default methods are ignored (@hahn-kev, #972)
- Callback validation too strict when setting up a task's
.Result
property (@stakx, #1132) setup.Returns(InvocationFunc)
wraps thrown exceptions inTargetInvocationException
(@stakx, #1141)
-
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 inmock.Protected()
and for custom awaitable types may be added in the future. (@stakx, #1126)
- Attempts to mark conditionals setup as verifiable are once again allowed; it turns out that forbidding it (as was done in #997 for version 4.14.0) is in fact a regression. (@stakx, #1121)
-
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)
- Upgraded
System.Threading.Tasks.Extensions
dependency to version 4.5.4 (@JeffAshton, #1108)
- New method overloads for
It.Is
,It.IsIn
, andIt.IsNotIn
that compare values using a customIEqualityComparer<T>
(@weitzhandler, #1064) - New properties
ReturnValue
andException
onIInvocation
to query recorded invocations return values or exceptions (@MaStr11, #921, #1077) - Support for "nested" type matchers, i.e. type matchers that appear as part of a composite type (such as
It.IsAnyType[]
orFunc<It.IsAnyType, bool>
). Argument match expressions likeIt.IsAny<Func<It.IsAnyType, bool>>()
should now work as expected, whereas they previously didn't. In this particular example, you should no longer need a workaround like(Func<It.IsAnyType, bool>)It.IsAny<object>()
as originally suggested in #918. (@stakx, #1092)
- Event accessor calls (
+=
and-=
) now get consistently recorded inMock.Invocations
. This previously wasn't the case for backwards compatibility withVerifyNoOtherCalls
(which got implemented before it was possible to check them usingVerify{Add,Remove}
). You now need to explicitly verify expected calls to event accessors prior toVerifyNoOtherCalls
. Verification of+=
and-=
now works regardless of whether or not you set those up (which makes it consistent with how verification usually works). (@80O, @stakx, #1058, #1084) - Portable PDB (debugging symbols) are now embedded in the main library instead of being published as a separate NuGet symbols package (`.snupkg) (@kzu, #1098)
SetupProperty
fails if property getter and setter are not both defined in mocked type (@stakx, #1017)- Expression tree argument not matched when it contains a captured variable – evaluate all captures to their current values when comparing two expression trees (@QTom01, #1054)
- Failure when parameterized
Mock.Of<>
is used in query comprehensionfrom
clause (@stakx, #982)
This version was accidentally published as 4.15.1 due to an intermittent problem with NuGet publishing.
- Mocks created by
DefaultValue.Mock
now inheritSetupAllProperties
from their "parent" mock (like it says in the XML documentation) (@stakx, #1074)
- Setup not triggered due to VB.NET transparently inserting superfluous type conversions into a setup expression (@InteXX, #1067)
- Nested mocks created by
Mock.Of<T>()
no longer have their properties stubbed since version 4.14.0 (@vruss, @1071) Verify
fails for recursive setups not explicitly marked asVerifiable
(@killergege, #1073)Mock.Of<>
fails for COM interop types that are annotated with a[CompilerGenerated]
custom attribute (@killergege, #1072)
- Regression since 4.14.0: setting nested non-overridable properties via
Mock.Of
(@mariotee, #1039)
- Regression since version 4.11.0:
VerifySet
fails withNullReferenceException
for write-only indexers (@Epicycle23, #1036)
- Regression:
NullReferenceException
on subsequent setup if expression contains null reference (@IanYates83, #1031)
- Regression, Part II:
Verify
behavior change usingDefaultValue.Mock
(@DesrosiersC, #1024)
- Regression:
Verify
behavior change usingDefaultValue.Mock
(@DesrosiersC, #1024)
- New
SetupSequence
verbs.PassAsync()
and.ThrowsAsync(...)
for async methods withvoid
return type (@fuzzybair, #993)
StackOverflowException
onVerifyAll
when mocked method returns mocked object (@hotchkj, #1012)
-
A mock's setups can now be inspected and individually verified via the new
Mock.Setups
collection andIInvocation.MatchingSetup
property (@stakx, #984-#987, #989, #995, #999) -
New
.Protected().Setup
andProtected().Verify
method overloads to deal with generic methods (@JmlSaul, #967) -
Two new public methods in
Times
:bool Validate(int count)
andstring 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 inmock.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 likenew Mock<C>()
: a record of such invocations is retained in the mock'sInvocations
collection (@stakx, #980) -
After updating Moq from 4.10.1 to 4.11, mocking NHibernate session throws a
System.NullReferenceException
(@ronenfe, #955)
-
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 upobject.ToString
on an interface mock (@vslynko, #942) -
Cannot "return" to original mocked type after downcasting with
Mock.Get
and then upcasting withmock.As<>
(@pjquirk, #943) -
params
arrays in recursive setup expressions are matched by reference equality instead of by structural equality (@danielcweber, #946) -
mock.SetupProperty
throwsNullReferenceException
when called for partially overridden property (@stakx, #951)
-
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 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 types
You 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
, 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)
-
-
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)
- Improved performance for
Mock.Of<T>
andmock.SetupAllProperties()
as the latter now performs property setups just-in-time, instead of as an ahead-of-time batch operation. (@vanashimko, #826) - Setups with no
.Returns(…)
nor.CallBase()
no longer returndefault(T)
for loose mocks, but a value that is consistent with the mock'sCallBase
andDefaultValue[Provider]
settings. (@stakx, #849)
- New method overload
sequenceSetup.ReturnsAsync(Func<T>)
(@stakx, #841) - LINQ to Mocks support for strict mocks, i.e. new method overloads for
Mock.Of
,Mocks.Of
,mockRepository.Of
, andmockRepository.OneOf
that accept aMockBehavior
parameter. (@stakx, #842)
- Adding
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)- Regression:
mock.SetupAllProperties()
andMock.Of<T>
fail due to inaccessible property accessors (@Mexe13, #845) - Regression:
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).
Same as 4.11.0-rc2. See changelog entries for the below two pre-release versions.
This is a pre-release version.
- Debug symbols (
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)
- Regression: Unhelpful exception message when setting up an indexer with
SetupProperty
(@stakx, #823)
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 ofargs
, not asexactParameterMatch
(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
andVerifySet
, 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
andsetup.Raises
to raise events on sub-objects (inner mocks) (@stakx, #772)
- Pex interop (which has not been maintained for years). You might notice changes when using Visual Studio's IntelliTest feature. (@stakx, #786)
- Setting multiple indexed object's property directly via LINQ fails (@TylerBrinkley, #314)
InvalidOperationException
when specifiying setup on mock with mock containing property of typeNullable<T>
(@dav1dev, #725)Verify
gets confused between the same generic and non-generic signature (@lepijohnny, #749)- Setup gets included in
Verify
despite being "unreachable" (@stakx, #703) Verify
can create setups that cause subsequentVerifyAll
to fail (@stakx & @lepijohnny, #699)- Incomplete stack trace when raising an event with
mock.Raise
throws (@MutatedTomato, #738) Mock.Raise
only raises events on root object (@hallipr, #166)- Mocking indexer captures
It.IsAny()
as the value, even if given in the indexer argument (@idigra, #696) VerifySet
fails on non-trivial property setup (@TimothyHayes, #430)- Use of
SetupSet
'forgets' method setup (@TimothyHayes, #432) - Recursive mocks don't work with argument matching (@thalesmello, #142)
- Recursive property setup overrides previous setups (@jamesfoster, #110)
- Formatting of enumerable object for error message broke EF Core test case (@MichaelSagalovich, #741)
Verify[All]
fails because of lazy (instead of eager) setup argument expression evaluation (@aeslinger, #711)ArgumentOutOfRangeException
when setup expression contains indexer access (@mosentok, #714)- Incorrect implementation of
Times.Equals
(@stakx, #805)
NullReferenceException
when usingSetupSet
on indexers with multiple parameters (@idigra, #694)CallBase
should not be allowed for delegate mocks (@tehmantra, #706)
- Dropped the dependency on the
System.ValueTuple
NuGet package, at no functional cost (i.e. value tuples are still supported just fine) (@stakx, #721) - Updated failure messages to show richer class names (@powerdude, #727)
- Upgraded
System.Reflection.TypeExtensions
andSystem.Threading.Tasks.Extensions
dependencies to versions 4.5.1 (@stakx, #729)
ExpressionCompiler
: An extensibility point for setting up alternate LINQ expression tree compilation strategies (@stakx, #647)setup.CallBase()
forvoid
methods (@stakx, #664)VerifyNoOtherCalls
forMockRepository
(@BlythMeister, #682)
- Make
VerifyNoOtherCalls
take into account previous calls to parameterlessVerify()
andVerifyAll()
(@stakx, #659) - Breaking change:
VerifyAll
now succeeds after a call toSetupAllProperties
even when not all property accessors were invoked (stakx, #684)
- More precise
out
parameter detection for mocking COM interfaces with[in,out]
parameters (@koutinho, #645) - Prevent false 'Different number of parameters' error with
Returns
callback methods that have been compiled fromExpression
s (@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)- Bug report #556: "Recursive setup expression creates ghost setups that make
VerifyAll
fail" (@stakx, #684) - Bug report #191: "Upgrade from 4.2.1409.1722 to 4.2.1507.0118 changed
VerifyAll
behavior" (@stakx, #684)
- Add
Mock.Invocations
property to support inspection of invocations on a mock (@Tragedian, #560)
- Update package reference to
Castle.Core
(DynamicProxy) from version 4.3.0 to 4.3.1 (@stakx, #635) - Floating point values are formatted with higher precision (satisfying round-tripping) in diagnostic messages (@stakx, #637)
CallBase
disregarded for some base methods from non-public interfaces (@stakx, #641)
mock.ResetCalls()
has been deprecated in favor ofmock.Invocations.Clear()
(@stakx, #633)
- Add
ISetupSequentialResult<TResult>.Returns
method overload that support delegate for deferred results (@snrnats, #594) - Support for C# 7.2's
in
parameter modifier (@stakx, #624, #625) - Missing methods
ReturnsAsync
andThrowsAsync
for sequential setups of methods returning aValueTask
(@stakx, #626)
- Breaking change: All
ReturnsAsync
andThrowsAsync
setup methods now consistently return a newTask
on each invocation (@snrnats, #595) - Speed up
Mock.Of<T>()
by approx. one order of magnitude (@informatorius, #598) - Update package reference to
Castle.Core
(DynamicProxy) from version 4.2.1 to 4.3.0 (@stakx, #624)
- Usage of
ReturnsExtensions.ThrowsAsync()
can causeUnobservedTaskException
(@snrnats, #595) ReturnsAsync
andThrowsAsync
with delay parameter starts timer at setup (@snrnats, #595)Returns
regression with null function callback (@Caraul, #602)
- Upgraded
System.ValueTuple
dependency to version 4.4.0 in order to reestablish Moq compatibility with .NET 4.7 (and later), which already include theValueTuple
types (@stakx, #591)
- Wrong parameters count for extension methods in
Callback
andReturns
(@Caraul, #575) CallBase
regression with members of additional interfaces (@stakx, #583)
- C# 7 tuple support for
DefaultValue.Empty
andDefaultValue.Mock
(@stakx, #563)
- Downgraded
System.Threading.Tasks.Extensions
andSystem.ValueTuple
dependencies to versions 4.3.0 as suggested by @tothdavid in order to improve Moq compatibility with .NET 4.6.1 / help preventMissingMethodException
and similar (@stakx, #571)
CallBase
regression with explicitly implemented interface methods (@stakx, #558)
Same as 4.8.0-rc1 (see below), plus some significant speed improvements.
SetupAllProperties
now fully supports property type recursion / loops in the object graph, thanks to deferred property initialization (@stakx, #550)
This is a pre-release version.
- Support for sequential setup of
void
methods (@alexbestul, #463) - Support for sequential setups (
SetupSequence
) of protected members (@stakx, #493) - Support for callbacks for methods having
ref
orout
parameters via two new overloads ofCallback
andReturns
(@stakx, #468) - Improved support for setting up and verifying protected members (including generic methods and methods having by-ref parameters) via the new duck-typing
mock.Protected().As<TAnalog>()
interface (@stakx, #495, #501) - Support for
ValueTask<TResult>
when using theReturnsAsync
extension methods, similar toTask<TResult>
(@AdamDotNet, #506) - Special handling for
ValueTask<TResult>
withDefaultValue.Empty
(@stakx, #529) - Support for custom default value generation strategies besides
DefaultValue.Empty
andDefaultValue.Mock
: Implement custom providers by subclassing eitherDefaultValueProvider
orLookupOrFallbackDefaultValueProvider
, install them by settingMock[Repository].DefaultValueProvider
(@stakx, #533, #536) - Allow
DefaultValue.Mock
to mockTask<TMockable>
andValueTask<TMockable>
(@stakx, #502) - Match any value for
ref
parameters withIt.Ref<T>.IsAny
(orItExpr.Ref<T>.IsAny
for protected methods) as you would withIt.IsAny<T>()
for regular parameters (@stakx, #537) Mock.VerifyNoOtherCalls()
to check whether all expected invocations have been verified -- can be used as an alternative toMockBehavior.Strict
(@stakx, #539)
- Breaking change:
SetupSequence
now overrides pre-existing setups like all otherSetup
methods do. This means that exhausted sequences no longer fall back to previous setups to produce a "default" action or return value. (@stakx, #476) - Delegates passed to
Returns
are validated a little more strictly than before (return type and parameter count must match with method being set up) (@stakx, #520) - Change assembly versioning scheme to
major.minor.0.0
to help prevent assembly version conflicts and to reduce the need for binding redirects (@stakx, #554)
- Update a method's invocation count correctly, even when it is set up to throw an exception (@stakx, #473)
- Sequences set up with
SetupSequence
are now thread-safe (@stakx, #476) - Record calls to methods that are named like event accessors (
add_X
,remove_X
) so they can be verified (@stakx, #488) - Improve recognition logic for sealed methods so that
Setup
throws when an attempt is made to set one up (@stakx, #497) - Let
SetupAllProperties
skip inaccessible methods (@stakx, #499) - Prevent Moq from relying on a mock's implementation of
IEnumerable<T>
(@stakx, #510) - Verification leaked internal
MockVerificationException
type; remove it (@stakx, #511) - Custom matcher properties not printed correctly in error messages (@stakx, #517)
- Infinite loop when invoking delegate in
Mock.Of
setup expression (@stakx, #528)
[Matcher]
has been deprecated in favor ofMatch.Create
(@stakx, #514)
- Moq no longer collects source file information for verification error messages by default. A current .NET Framework regression (microsoft/dotnet#529) makes this extremely costly, so this is now an opt-in feature; see
Switches.CollectSourceFileInfoForSetups
(@stakx, #515)
Mock.Switches
andMockRepository.Switches
, which allow opting in and out of certain features (@stakx, #515)
- Update package reference to
Castle.Core
(DynamicProxy) from version 4.2.0 to 4.2.1 due to a regression; see castleproject/Core#309 for details (@stakx, #482)
TypeLoadException
s ("Method does not have an implementation") caused by the regression above, see e.g. #469 (@stakx, #482)
- Update package reference to
Castle.Core
(DynamicProxy) from version 4.1.1 to 4.2.0, which uses a new assembly versioning scheme that should eventually reduce assembly version conflicts and the need for assembly binding redirects (@stakx, #459)
mock.Object
should always return the exact same proxy object, regardless of whether the mock has been cast to an interface via.As<T>()
or not (@stakx, #460)
- Make setups for inaccessible internal members fail fast by throwing an exception (@stakx, #455)
- The redundant type
ObsoleteMockException
has been removed (@stakx)
- Make
SetupAllProperties
work correctly for same-typed sibling properties (@stakx, #442) - Switch back from portable PDBs to classic PDBs for better compatibility of SourceLink with older .NET tools (@stakx, #443)
- Make strict mocks recognize that
.CallBase()
can set up a return value, too (@stakx, #450)
- Add
[NeutralResourcesLanguage]
to assembly info for portable library use (@benbillbob, #394) - Add portable, SourceLink-ed debugging symbols (PDB) to NuGet package, enabling end users to step into Moq's source code (@stakx, #417)
- Move all hardcoded message strings to
Resources.resx
(@stakx, #403) - Update package reference to
Castle.Core
(DynamicProxy) from version 4.1.0 to 4.1.1 (@stakx, #416) - Clean up and simplify the build process by merging separate .NET Framework and .NET Standard projects (@stakx, #417)
- Replace outdated
ReleaseNotes.md
with newCHANGELOG.md
(@stakx, #423)
- Fix member name typo in reflection code (@JohanLarsson, #389)
- Make
Interceptor
more thread-safe duringmock.Setup
(@stakx, #392) - Make abstract events defined in classes work even when
CallBase
is true by suppressingInvokeBase()
(@stakx, #395) - Allow setting up null return values using
Mock.Of
(@stakx, #396) - Allow
Mock<T>.Raise
to raise events on child mocks instead of raising no or the wrong event (@stakx, #397) - Improve specificity of
Setup
/Verify
exception messages for static members and extension methods (@stakx, #400) - Prevent internal interception on a mock from changing its
DefaultValue
property (@vladonemo, #411) - Prevent stack overflow in conditional setups (@stakx, #412)
- Fix
NullReferenceException
caused by internally relying on a mock'sIEnumerable
implementation (@stakx, #413) - Improve method match accuracy in
ExtractProxyCall
so that the order of setting up methods in an hierarchy of interfaces does not matter (@stakx, #415) - Improve mockability of C++/CLI interfaces having custom modifiers (
modopt
,modreq
) in their method signatures (@stakx, #416) - Make types implementing the same generic type more than two times mockable (@stakx, #416)
- Fix misreported
Times
in verification error messages (@stakx, #417)
- Ensure that
null
never matches anIt.IsRegex(…)
(@stakx, #385)
- Fix mocking of non-virtual methods via
mock.As<TInterface>()
which was broken by #381 (@stakx, #387)
- Fix formatting inconsistencies for array values in
MockException.Message
(@stakx, #380) - Fix major "class method vs. interface method" bug introduced by #119 / commit 162a543 (@stakx, #381)
- Fix mocking for redeclared interface properties (get-set but get-only in base type) (@stakx, #382)
- Fix incorrect Castle.Core package reference in NuGet package specification (@stakx, #379)
- Extend
EmptyDefaultValueProvider
so it understands multidimensional arrays (return empty multidimensional arrays instead ofnull
) (@stakx, #360) - Update package reference to
Castle.Core
(DynamicProxy) from version 4.0.0 to 4.1.0, updateSystem
andMicrosoft
packages from versions 4.0.1 to 4.3.0 (@stakx, #369) - Clean up and reduce usage of conditional compilation (
#if
) (@stakx, #378)
- Ensure default mock names are (more) unique (@stakx, #359)
- Make
It.IsAny
,It.IsNotNull
work for COM types (@stakx, #361) - Fix equality check bug in
ExpressionKey
which meant Moq would sometimes ignore exact argument order in setups (@kostadinmarinov, #135; @stakx, #363) - Ensure incorrect implementations of
ISerializable
are caught properly (@stakx, #370) - Make event accessor recognition logic more correct (don't just rely on
add_
orremove_
name prefixes) (@stakx, #376)
- Add new
setup.ReturnsAsync
andsetup.ThrowsAsync
overloads allowing you to specify a delay (@jochenz, #289)
- Migrate .NET Core project to the new
.csproj
format (@jeremymeng, #336)
- Add overload in
mock.Protected()
setups to enforce the old behavior of exact parameter matching (new behavior fails for specific overloads) (@80er, #347)
Minor change only (fix typo in documentation)
Minor change only (update project URL in NuGet package metadata)
Minor change only (add download badge to README.md
)
Minor change only (update license URL in NuGet package metadata)
- Allow setting up of protected methods with nullable parameters (@RobSiklos, #200)
- Fix incorrect code example in XML documentation comment for
Mock.Verify
(@jcockhren, #333) - Fix bug in
HasMatchingParameterTypes
which causedProtected().Verify
to reject valid mocks (@jeremymeng, #335)
Minor change only (fix typo in documentation)
Minor change only (correcting Moq version after semver violation) This version is the successor of 4.6.62-alpha.
This version is the predecessor of 4.7.0 and essentially a cleaned up merge of both 4.5.30 and 4.6.39-alpha.
Note: The release notes for some Moq versions 4.6.*-alpha are still missing. They need to be reconstructed from the commit history and the GitHub issue archive. If you would like to help make this changelog more complete, any pull requests towards that goal are appreciated!
- Fix issue in
ExpressionKey
that caused identical setups to no longer be considered the same (@MatKubicki, #313)
- Make the recently added
setup.ReturnsAsync(Func<TResult> result)
evaluate its argument lazily, likesetup.Returns
would (@SaroTasciyan, #309)
- New method
setup.ReturnsAsync(Func<TResult> result)
(@joeenzminger, @tlycken, #297)
- Improves comparison of call arguments in
ExpressionKey
so that setups for the same method but with differing arguments don't override each other (@MatKubicki, #291)
- Properly raise events when mocked type implements multiple interfaces (@bradreimer, #288)
- Fix
mock.Reset()
which so far forgot to also clear all existing calls in the interceptor (@anilkamath87, #277)
- Ensure that mocking of
System.Object
methods always works, even in strict mode (again) (@kolomanschaft, #280)
- Make
SetupAllProperties
work withDefaultValue.Mock
in the presence of object graph loops (i.e. when a type contains a property having the same type) (@vladonemo, #245) - Prevent invalid implementations of
ISerializable
from being mocked (as DynamicProxy cannot handle these) via the newSerializableTypesValueProvider
decorator (@vladonemo, #245)
- Ensure that mocking of
System.Object
methods always works, even in strict mode (@kolomanschaft, #279)
- Allow mocking of
System.Object
methods (ToString
,Equals
, andGetHashCode
) (@kolomanschaft, #250)
Verify
exception messages should include actual array values for specific calls instead of justT[]
or variable names (@hahn-kev, #264)
- Add helper classes
Capture
,CaptureMatch<T>
to simplify parameter capture (@ocoanet, #251)
Minor change only (remove download badge from README.md
)
Minor change only (add .editorconfig
file)
- Reference Castle.Core as a NuGet package dependency instead of ILMerge-ing it into Moq's own assembly. (@kzu)
- Update package reference to
GitInfo
from version 1.1.14 to 1.1.15 to fix versioning issue with cached Git info (@kzu)
- Remove debugging symbols (PDB) from package since GitLink doesn't seem to be working (@kzu)
- New helper methods
Mock.Verify(params Mock[] mocks)
andMock.VerifyAll(...)
(@RehanSaeed, #238)
Minor change only (update release notes in NuGet package metadata) This version is the successor of 4.5.9-alpha.
This version is the predecessor of 4.5.0.
- Fix broken hashing in
ExpressionKey
that causes Moq to not be able to distinguish method setups differing only in the exact argument order (@LeonidLevin, #262)
- Remove (for the time being) official statement in release notes that Moq supports .NET Core (@kzu)
- Add
ReturnsAsync
andThrowsAsync
methods for sequential values setups (@abatishchev, #261)
- Migrate to .NET 4.5 and NuGet 3 (@kzu)
- Update package reference to
GitInfo
from version 1.1.13 to 1.1.14 (@kzu)
- Remove COM unit tests (@kzu)
- Remove legacy Silverlight unit test project (@kzu)
- Remove
[NeutralResourcesLanguage]
attribute from main assembly (@kzu)
- Avoid race conditions / improve thread safety of
MockDefaultValueProvider
(@mizbrodin, #207) - Fix a code typo in
ExpressionComparer
(@AppChecker, #242) - When mocking delegates, copy parameter attributes so
out
parameters work correctly (@urasandesu, #255)
- Add Gitter badge to
README.md
(@kzu)
- Upgrade to Castle.Core version 3.3.3 (@MSK61, @kzu, #204)
- Make Task Parallel Library (TPL) code Silverlight 5 compatible (@iskiselev, #148)
- Fox license hyperlink so it points to correct version of the BSD license (@chkpnt, #198)
- Move Silverlight 5 assemblies in proper
lib\sl5
folder (instead oflib\sl4
) in the NuGet package (@kzu)
- Add new
mock.Reset()
extension method (@ashmind, #138)
- Allow
null
to match nullable value types (@pkpjpm, #185)
- Add NuGet badges to
README.md
(@kzu) - Add generic type argument information in exception messages for easier debugging (@hasaki, #177)
- Migrate Silverlight support from version 4 to 5 (@kzu)
- Upgrade source code to Visual Studio 2013 (@kzu)
- Fix
NullReferenceException
when passingnull
to a nullable argument but trying to match it with a non-nullableIsAny
(@benjamin-hodgson, #160) - Fix infinite loop when calling
SetupAllProperties
for entities with a hierarchy (@Moq, #180)
SetupAllProperties
doesn't setup properties that don't have a setter (@NGloreous, #137)- Fix DynamicProxy-related
NotImplementedException
when mocking interfaces withCallBase = true
(@rjasica, #145)
Minor change only (update NuGet metadata) This version was released twice under different version numbers.
- Migrate to MSBuild version 12 (@kzu)
- Enable
mock.As<TInterface>()
syntax for all implemented interfaces (except COM interfaces) even aftermock.Object
has been called (@scott-xu, #119, #123)
- Change
README.md
to show the use ofAtMostOnce
inVerify
phase instead ofSetup
phase (@kzu)
- Ordered call issue with invocations with same arguments in
MockSequence
(@drieseng, #97) - Update various hyperlinks in
README.md
(@kzu) - Improve Moq's support for curried delegates and fix failing unit tests when compiling Moq with Roslyn (@theoy, #125)
- Allow mocks to have names (@pimterry, #76, #83)
- Make
InterfaceProxy
class publicly visible to reenable mocking of interfaces (@pimterry, #99)
- Remove commercial licenses offer in
README.md
(@kzu)
- Improve thread safety by splitting the interceptor's context into global one and one for the current proxy invocation only (@MatKubicki, #80)
- Improve thread safety in
Interceptor
and fix multithreading tests (@MatKubicki, #68)
- Fix
NullReferenceException
when trying to get a default value forTask<T>
whenT
is a reference type (@alextercete, #73)
Minor change only (update release notes)
InSequence
setups can now be used on the same mock instance (@halllo, #72)
- Move extension methods in class
Moq.Language.Flow.IReturnsExtensions
toMoq.ReturnsExtensions
for better discoverability (@jdom, #71)
- Add
ReturnsAsync
andThrowsAsync
setup methods for better async support (@Blewzman, #60) - Migrate
README.md
content from Google Code (@kzu)
- Change
EmptyDefaultValueProvider
so it does not returnnull
forTask
andTask<T>
types, but completed, awaitable tasks (@alextercete, #66)
- Add
Throws
method to sequential value setups for testing retry logic in web services (@kellyselden, #59)
- Matchers should not ignore implicit type conversions (@svick, #56)
This version was released twice under different version numbers.
- Fix regression bug surrounding
Mock.As<TInterface>()
: Prevent early initialization of mock from checking for delegate mocks. (@kzu, #54)
- Allow resetting of all call counts (those that will be compared with
Times
) (@salfab, #55)
This version was released twice under different version numbers.
- New
It.IsNotNull<T>
matcher (@Pjanssen, #40) - Add covariant
IMock<out T>
interface toMock<T>
(@tkellogg, #44)
- Rename
Changelog.txt
toReleaseNotes.md
and inject the latter into the NuGet metadata (@Moq, #52)
- Fix "collection modified" exception thrown as result of more methods being called on a mock while verifying method calls (@yonahw, #36)
- Fix
NullReferenceException
when subscribing to an event (@bittailor, #39) - Fix thread safety issue (
IndexOutOfRangeException
) on setup (@stoo101, #51)
Minor change only (change title in NuGet package metadata)
- Add capability for mocking delegates (event handlers) (@quetzalcoatl, #4)
- Allow
CallBase
for specific method / property (@srudin, #8) - New matchers
It.IsIn
andIt.IsNotIn
(@rdingwall, #27) - Add
.gitignore
file (@yorah, #10 / @FellicePollano, #30) - Add new
Verify
method overload group that accepts aTimes
instance (@ChrisMissal, #34)
- Update Castle.Core assemblies from version 1.2.0.0 to 3.2.0, fetch Castle.Core via NuGet (@yorah, #11 / @kzu)
- Corrected Verify method behavior for generic methods calls (@Suremaker, #25)
- Split up
Interceptor.Intercept
into a set of 8 strategies, introduceInterceptionAction
(@FellicePollano, #31)
- Fix
SetupSequentialContext
to increment counter also afterThrows
(@lukas-ais, #7) - Make
Mock.Of
work on properties with non-public setters (@yorah, #9, #19) - Adding (and removing) handlers for events declared on interfaces when
CallBase = true
(@IharBury, #13) - Distinguish between verification exception and mock crash (@quetzalcoatl, #16)
- Improve thread safety of
Interceptor
class (@FelicePollano, #29)
Note: Release notes in the above format are not available for ealier versions of Moq. The above changelog entries have been reconstructed from the Git commit history. What follows below are the original release notes, for which maintenance stopped around Moq version 4.5. They are nevertheless included below as they go back further in time.
- Updated to .NET 4.5
- Dropped support for .NET < 4.5 and Silverlight
- Remove ILMerge. Depend on Castle NuGet package instead.
- Added support for Roslyn
- Automatically add implemented interfaces to mock
- Improved support for async APIs by making default value a completed task
- Added support for async Returns and Throws
- Improved mock invocation sequence testing
- Improved support for multi-threaded tests
- Added support for named mocks
- Added covariant
IMock<out T>
interface toMock<T>
- Added
It.IsNotNull<T>
- Fix: 'NullReferenceException when subscribing to an event'
- Added overloads to
Verify
to acceptTimes
as a Method Group - Feature request:
It.IsIn(..)
,It.IsNotIn(...)
- Corrected Verify method behavior for generic methods calls
- Differentiate verification error from mock crash
- Fix: Adding (and removing) handlers for events declared on interfaces works when
CallBase = true
. - Update to latest Castle
- Fix:
Mock.Of
(Functional Syntax) doesn't work on properties with non-public setters - Fix: Allow to use
CallBase
instead ofReturns
- Fix: Solved Multi-threading issue -
IndexOutOfRangeException
- Capability of mocking delegates (event handlers)
- Linq to Mocks:
Mock.Of<T>(x => x.Id == 23 && x.Title == "Rocks!")
- Fixed issues:
- 87
BadImageFormatException
when using a mock with a Visual Studio generated Accessor object - 166 Unable to use a delegate to mock a function that takes 5 or more parameters.
- 168 Call count failure message never says which is the actual invocation count
- 175
theMock.Object
failing on VS2010 Beta 1 - 177 Generic constraint on interface method causes
BadImageFormatException
when gettingObject
. - 183 Display what invocations were recieved when the expected one hasn't been met
- 186 Methods that are not virtual gives non-sense-exception message
- 188 More
Callback
Overloads - 199 Simplify
SetupAllProperties
implementation to simply iterate and callSetupProperty
- 200 Fluent mock does not honor parent mock
CallBase
setting. - 202
Mock.Protected().Expect()
deprecated with no work-around - 204 Allow default return values to be specified (per-mock)
- 205 Error calling
SetupAllProperties
forMock<IDataErrorInfo>
- 206 Linq-to-Mocks Never Returns on Implicit Boolean Property
- 207
NullReferenceException
thrown when usingMocks.CreateQuery
with implicit boolean expression - 208 Can't setup a mock for method that accept lambda expression as argument.
- 211
SetupAllProperties
should return theMock<T>
instead ofvoid
. - 223 When a method is defined to make the setup an asserts mock fails
- 226 Can't raise events on mocked Interop interfaces
- 229
CallBase
is not working for virtual events - 238 Moq fails to mock events defined in F#
- 239 Use
Func
instead ofPredicate
- 250 4.0 Beta 2 regression - cannot mock
MethodInfo
when targetting .NET 4 - 251 When a generic interface also implements a non-generic version,
Verify
does not work in some cases - 254 Unable to create mock of
EnvDTE.DTE
- 261 Can not use protected setter in public property
- 267 Generic argument as dependency for method
Setup
overrides all previous method setups for a given method - 273 Attempting to create a mock thrown a Type Load exception. The message refers to an inaccessible interface.
- 276 .Net 3.5 no more supported
- 87
- Silverlight support! Finally integrated Jason's Silverlight contribution! Issue #73
- Brand-new simplified event raising syntax (#130):
mock.Raise(foo => foo.MyEvent += null, new MyArgs(...));
- Support for custom event signatures (not compatible with
EventHandler
):mock.Raise(foo => foo.MyEvent += null, arg1, arg2, arg3);
- Substantially improved property setter behavior:
mock.VerifySet(foo => foo.Value = "foo");
(also available forSetupSet
- Renamed
Expect*
withSetup*
- Vastly simplified custom argument matchers:
public int IsOdd() { return Match<int>.Create(v => i % 2 == 0); }
- Added support for verifying how many times a member was invoked:
mock.Verify(foo => foo.Do(), Times.Never());
- Added simple sample app named StoreSample
- Moved Stub functionality to the core API (
SetupProperty
andSetupAllProperties
) - Fixed sample ASP.NET MVC app to work with latest version
- Allow custom matchers to be created with a substantially simpler API
- Fixed issue #145 which prevented discrimination of setups by generic method argument types
- Fixed issue #141 which prevented ref arguments matching value types (i.e. a Guid)
- Implemented improvement #131: Add support for
It.IsAny
and custom argument matchers forSetupSet
/VerifySet
- Implemented improvement #124 to render better error messages
- Applied patch from David Kirkland for improvement #125 to improve matching of enumerable parameters
- Implemented improvement #122 to provide custom errors for
Verify
- Implemented improvement #121 to provide
null
as default value forNullable<T>
- Fixed issue #112 which fixes passing a null argument to a mock constructor
- Implemented improvement #111 to better support params arguments
- Fixed bug #105 about improperly overwriting setups for property getter and setter
- Applied patch from Ihar.Bury for issue #99 related to protected expectations
- Fixed issue #97 on not being able to use
SetupSet
/VerifySet
if property did not have a getter - Better integration with Pex (http://research.microsoft.com/en-us/projects/Pex/)
- Various other minor fixes (#134, #135, #137, #138, #140, etc.)
- Implemented Issue #55: We now provide a
mock.DefaultValue
= [DefaultValue.Empty
|DefaultValue.Mock
] which will provide the current behavior (default) or mocks for mockeable return types for loose mock invocations without expectations. - Added support for stubbing properties from moq-contrib: now you can do
mock.Stub(m => m.Value)
and add stub behavior to the property.mock.StubAll()
is also provided. This integrates with theDefaultValue
behavior too, so you can stub entire hierarchies :). - Added support for mocking methods with
out
andref
parameters (Issue #50) - Applied patch contributed by slava for Issue #72: add support to limit numbor of calls on mocked method (we now have
mock.Expect(...).AtMost(5)
) - Implemented Issue #94: Easier setter verification: Now we support
ExpectSet(m = m.Value, "foo")
andVerifySet(m = m.Value, 5)
(Thanks ASP.NET MVC Team!) - Implemented issue #96: Automatically chain mocks when setting expectations. It's now possible to specify expectations for an entire hierarchy of objects just starting from the root mock. THIS IS REALLY COOL!!!
- Fixed Issue #89:
Expects()
does not always return last expectation - Implemented Issue 91: Expect a method/property to never be called (added
Never()
method to an expectation. Can be used on methods, property getters and setters) - Fixed Issue 86:
IsAny<T>
should check if the value is actually of typeT
- Fixed Issue 88: Cannot mock protected internal virtual methods using
Moq.Protected
- Fixed Issue 90: Removing event handlers from mocked objects
- Updated demo and added one more test for the dynamic addition of interfaces
- Added support for mocking protected members
- Added new way of extending argument matchers which is now very straightforward
- Added support for mocking events
- Added support for firing events from expectations
- Removed usage of MBROs which caused inconsistencies in mocking features
- Added
ExpectGet
andExpectSet
to better support properties, and provide better intellisense. - Added verification with expressions, which better supports Arrange-Act-Assert testing model (can do
Verify(m => m.Do(...)))
- Added
Throws<TException>
- Added
mock.CallBase
property to specify whether the virtual members base implementation should be called - Added support for implementing and setting expectations and verifying additional interfaces in the mock, via the new
mock.As<TInterface>()
method (thanks Fernando Simonazzi!) - Improved argument type matching for
Is
/IsAny
(thanks Jeremy.Skinner!)
- Refactored fluent API on mocks. This may cause some existing tests to fail, but the fix is trivial (just reorder the calls to
Callback
,Returns
andVerifiable
) - Added support for retrieving a
Mock<T>
from aT
instance created by a mock. - Added support for retrieving the invocation arguments from a
Callback
orReturns
. - Implemented
AtMostOnce()
constraint - Added support for creating MBROs with protected constructors
- Loose mocks now return default empty arrays and
IEnumerables
instead ofnull
s
- Refactored
MockFactory
to make it simpler and more explicit to use with regards to verification. Thanks Garry Shutler for the feedback!
- Added
MockFactory
to allow easy construction of multiple mocks with the same behavior and verification
- Added support for passing constructor arguments for mocked classes.
- Improved code documentation
- Added support for overriding expectations set previously on a Mock. Now adding a second expectation for the same method/property call will override the existing one. This facilitates setting up default expectations in a fixture setup and overriding when necessary in a specific test.
- Added support for mock verification. Both
Verify
andVerifyAll
are provided for more flexibility (the former only verifies methods markedVerifiable
)
- Added support for
MockBehavior
mock constructor argument to affect the way the mocks expect or throw on calls.
- Merged branch for dynamic types. Now Moq is based on Castle DynamicProxy2 to support a wider range of mock targets.
- Added ILMerge so that Castle libraries are merged into Moq assembly (no need for external references and avoid conflicts)
- Initial release, initial documentation process in place, etc.