PosInformatique.Moq.Analyzers 1.11.0

Prefix Reserved
dotnet add package PosInformatique.Moq.Analyzers --version 1.11.0                
NuGet\Install-Package PosInformatique.Moq.Analyzers -Version 1.11.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PosInformatique.Moq.Analyzers" Version="1.11.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PosInformatique.Moq.Analyzers --version 1.11.0                
#r "nuget: PosInformatique.Moq.Analyzers, 1.11.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install PosInformatique.Moq.Analyzers as a Cake Addin
#addin nuget:?package=PosInformatique.Moq.Analyzers&version=1.11.0

// Install PosInformatique.Moq.Analyzers as a Cake Tool
#tool nuget:?package=PosInformatique.Moq.Analyzers&version=1.11.0                

PosInformatique.Moq.Analyzers

PosInformatique.Moq.Analyzers is a library to verify syntax and code design when writing the unit tests using the Moq library.

Installing from NuGet

The PosInformatique.Moq.Analyzers library is available directly on the Nuget official website.

To download and install the library to your Visual Studio unit test projects use the following NuGet command line

Install-Package PosInformatique.Moq.Analyzers

The analyzer is automatically added and activated with their default severity levels.

Rules

This section describes the list of the rules analyzed by the library to improve code quality of the unit tests using the Moq library.

Design

Design rules used to make your unit tests more strongly strict.

Rule Description
PosInfoMoq1000: VerifyAll() methods should be called when instantiate a Mock<T> instances When instantiating a Mock<T> in the Arrange phase of an unit test, VerifyAll() method should be called in the Assert phase to check the setup methods has been called.
PosInfoMoq1001: The mocked instances behaviors should be defined to Strict mode When instantiating a Mock<T> instance, the MockBehavior of the Mock instance should be defined to Strict.
PosInfoMoq1002: Verify() methods should be called when Verifiable() has been setup When a mocked member has been setup with the Verifiable() method, the Verify() method must be called at the end of the unit test.
PosInfoMoq1003: The Callback() method should be used to check the parameters when mocking a method with It.IsAny<T>() arguments When a mocked method contains a It.IsAny<T>() argument, the related parameter should be checked in the Callback() method.
PosInfoMoq1004: The Callback() parameter should not be ignored if it has been setup as an It.IsAny<T>() argument When a mocked method contains a It.IsAny<T>() argument, the related parameter should not be ignored in the Callback() method.
PosInfoMoq1005: Defines the generic argument of the SetupSet() method with the type of the mocked property When mocking the setter of a property, use the SetupSet<TProperty>() method version.

Compilation

Compilation rules check some error during the compilation to be sure that the execution of the unit tests with Mock<T> will not raise exceptions. All the rules of this category should not be disabled (or changed their severity differently of Error).

Rule Description
PosInfoMoq2000: The Returns() or ReturnsAsync() methods must be call for Strict mocks When a Mock<T> has been defined with the Strict behavior, the Returns() or ReturnsAsync() method must be called when setup a method to mock which returns a value.
PosInfoMoq2001: The Setup()/SetupSet() method must be used only on overridable members) The Setup() method must be applied only for overridable members.
PosInfoMoq2002: Mock<T> class can be used only to mock non-sealed class The Mock<T> class can mock only interfaces or non-sealed classes.
PosInfoMoq2003: The Callback() delegate expression must match the signature of the mocked method The delegate in the argument of the Callback() method must match the signature of the mocked method.
PosInfoMoq2004: Constructor arguments cannot be passed for interface mocks No arguments can be passed to a mocked interface.
PosInfoMoq2005: Constructor arguments must match the constructors of the mocked class When instantiating a Mock<T>, the parameters must match one of the constructors of the mocked type.
PosInfoMoq2006: The Protected().Setup() method must be use with overridable protected or internal methods When using the Protected().Setup() configuration, the method mocked must be overridable and protected or internal.
PosInfoMoq2007: The As<T>() method can be used only with interfaces. The As<T>() can only be use with the interfaces.
PosInfoMoq2008: The Verify() method must be used only on overridable members) The Verify() method must be applied only for overridable members.
PosInfoMoq2009: Mock.Of<T> method must be used only to mock non-sealed class The Mock.Of<T> method can mock only interfaces or non-sealed classes
PosInfoMoq2010: Mock.Of<T> method must be used only with types that contains parameterless contructor The Mock.Of<T> method requires a non-private parameterless contructor
PosInfoMoq2011: Constructor of the mocked class must be accessible. The constructor of the instantiate mocked class must non-private.
PosInfoMoq2012: The delegate in the argument of the Returns() method must return a value with same type of the mocked method. The lambda expression, anonymous method or method in the argument of the Returns() must return return a value of the same type as the mocked method or property.
PosInfoMoq2013: The delegate in the argument of the Returns()/ReturnsAsync() method must have the same parameter types of the mocked method/property. The lambda expression, anonymous method or method in the argument of the Returns()/ReturnsAsync() must have the same arguments type of the mocked method or property.
PosInfoMoq2014: The Callback() delegate expression must not return a value. The Callback() delegate expression must not return a value.
PosInfoMoq2015: The Protected().Setup() method must match the return type of the mocked method The method setup with Protected().Setup() must match the return type of the mocked method.
PosInfoMoq2016: Mock<T> constructor with factory lambda expression can be used only with classes. The factory lambda expression used in Mock<T> instantiation must used only for the classes.
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.11.0 247 10/28/2024
1.10.0 382 9/2/2024
1.9.3 159 8/19/2024
1.9.2 104 8/6/2024
1.9.1 146 7/17/2024
1.8.0 121 7/3/2024
1.7.0 104 6/28/2024
1.6.0 94 6/24/2024
1.5.0 120 6/10/2024
1.4.0 629 2/26/2024
1.3.0 348 12/5/2023
1.2.0 265 11/7/2023
1.1.0 203 11/7/2023
1.0.0 226 11/1/2023

