Releases: devlooped/moq
Releases · devlooped/moq
4.18.4
4.18.3
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)