0
我有自定義事件記錄器,我想測試它。如何構建單元測試
[Test]
public void AddLogWithExceptionAndEventLogEntryTypeTest()
{
const string loggerName = "mockLoggerName";
var logger = new MyLogger(loggerName);
System.Diagnostics.EventLog log = new System.Diagnostics.EventLog("System");
string logValue = Guid.NewGuid().ToString();
logger.AddEntry(new Exception(logValue),EventLogEntryType.Error);
foreach (
EventLogEntry entry in log.Entries)
{
if (entry.Message.ToUpper().Contains(logValue))
{
//what can is do ?
}
}
}
什麼斷言用於提供信息,該條目被添加?
你使用什麼單元測試框架? – 2010-10-04 14:09:13
nunit和rhinomock 3.6.0.0 – user278618 2010-10-04 14:10:51
可能是有用的http://bytes.com/topic/c-sharp/answers/260170-nunit-testing-eventlog-entry – 2010-10-04 14:19:40