I have the following code in a unit test where I am using Moq
:
Mock<BorderedCanvas> canvas2 = new Mock<BorderedCanvas>();
canvas2.Object.Children.Add(canvas1);
canvas1.RaiseEvent(someEvent);
canvas2.Verify(c => c.RaiseEvent(It.IsAny<RoutedEventArgs>()), Times.Once);
The code fails on the second line with this message:
System.NullReferenceException : Object reference not set to an instance of an object.
Any idea why I can not access the underlying object of the mock canvas2
?