I am testing a controler using Moq and I get a NullReferenceException when the method I'm testing raises an event. Any idea on how to solve this ?
Here is the test code :
//Arrange
mockNumeriseur.Setup(x => x.InitialiserNumerisation());
mockCommande.Setup(x => x.ConnaitreStatut()).Returns(numerisationReussie);
mockNumeriseur.Setup(x => x.Numeriser(false, It.IsAny<string>(), It.IsAny<IntPtr>()));
//Act
controleur.Numeriser(new IntPtr(), false, false, false);
//Assert
mockNumeriseur.Verify(x => x.InitialiserNumerisation(), Times.Once());
mockCommande.Verify(x => x.ConnaitreStatut(), Times.Once());
mockNumeriseur.Verify(x => x.Numeriser(false, It.IsAny<string>(), It.IsAny<IntPtr>()), Times.Once());
Here is the line that causes the issue :
ActiverBoutonsNumerisationUniqueEvent(this, new BooleanEventArgs(false));
BooleanEventArgs extends EventArgs to allow passing a boolean to the EventHandler.
Edit : I know what a NullReferenceException is, what I'm trying to figure out is why my unit tests cause one when this event is triggered. I think it might have something to do with Unity/Moq but I'm new to these libraries so I don't know where to start.