How to imitate Elma?
I've seen this post, but I'm a little confused about this.
How can I mock Elmah's ErrorSignal procedure?
I'm looking at option 2
Create a wrapper class around the call to Raise and just mock out the wrapper class.
public class ErrorSignaler {
public virtual void SignalFromCurrentContext(Exception e) {
if (HttpContext.Current != null)
Elmah.ErrorSignal.FromCurrentContext().Raise(e);
}
}
I'm a little confused that this doesn't seem to implement the interface, and I'm not entirely sure why it seems in place for some sort of inheritance.
thank
source to share
The idea here is that you would use a class ErrorSignaler
in your code to signal an error instead of calling Elmah directly. When running your code in unit tests, since HttpContext.Current
it is null, the Elmah component will not be used and there will be no null reference exceptions.
You can also create an interface ErrorSignaler
:
public interface IErrorSignaler
{
void SignalFromCurrentContext(Exception e);
}
Thus, the implementation used for the implementation IErrorSignaler
can be manufactured in unit tests, if needed.
source to share