Skip to content

Releases: devlooped/moq

4.18.2

30 Dec 11:48
Compare
Choose a tag to compare

Changed

  • 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 for netstandard2.1 and net6.0 (@tibel, #1274)

Fixed

  • "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)

4.18.1

30 Dec 11:49
Compare
Choose a tag to compare

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

30 Dec 11:49
Compare
Choose a tag to compare

New major version of DynamicProxy (you may get better performance!), so please update with care.

Changed

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 and DefaultValue.Mock configured (@IanKemp, #1249)

4.17.2

30 Dec 11:50
Compare
Choose a tag to compare

Fixed

4.17.1

30 Dec 11:51
Compare
Choose a tag to compare

Added

  • SetupSet, VerifySet methods for mock.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())
    and Setup(x => x.GetFooAsync(It.IsAny<string>()).Result).Throws((string s) => new InvalidOperationException(s)). (@adam-knights, #1191)

Changed

  • Update package reference to Castle.Core (DynamicProxy) from version 4.4.0 to 4.4.1 (@stakx, #1233)

Fixed

  • The guard against unmatchable matchers (added in #900) was too strict; relaxed it to enable an alternative user-code shorthand _ for It.IsAny<>() (@adamfk, #1199)
  • mock.Protected() setup methods fail when argument is of type Expression (@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

30 Dec 11:51
Compare
Choose a tag to compare

Added

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 in TargetInvocationException (@stakx, #1141)

4.16.0

30 Dec 11:52
Compare
Choose a tag to compare

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 in mock.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

  • 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)

4.15.2

30 Dec 11:53
Compare
Choose a tag to compare

Changed

  • Upgraded System.Threading.Tasks.Extensions dependency to version 4.5.4 (@JeffAshton, #1108)

4.15.1

30 Dec 11:54
Compare
Choose a tag to compare

Added

  • New method overloads for It.Is, It.IsIn, and It.IsNotIn that compare values using a custom IEqualityComparer<T> (@weitzhandler, #1064)
  • New properties ReturnValue and Exception on IInvocation 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[] or Func<It.IsAnyType, bool>). Argument match expressions like It.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 in Mock.Invocations. This previously wasn't the case for backwards compatibility with VerifyNoOtherCalls (which got implemented before it was possible to check them using Verify{Add,Remove}). You now need to explicitly verify expected calls to event accessors prior to VerifyNoOtherCalls. 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 comprehension from clause (@stakx, #982)

4.14.7

30 Dec 11:54
Compare
Choose a tag to compare

Changed

  • Mocks created by DefaultValue.Mock now inherit SetupAllProperties 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 as Verifiable (@killergege, #1073)
  • Mock.Of<> fails for COM interop types that are annotated with a [CompilerGenerated] custom attribute (@killergege, #1072)