NSubstitute v4.0.0 Release Notes

Release Date: 2019-01-01 // over 5 years ago
  • Thanks to core team member Alex Povar (@zvirja) for putting a huge amount of work into ๐Ÿš€ defining and implementing features, fixes and refactoring for this release! Also thanks to @tpodolak for the new NSubstitute.Analyzers project! Finally, thanks to everyone who submitted PRs, raised or commented on issues, or took the time to help answer questions on StackOverflow.

    Major new features and improvements

    • [NEW] NSubstitute.Analyzers project. ๐Ÿ”ง Uses Roslyn to detect potential problems with NSubstitute configurations, such as trying to substitute for non-virtual members. Whenever you add NSubstitute to your C# or VB project, ๐Ÿ“ฆ don't forget to also add the corresponding NSubstitute.Analyzers package! Thanks to @tpodolak for starting and running this project!
    • [NEW] CallBase for enabling base method calls for specific methods. (#449, @zvirja)
    • [NEW][BREAKING] Arg matchers (Arg.Is etc) can now be used for ref and out arguments. ๐Ÿ‘€ See [BreakingChanges.md](BreakingChanges.md) if you are still using pre-C#7. (#404, @zvirja)
    • ๐Ÿ”ง [NEW] Configure() extension in NSubstitute.Extensions.ConfigurationExtensions to ๐Ÿ”ง ensure NSubstitute handles the next call as a configuration/specification. (#350, @zvirja)
    • ๐ŸŽ [UPDATE] Performance improvements. (@zvirja)
      • CallResults performance optimisation
      • Delegate proxy generation improvements (#362)
      • Minimise allocations and LINQ use on hot code paths (#390)
      • Optimise array allocation (#395)
    • โšก๏ธ [UPDATE][BREAKING] Calls made with one or more argument matchers (Arg.Is or Arg.Any) ๐Ÿ”ง will no longer return previously configured results. NSubstitute will assume the call is ๐Ÿ”ง being configured and avoid running logic configured via previous Returns() calls. ๐Ÿ‘€ This helps fix some problems with overlapping configurations. See #345 and [BreakingChanges.md](BreakingChanges.md) for more information. (@zvirja)

    ๐Ÿ†• New and improved debugging, errors and error messages

    • ๐Ÿ”ง [NEW] Raise CouldNotConfigureBaseMethodException when trying to configure a call to call a base method that does not exist. (#429, @zvirja)
    • [NEW] Raise RedundantArgumentMatcherException if extra arg matchers are detected. This is โœ… a huge help for immediately identifying misconfigured tests. (@zvirja)
    • โšก๏ธ [UPDATE] Improved AmbiguousArgumentsException behaviour and errors. (#403 and others; @zvirja)
    • [NEW] Improve debugging experience with proxy ids. (#39, @zvirja)
    • โšก๏ธ [UPDATE] Improved display of MatchArgs to help with debugging. (@zvirja)
    • โœ… [NEW][BREAKING] Detection of unused argument matchers. This helps to identify errors in tests due to incorrectly used argument matchers. (#361, #89, #279; @zvirja)

    And lots, lots more!

    Including (but not limited to):

    • ๐Ÿ‘ [NEW] Support for netstandard-2.0. (#447, @zvirja)
    • [FIX] Improved handling of virtual calls in constructors. (#423, @zvirja)
    • ๐Ÿ”ง [NEW] Added a set of When() overloads to configure async methods without compilation warnings. (#468, @zvirja)
    • ๐Ÿ›  [FIX] Fixed potential for ArgumentNullException on finalizer thread. (#382, @zvirja)
    • โšก๏ธ [UPDATE] Now using Castle.Core 4.3.1+. We :heart: you Castle.Core! (Thanks for the PR Alexandr Nikitin!)
    • [NEW] Expose .Received(Quantity) in NSubstitute.ReceivedExtensions namespace. Thanks to @firelizzard18 for this suggestion.
    • โšก๏ธ [UPDATE] Made substitute setup and verification more robust in the concurrent environments. (#462, @zvirja)
    • โšก๏ธ [UPDATE] Removed NSubstitute.Core.Extensions.Zip (no longer require NET35 support). (#336)
    • ๐Ÿ“š [FIX] Restored XML documentation. (#345)
    • [NEW] Made global NSubstitute customization more easier. (#448, @zvirja)
    • ๐Ÿ“š [UPDATE] Documentation updates and fixes. Thanks to @jsbed, Chris Maddock, Jim Aho (#369), and Mathias Lorenzen.
    • โšก๏ธ [UPDATE] Updated builds thanks to Alexandr Nikitin.
    • ๐Ÿ”จ [UPDATE] Significant refactoring thanks to Alex Povar. (#448 and many, many other PRs)