I have a question about Rhino Mock.
I am trying to put restriction on what methods could be called from the method that is under test.
Lets say I have a method that I am writing the Unit Test against like this:
public void MyMethod()
{
var test = _Repository.Get(2);
_Services.DoSomething(test);
}
what I do right now is something like this :
[Test]
public void TestMethod()
{
var mock1 = CreateMock<IRepository>();
var mock2 = CreateMock<IServices)();
mock1.Expect(x => x.Get(1).IgnoreArguments().Return(new Poo()).Repeat.Once();
mock2.Expect(x => x.DoSomething(new Something()).IgnoreArguments().Repeat.Once();
ClassUnderTest.MyMethod();
mock1.VerifyAllExpectations();
mock2.VerityAllExpectations();
}
this is fine but what I want is to prevent somebody to change the method like this:
public void MyMethod()
{
var test = _Repository.Get(2);
var test = _Repository.Save(test);
_Services.DoSomething(test);
}
As you can see Save method on Repository is called, so this is dangerous obviously because if somebody by mistake add that line there we will be in trouble.
How can I restrict someond from doing that ? Thanks.