![Collapse image Collapse image](collapse_all.gif)
![Expand Image Expand Image](expand_all.gif)
![](collapse_all.gif)
![](expand_all.gif)
![](dropdown.gif)
![](dropdownHover.gif)
![Copy image Copy image](icons/copycode.gif)
![CopyHover image CopyHover image](copycodeHighlight.gif)
![]() |
Moq |
Mock<(Of <(<'T>)>)>..::..Raise Method (Action<(Of <(<'T>)>)>, EventArgs) |
Mock<(Of <(<'T>)>)> Class Example See Also Send Feedback |
Raises the event referenced in eventExpression using
the given args argument.
Namespace: Moq
Assembly: Moq (in Moq.dll) Version: 4.0.10827.0 (4.0.0.0)
Syntax
Examples
The following example shows how to raise a PropertyChanged event:
CopyC#
![](CopyCode.gif)
var mock = new Mock<IViewModel>(); mock.Raise(x => x.PropertyChanged -= null, new PropertyChangedEventArgs("Name"));
Examples
This example shows how to invoke an event with a custom event arguments
class in a view that will cause its corresponding presenter to
react by changing its state:
CopyC#
![](CopyCode.gif)
var mockView = new Mock<IOrdersView>(); var presenter = new OrdersPresenter(mockView.Object); // Check that the presenter has no selection by default Assert.Null(presenter.SelectedOrder); // Raise the event with a specific arguments data mockView.Raise(v => v.SelectionChanged += null, new OrderEventArgs { Order = new Order("moq", 500) }); // Now the presenter reacted to the event, and we have a selected order Assert.NotNull(presenter.SelectedOrder); Assert.Equal("moq", presenter.SelectedOrder.ProductName);
Exceptions
Exception | Condition |
---|---|
System..::..ArgumentException | The args argument is invalid for the target event invocation, or the eventExpression is not an event attach or detach expression. |