Jan 20, 2009

An Example of Mock

 [Test] 
Public void Analyze_TooShortFileName_ErrorLoggedToService() 
{ 
MockRepository mocks = new MockRepository(); 
IWebService simulatedService =  
mocks.CreateMock(); 
 
//pre-arrange setting
 using(mocks.Record()) 
 { 
    simulatedService.LogError("file name was too short "); 
 } 
 
//play
    LogAnalyzer log = new LogAnalyzer(simulatedService); 
      string tooShortFileName="abc.ext"; 
      log.Analyze(tooShortFileName); 

//verify
mocks.VerifyAll(); 

}