You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+2-1Lines changed: 2 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -48,7 +48,8 @@ Design rules used to make your unit tests more strongly strict.
48
48
|[PosInfoMoq1006: The `It.IsAny<T>()` or `It.Is<T>()` arguments must match the parameters of the mocked method.](docs/Design/PosInfoMoq1006.md)| When setting up a method using `It.IsAny<T>()` or `It.Is<T>()` as arguments, the type `T` must exactly match the parameters of the configured method. |
49
49
|[PosInfoMoq1007: The `Verify()` method must specify the `Times` argument.](docs/Design/PosInfoMoq1007.md)| When calling the `Verify()` method, if the `Times` argument is not specified, Moq will assume `Times.AtLeastOnce()` by default. |
50
50
|[PosInfoMoq1008: The `Mock.Verify()` and `Mock.VerifyAll()` methods must specify at least one mock.](docs/Design/PosInfoMoq1008.md)| When calling the static methods `Mock.Verify()` or `Mock.VerifyAll()` without providing any `Mock<T>` instances, no verification is performed. |
51
-
|[PosInfoMoq1009: Avoid using `Verifiable()` method](docs/Design/PosInfoMoq1008.md)| A `Verify()` of an `Mock<T>` instance has not been called in the *Assert* phase of an unit test for `Verifiable()` setups. |
51
+
|[PosInfoMoq1009: Avoid using `Verifiable()` method](docs/Design/PosInfoMoq1009.md)| A `Verify()` of an `Mock<T>` instance has not been called in the *Assert* phase of an unit test for `Verifiable()` setups. |
52
+
|[PosInfoMoq1010: Use `+= null` syntax when raising events with `Raise()`/`RaiseAsync()`](docs/Design/PosInfoMoq1010.md)| When using `Mock<T>.Raise()` or `Mock<T>.RaiseAsync()`, the lambda expression used to identify the event should consistently use the `+= null` syntax. |
|**Title**| Use `+= null` syntax when raising events with `Raise()`/`RaiseAsync()`|
7
+
|**Category**| Design |
8
+
|**Default severity**| Warning |
9
+
10
+
## Cause
11
+
12
+
When using `Mock<T>.Raise()` or `Mock<T>.RaiseAsync()`, the lambda expression used to identify the event should consistently use the `+= null` syntax.
13
+
14
+
## Rule description
15
+
16
+
While Moq is flexible and can identify the event even with `+= SomeMethod`, using `+= null` is the conventional and clearest way to indicate that you are merely referencing the event for Moq's internal use, not actually subscribing a handler. This improves code readability and intent.
This is a design guideline for code readability. While suppressing it won't cause runtime errors, it's generally recommended to follow for consistent and clear code.
0 commit comments