1.11.0
     - Add new rules:
       - PosInfoMoq1005: Defines the generic argument of the SetupSet() method with the type of the mocked property.
       - PosInfoMoq2014: The delegate in the argument of the Returns() method must return a value with same type of the mocked method.
       - PosInfoMoq2015: The Protected().Setup() method must match the return type of the mocked method.
       - PosInfoMoq2016: Mock<T> constructor with factory lambda expression can be used only with classes.
     - Improvements of the rules:
       - PosInfoMoq2001: Check that property setup with the SetupSet() method are overridable.
     - Fix the PosInfoMoq1001 rule for the Mock<T> instantiation with the lambda expression to create mock instances.
     - Fix the PosInfoMoq2004 rule for the Mock<T> instantiation with the lambda expression to create mock instances.
     - Fix the PosInfoMoq1001 fixer when using the Mock.Of<T> as argument in the constructor call.

     1.10.0
     - Add new rules:
     - PosInfoMoq2012: The delegate in the argument of the Returns() method must return a value with same type of the mocked method.
     - PosInfoMoq2013: The delegate in the argument of the Returns()/ReturnsAsync() method must have the same parameter types of the mocked method/property.

     1.9.3
     - Fix the PosInfoMoq2006 when Setup() a method/property in inherited class.

     1.9.2
     - Fix the PosInfoMoq1003 to raise warnings when using InSequence() method.
     - Fix the PosInfoMoq2003 to raise errors when using InSequence() method.

     1.9.1
     - Add new rules:
     - PosInfoMoq2009: Mock.Of<T> method must be used only to mock non-sealed class
       - PosInfoMoq2010: Mock.Of<T> method must be used only with types that contains parameterless contructor
       - PosInfoMoq2011: Constructor of the mocked class must be accessible.
     - Fix the PosInfoMoq1001 to check the MockBehavior usage to strict.
     
     1.8.0
     - Add new rules:
       - PosInfoMoq1003: The Callback() method should be used to check the parameters when mocking a method with It.IsAny<T>() arguments.
       - PosInfoMoq1004: The Callback() parameter should not be ignored if it has been setup as an It.IsAny<T>() argument.
     
     1.7.0
     - Add new rules:
       - PosInfoMoq1002: Verify() methods should be called when Verifiable() has been setup.
     - Fix the PosInfoMoq1000 rule to check only the call to VerifyAll() method.
     - Fix a bug when developer use custom Setup() method when using Moq.
       
     1.6.0
     - Add new rules:
       - PosInfoMoq2007: The As<T>() method can be used only with interfaces.
       - PosInfoMoq2008: The Verify() method must be used only on overridable members
     - Add the support of static methods VerifyAll() and Verify() for the PosInfoMoq2000 rule.
     - Various optimizations to increase speed of analysis.
     - Various optimizations to reduce memory usage.
     - Add hyperlink to the documentation of the r
     
     1.5.0
     - Add new rules:
       - PosInfoMoq2004: Check that constructor arguments can not be passed to a mocked interface.
       - PosInfoMoq2005: Check the constructors arguments passed to mocked class.
       - PosInfoMoq2006: Check that the setup method with Protected() exists, are overridable and is protected or internal.
     - Fix the PosInfoMoq2000 rule to not raise an error when the Returns()/ReturnsAsync() in invalided by the compiler.
     - Fix the PosInfoMoq2001 rule to raise error when Setup() is defined to chained members calls which are not overridable.

     1.4.0
     - Reduce the dependency of Microsoft.CodeAnalysis.CSharp to the release 4.0.1.

     1.3.0
     - Add new rules:
       - PosInfoMoq2003: Check the Callback() signature method (fixes #3).
     - Fixes the PosInfoMoq2000 rule to check the call of the Returns()/ReturnsAsync() methods for the mocked properties for the mock with Strict behavior.

     1.2.0
     - Add new rules:
       - PosInfoMoq2001: The Setup() method must be used only on overridable members.
       - PosInfoMoq2002: Mock<T> class can be used only to mock non-sealed class.
     
     1.1.0
     - Add new rules:
       - PosInfoMoq2000: The Returns() or ReturnsAsync() methods must be call for Strict mocks.

     1.0.0
     - Initial version with the followings rules:
       - PosInfoMoq1000: Verify() and VerifyAll() methods should be called when instantiate a Mock<T> instances
       - PosInfoMoq1001: The Mock<T> instance behavior should be defined to Strict mode.