문제

I seen this post but I am sort of confused by it.

How can I mock Elmah's ErrorSignal routine?

I am 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 am kinda confused though by the fact that this does not seem to implement an interface and I am not really sure why it seems to be in place for some sort of inheritance.

Thanks

도움이 되었습니까?

해결책

The idea here is that you would use the ErrorSignaler class in your code to signal an error instead of invoking Elmah directly. When running your code in unit tests, because HttpContext.Current is null, the Elmah component won't be used, and there won't be any null reference exceptions.

You could also create an ErrorSignaler interface:

public interface IErrorSignaler
{
    void SignalFromCurrentContext(Exception e);
}

That way the implementation used to implement IErrorSignaler can be mocked in the unit tests if required.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top