Releases: devlooped/moq
Releases · devlooped/moq
4.18.2
4.18.1
Fixed
- 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)
4.18.0
New major version of DynamicProxy (you may get better performance!), so please update with care.
Changed
- 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
Fixed
- 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)
4.17.2
4.17.1
Added
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)
Changed
Fixed
- 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)
4.16.1
Added
CallBase
can now be used with interface methods that have a default interface implementation. It will call the most specific override. (@stakx, #1130)
Changed
- Improved error message formatting of
It.Is
lambda expressions that capture local variables. (@bfriesen, #1140)
Fixed
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)
4.16.0
Added
-
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)
Changed
- 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)
Fixed
4.15.2
4.15.1
Added
- 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)
Changed
- 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)
Fixed
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)
4.14.7
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)