我正在使用 DotCover 检查单元测试覆盖率。在我从 SearchResult 中的活动目录返回结果的方法之一中,我模拟了该类,但 DotCover 显示 0%
public virtual T SearchOneRecord(ISearchConfigurator configurator)
{
var record = (T)Activator.CreateInstance(typeof(T));
var searchResult = configurator.DirectorySearcher.FindOne();
if (searchResult != null)
{
AssignActiveDirectoryValue(searchResult, record);
}
return record;
}
[Test]
public void SearchOneRecord()
{
//Arrange
var configuratorMock = MockRepository.GenerateMock<ISearchConfigurator>();
var searchMock = MockRepository.GenerateStub<Searcher<NativeDs>>();
searchMock.Replay();
var nativeDs = new NativeDs() { PasswordAge = 100 };
searchMock.Expect(x => x.SearchOneRecord(configuratorMock)).Return(nativeDs);
//Act
var record = searchMock.SearchOneRecord(configuratorMock);
//Assert
Assert.AreEqual(nativeDs.PasswordAge, record.PasswordAge);
}
测试通过了,但由于我是 RhinoMock 的新手(一般是在模拟),所以可能存在问题。
任何的想法?