문제

I implemented an API to process EventLogRecord object.

using System.Diagnostics.Eventing.Reader;

...
MyLog ProcessEvent(EventLogRecord eventRecord)

Now, I want create unit test for this and EventLogRecord doesn't have a public constructor. How do I get a EventLogRecord object without hooking up to the event logging system?

도움이 되었습니까?

해결책

The standard way of making untestable items like this (non-virtual) work is by using a wrapper. Here is some pseducode of the idea:

WrapperEventLogRecord : IEventLogRecordWrapper
{
    ctor(EventLogRecord eventLogRecord)
    public ActivityId {get{return _eventLogRecord.ActivityId;}}
}

Now you can pass in the interface and mock it out as necessary

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