CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: C#

NMock -> RhinoMocks

187 Views
Copy Code Show/Hide Line Numbers
/************************************************************/
/* Set expectations for a method to be called only once     */
/************************************************************/
// NMock:
Expect.Once.On(mockLookupList).Method("Clear");
 
// Rhino Mocks
mockLookupList.Expect(x => x.Clear()).Repeat.Once();
 
/************************************************************/
/* Set expectations for a method call with return value     */
/************************************************************/
// NMock: 
// Check
Expect.Once.On(mockLookupList).Method("GetLookupCollection").Return(mockLookupCollection);
 
// Rhino Mocks:
mockLookupList.Expect(x => x.GetLookupCollection())
   .Return(mockLookupCollection)
   .Repeat.Once();
 
/************************************************************/
/* Set expectations for a method call with parameters       */
/************************************************************/
// NMock: 
Expect.Once.On(mockLookupList).Method("Add").With(lookupDTO);
 
// Rhino Mocks
mockLookupLIst.Expect(x => x.Add(lookupDTO)).Repeat.Once();
 
/***********************************************************************/
/* Set expectations that a method called, we don't care how many times */
/***********************************************************************/
 
// NMock: 
Stub.On(mockLookupList).Method("Clear");
 
// Rhino Mocks:
mockLookupList.Stub(x => x.Clear()); // check
 
 
/***********************************************************************/
/* Dynamic mocks */
/***********************************************************************/
 
// NMock: 
DynamicMock mockUser = new NMock.DynamicMock(typeof(IUserInfo));
 
// Rhino Mocks:
MockRepository mocks = new MockRepository();
IUserInfo mockuser = mocks.DynamicMock<IUserInfo>();
 
 
/***********************************************************************/
/* SetupResult */
/* tell the data mock to return sources when it gets called with Retrieve(). */
/***********************************************************************/
 
IList<Source> sources = new List<Source>()
{
    new Source("x"),
    new Source("y"),
    new Source("z")
};
 
// NMock:
_Data.SetupResult("Retrieve", sources);
 
// Rhino Mocks:
SetupResult.For(_Data.Retrieve()).Return(sources);
by Cat
  June 22, 2010 @ 12:53pm
Tags:

Add a comment


Report Abuse
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate