Is it possible to check via unit testing, if the event is subscribed or not when mocking is not possible.
I have following class "InteractiveEventManager" which takes a class called DrawingArea. The class implements IEventManager which has two methods - Subscribe() and UnSubscribe();
Subscribe method subscribes custom events from DrawingArea class.
Now I am not sure how to check if the Subscribe method has subscribed those events?
internal interface IEventManager
{
void Subscribe();
void UnSubscribe();
}
public class InteractiveEventManager: IEventManager
{
private readonly DrawingArea _drawingArea;
public InteractiveEventManager(DrawingArea drawingArea)
{
_drawingArea = drawingArea;
}
public void Subscribe()
{
_drawingArea.MouseMove += DrawingAreaMouseMove;
_drawingArea.PreviewMouseDown += DrawingAreaPreviewMouseDown;
}
private void DrawingAreaPreviewMouseDown(object sender, MouseButtonEventArgs e)
{
_drawingArea.Chart.InteractiveCurvesArea.ProcessMouseDown(
e.GetPosition(_drawingArea));
}
private void DrawingAreaMouseMove(object sender, MouseEventArgs e)
{
_drawingArea.Chart.InteractiveCurvesArea.ProcessMouseMove(
e.GetPosition(_drawingArea));
}
}
I have written following test but it does not work. Since, DrawingArea is a class(not an interface), I think we cannot call AssertWasCalled. Can you please help.
[Test]
public void When_register_then_drawing_area_mouse_move_is_registered()
{
DrawingArea drawingArea = new DrawingArea();
InteractiveEventManager interactiveEventManager =
new InteractiveEventManager(drawingArea);
interactiveEventManager.Subscribe();
drawingArea.AssertWasCalled(x => x.MouseMove +=
Arg<MouseEventHandler>.Is.Anything);
}
Thanks.