有一个方法分析文件名长度,小于8的的时候调用WebService记录,记录出错则发送邮件
public class LogAnalyzer { private IWebService service; private IEmailService email; public IWebService Service { get { return service; } set { service = value; } } public IEmailService Email { get { return email; } set { email = value; } } public void Analyze(string fileName) { if (fileName.Length < 8) { try { service.LogError("the file name is to short" + fileName); } catch (Exception e) { email.SendEmail("From@test.com", "To@test.com", "IWebServiceFailed", e.Message); } } } }
webservice和emailservice的接口
public interface IWebService { void LogError(string log); } public interface IEmailService { string ErrorMsg { get; set; } void SendEmail(string from, string to, string log, string errorMsg); }
如果想在单元测试Nunit.net中怎么使用rhino mock模拟这两个接口进行测设应该怎么写??