-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactoring of the unit tests to use Moq library from NuGet packages (fixes #23). * Changes the PosInfoMoq1000 rule to check only VerifyAll() method call (#fixes #22). * Add the PosInfoMoq1002 rule (fixes #22). * Improving the PosInfoMoq2005 rules unit tests to check when no explicit constructors. * Improves the PosInfoMoq1002 rules to check the Verifiable() expression setup method depending of the expressions (#22). * Add unit test to check that custom Setup() method is not impacted by the analyzer (fixes #12).
- Loading branch information
1 parent
da2f494
commit fc643f3
Showing
36 changed files
with
1,043 additions
and
605 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# PosInfoMoq1002: `Verify()` methods should be called when `Verifiable()` has been setup | ||
|
||
| Property | Value | | ||
|-------------------------------------|------------------------------------------------------------------------| | ||
| **Rule ID** | PosInfoMoq1002 | | ||
| **Title** | `Verify()` methods should be called when `Verifiable()` has been setup | | ||
| **Category** | Design | | ||
| **Default severity** | Warning | | ||
|
||
## Cause | ||
|
||
A `Verify()` of an `Mock<T>` instance has not been called in the *Assert* phase | ||
of an unit test for `Verifiable()` setups. | ||
|
||
## Rule description | ||
|
||
In the *Arrange* phase of an unit test, when `Verifiable()` method has been setup to mocked member, the | ||
`Verify()` method should be called in the *Assert* phase to check the setup member has been called. | ||
|
||
```csharp | ||
[Fact] | ||
public void GetCustomer_ShouldCallRepository() | ||
{ | ||
// Arrange | ||
var smtpService = new Mock<ISmtpService>(); | ||
smtpService.Setup(s => s.SendMail("[email protected]", "Gilles")) | ||
.Verifiable(); | ||
|
||
var service = new CustomerService(repository.Object); | ||
|
||
// Act | ||
service.SendMail("Gilles"); | ||
|
||
// Assert | ||
smtpService.Verify(); // The Verify() will check that the mocked ISmtpService.SendMail() has been called (because marked with the ".Verifiable()" method). | ||
} | ||
``` | ||
|
||
## How to fix violations | ||
|
||
To fix a violation of this rule, call the `Verify()` in the *Assert* phase | ||
on the `Mock<T>` instances, if some mocked members has been marked as `Verifiable()` in the *Arrange* phase. | ||
|
||
## When to suppress warnings | ||
|
||
Do not suppress a warning from this rule. Normally `Verifiable()` setup members must be call in the unit tests execution. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.