All Versions
107
Latest Version
Avg Release Cycle
40 days
Latest Release
711 days ago

Changelog History
Page 3

  • v4.13.0 Changes

    August 31, 2019
    ๐Ÿ”„ Changed
    • ๐Ÿ‘Œ Improved error message that is supplied with ArgumentException thrown when Setup or Verify 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 not Callback is preceded by a Returns: 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] and Verify[Add|Remove|All] (@lepijohnny, #825)

    • โž• Added support for lambda expressions while creating a mock through new Mock<SomeType>(() => new SomeType("a", "b")) and repository.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 type
    • It.IsSubtype<T> — matches T and proper subtypes of T
    • 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, the argument 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 parameter parameterType. (@stakx, #908)

    ๐Ÿ›  Fixed
    • ๐Ÿคก Moq does not mock explicit interface implementation and protected virtual correctly. (@oddbear, #657)

    • Invocations.Clear() does not cause Verify to fail (@jchessir, #733)

    • Regression: SetupAllProperties can no longer set up properties whose names start with Item. (@mattzink, #870; @kaan-kaya, #869)

    • ๐Ÿคก Regression: MockDefaultValueProvider will no longer attempt to set CallBase to true for mocks generated for delegates. (@dammejed, #874)

    • ๐Ÿคก Verify throws TargetInvocationException instead of MockException 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) throws NullReferenceException instead of producing a completed task with result null (@voroninp, #909)

  • v4.12.0 Changes

    June 20, 2019
    ๐Ÿ”„ Changed
    • ๐Ÿ‘Œ Improved performance for Mock.Of<T> and mock.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 return default(T) for loose mocks, but a value that is consistent with the mock's CallBase and DefaultValue[Provider] settings. (@stakx, #849)
    โž• Added
    • ๐Ÿ†• 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, and mockRepository.OneOf that accept a MockBehavior parameter. (@stakx, #842)
    ๐Ÿ›  Fixed
    • โž• 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() and Mock.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).
  • v4.11.0 Changes

    May 28, 2019

    ๐Ÿš€ Same as 4.11.0-rc2. See changelog entries for the below two pre-release versions.

  • v4.11.0-rc2 Changes

    May 27, 2019

    ๐Ÿš€ This is a pre-release version.

    ๐Ÿ”„ Changed
    • ๐Ÿ”ง 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)
    ๐Ÿ›  Fixed
    • ๐Ÿ‘ป Regression: Unhelpful exception message when setting up an indexer with SetupProperty (@stakx, #823)
  • v4.11.0-rc1 Changes

    April 19, 2019

    ๐Ÿš€ 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.

    ๐Ÿ”„ Changed
    • ๐Ÿ”Š 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 of args, not as exactParameterMatch (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 and VerifySet, 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)
    โž• Added
    • ๐Ÿ†• 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 and setup.Raises to raise events on sub-objects (inner mocks) (@stakx, #772)
    โœ‚ Removed
    • โœ… Pex interop (which has not been maintained for years). You might notice changes when using Visual Studio's IntelliTest feature. (@stakx, #786)
    ๐Ÿ›  Fixed
    • Setting multiple indexed object's property directly via LINQ fails (@TylerBrinkley, #314)
    • ๐Ÿคก InvalidOperationException when specifiying setup on mock with mock containing property of type Nullable<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 subsequent VerifyAll 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)
  • v4.10.1 Changes

    December 03, 2018
    ๐Ÿ›  Fixed
    • NullReferenceException when using SetupSet on indexers with multiple parameters (@idigra, #694)
    • ๐Ÿคก CallBase should not be allowed for delegate mocks (@tehmantra, #706)
    ๐Ÿ”„ Changed
    • โฌ‡๏ธ 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 and System.Threading.Tasks.Extensions dependencies to versions 4.5.1 (@stakx, #729)
  • v4.10.0 Changes

    September 08, 2018
    โž• Added
    • ExpressionCompiler: An extensibility point for setting up alternate LINQ expression tree compilation strategies (@stakx, #647)
    • setup.CallBase() for void methods (@stakx, #664)
    • ๐Ÿคก VerifyNoOtherCalls for MockRepository (@BlythMeister, #682)
    ๐Ÿ”„ Changed
    • ๐Ÿ‘‰ Make VerifyNoOtherCalls take into account previous calls to parameterless Verify() and VerifyAll() (@stakx, #659)
    • ๐Ÿ’ฅ Breaking change: VerifyAll now succeeds after a call to SetupAllProperties even when not all property accessors were invoked (stakx, #684)
    ๐Ÿ›  Fixed
    • ๐Ÿคก 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 from Expressions (@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)
  • v4.9.0 Changes

    July 13, 2018
    โž• Added
    • โž• Add Mock.Invocations property to support inspection of invocations on a mock (@Tragedian, #560)
    ๐Ÿ”„ Changed
    • โšก๏ธ 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)
    ๐Ÿ›  Fixed
    • CallBase disregarded for some base methods from non-public interfaces (@stakx, #641)
    Obsoleted
    • ๐Ÿ—„ mock.ResetCalls() has been deprecated in favor of mock.Invocations.Clear() (@stakx, #633)
  • v4.8.3 Changes

    June 09, 2018
    โž• Added
    • โž• 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 and ThrowsAsync for sequential setups of methods returning a ValueTask (@stakx, #626)
    ๐Ÿ”„ Changed
    • ๐Ÿ’ฅ Breaking change: All ReturnsAsync and ThrowsAsync setup methods now consistently return a new Task 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)
    ๐Ÿ›  Fixed
    • Usage of ReturnsExtensions.ThrowsAsync() can cause UnobservedTaskException (@snrnats, #595)
    • ReturnsAsync and ThrowsAsync with delay parameter starts timer at setup (@snrnats, #595)
    • Returns regression with null function callback (@Caraul, #602)
  • v4.8.2 Changes

    February 23, 2018
    ๐Ÿ”„ Changed
    • โฌ†๏ธ Upgraded System.ValueTuple dependency to version 4.4.0 in order to reestablish Moq compatibility with .NET 4.7 (and later), which already include the ValueTuple types (@stakx, #591)
    ๐Ÿ›  Fixed
    • Wrong parameters count for extension methods in Callback and Returns (@Caraul, #575)
    • CallBase regression with members of additional interfaces (@stakx, #583)