Changelog History
Page 2
-
v4.14.7 Changes
October 14, 2020๐ Changed
- ๐ Mocks created by
DefaultValue.Mock
now inheritSetupAllProperties
from their "parent" mock (like it says in the XML documentation) (@stakx, #1074)
๐ Fixed
- 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)
- ๐ Mocks created by
-
v4.14.6 Changes
September 30, 2020๐ Fixed
- ๐คก Regression since 4.14.0: setting nested non-overridable properties via
Mock.Of
(@mariotee, #1039)
- ๐คก Regression since 4.14.0: setting nested non-overridable properties via
-
v4.14.5 Changes
July 01, 2020๐ Fixed
- Regression since version 4.11.0:
VerifySet
fails withNullReferenceException
for write-only indexers (@Epicycle23, #1036)
- Regression since version 4.11.0:
-
v4.14.4 Changes
June 24, 2020๐ Fixed
- Regression:
NullReferenceException
on subsequent setup if expression contains null reference (@IanYates83, #1031)
- Regression:
-
v4.14.3 Changes
June 18, 2020๐ Fixed
- ๐คก Regression, Part II:
Verify
behavior change usingDefaultValue.Mock
(@DesrosiersC, #1024)
- ๐คก Regression, Part II:
-
v4.14.2 Changes
June 16, 2020๐ Fixed
- ๐คก Regression:
Verify
behavior change usingDefaultValue.Mock
(@DesrosiersC, #1024)
- ๐คก Regression:
-
v4.14.1 Changes
April 28, 2020โ Added
- ๐ New
SetupSequence
verbs.PassAsync()
and.ThrowsAsync(...)
for async methods withvoid
return type (@fuzzybair, #993)
๐ Fixed
- ๐คก
StackOverflowException
onVerifyAll
when mocked method returns mocked object (@hotchkj, #1012)
- ๐ New
-
v4.14.0 Changes
April 24, 2020โ Added
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)
๐ Changed
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)
๐ Fixed
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)
-
v4.13.1 Changes
October 19, 2019๐ Fixed
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)
-
v4.13.0 Changes
August 31, 2019๐ Changed
๐ Improved error message that is supplied with
ArgumentException
thrown whenSetup
orVerify
are called on a protected method if the method could not be found with both the name and compatible argument types specified (@thomasfdm, #852).๐
mock.Invocations.Clear()
now removes traces of previous invocations more thoroughly by additionally resetting all setups to an "unmatched" state. (@stakx, #854)Consistent
Callback
delegate validation regardless of whether or notCallback
is preceded by aReturns
: Validation for post-Returns
callback delegates used to be very relaxed, but is now equally strict as in the pre-Returns
case.) (@stakx, #876)๐คก Subscription to mocked events used to be handled less strictly than subscription to regular CLI events. As with the latter, subscribing to mocked events now also requires all handlers to have the same delegate type. (@stakx, #891)
Moq will throw when it detects that an argument matcher will never match anything due to the presence of an implicit conversion operator. (@michelcedric, #897, #898)
๐ New algorithm for matching invoked methods against methods specified in setup/verification expressions. (@stakx, #904)
โ Added
โ Added support for setup and verification of the event handlers through
Setup[Add|Remove]
andVerify[Add|Remove|All]
(@lepijohnny, #825)โ Added support for lambda expressions while creating a mock through
new Mock<SomeType>(() => new SomeType("a", "b"))
andrepository.Create<SomeType>(() => new SomeType("a", "b"))
. This makes the process of mocking a class without a parameterless constructor simpler (compiler syntax checker...). (@frblondin, #884)๐ Support for matching generic type arguments:
mock.Setup(m => m.Method<It.IsAnyType>(...))
. (@stakx, #908)
The standard type matchers are:
It.IsAnyType
— matches any typeIt.IsSubtype<T>
— matchesT
and proper subtypes ofT
It.IsValueType
— matches only value 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)
๐ Fixed
๐คก Moq does not mock explicit interface implementation and
protected virtual
correctly. (@oddbear, #657)Invocations.Clear()
does not causeVerify
to fail (@jchessir, #733)Regression:
SetupAllProperties
can no longer set up properties whose names start withItem
. (@mattzink, #870; @kaan-kaya, #869)๐คก Regression:
MockDefaultValueProvider
will no longer attempt to setCallBase
to true for mocks generated for delegates. (@dammejed, #874)๐คก
Verify
throwsTargetInvocationException
instead ofMockException
when one of the recorded invocations was to an async method that threw. (@Cufeadir, #883)Moq does not distinguish between distinct events if they have the same name (@stakx, #893)
๐ Regression in 4.12.0:
SetupAllProperties
removes indexer setups. (@stakx, #901)Parameter types are ignored when matching an invoked generic method against setups. (@stakx, #903)
For
[Value]Task<object>
,.ReturnsAsync(null)
throwsNullReferenceException
instead of producing a completed task with resultnull
(@voroninp, #909)