-
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.
Add a new PosInfoMoq2014 rule to check if a delegate in the Callback(…
…) method does not a return a value (fixes: #35).
- Loading branch information
1 parent
350aca5
commit e5bda95
Showing
8 changed files
with
154 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# PosInfoMoq2014: The `Callback()` delegate expression must not return a value. | ||
|
||
| Property | Value | | ||
|-------------------------------------|-----------------------------------------------------------------------------------------| | ||
| **Rule ID** | PosInfoMoq2014 | | ||
| **Title** | The `Callback()` delegate expression must not return a value. | | ||
| **Category** | Compilation | | ||
| **Default severity** | Error | | ||
|
||
## Cause | ||
|
||
The delegate in the argument of the `Callback()` method must not return a value. | ||
|
||
## Rule description | ||
|
||
The lambda expression in the argument of the `Callback()` method must not return a value. | ||
|
||
```csharp | ||
[Fact] | ||
public void Test() | ||
{ | ||
var service = new Mock<Service>(); | ||
service.Setup(s => s.GetData("TOURREAU", 1234)) | ||
.Callback((string n, int age) => | ||
{ | ||
// ... | ||
return 1234; // The delegate in the Callback() method must not return a value. | ||
}) | ||
.Returns(10); | ||
} | ||
|
||
public interface IService | ||
{ | ||
public int GetData(string name, int age) { } | ||
} | ||
``` | ||
|
||
## How to fix violations | ||
|
||
To fix a violation of this rule, be sure that the delegate method in the `Callback()` method does not return a value. | ||
|
||
## When to suppress warnings | ||
|
||
Do not suppress an error from this rule. If bypassed, the execution of the unit test will be failed with a `ArgumentException` | ||
thrown with the *"Invalid callback. This overload of the "Callback" method only accepts "void" (C#) or "Sub" (VB.NET) delegates with parameter types matching those of the set up method. (Parameter 'callback')"* message. |
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