Assuming an IMouvement Object which contains some subobjects like ITache, IStockPalette.
public interface IMouvement : IObjectBase<Guid>
{
ITache Tache { get; set; }
IStockPalette StockPalOrigine { get; set; }
}
How can I Mock this using Rhino Mocks ?
Assuming this test, what's wrong with this ?
[TestMethod]
public void Can_Validate_EmplacementTransitoireRule()
{
var mocks = new MockRepository();
var mouvement = mocks.StrictMock<IMouvement>();
var manager = mocks.StrictMock<ValidationManager>();
mouvement.Tache = mocks.StrictMock<ITache>();
mouvement.StockPalOrigine = mocks.StrictMock<IStockPalette>();
mouvement.ID = Guid.NewGuid();
var rule = new EmplacementTransitoireRule(mouvement);
manager.AddRule(rule);
Expect.Call(manager.ValidateAll()).Return(true);
mocks.ReplayAll();
var all = manager.ValidateAll();
mocks.VerifyAll();
Assert.IsTrue(all);
}
this Test always fails ..
Typically I would set up expectations on the mock objects instead of merely assigning their properties.
Tache tache = mocks.StrictMock<Tache>();
Expect.Call( mouvement.Tache ).Return( tache );
Also, you may want to use the AAA (Arrange-Act-Assert) syntax for RhinoMocks -- I believe that StrictMock has been deprecated.
Mouvement mouvement = MockRepository.GenerateMock<Mouvement>();
Tache tache = MockRepository.GenerateMock<Tache>();
mouvement.Expect( m => m.Tache ).Return( tache );
tache.Expect( t => t.Value ).Return( 100 ); // or whatever
... test code...
tache.VerifyAllExpectations();
mouvement.VerifyAllExpectations();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.