public interface IMyINterface
{
int GetMeSomeInteger();
Toy GetMeAToy(string toyName);
}
[TestMethod]
public void PlayWithANumber_RecievesInteger_DoRightJob()
{
IMyINterface stub = MockRepository.GenerateStub<IMyINterface>();
// HOW CAN I? :
// Instruct GetMeSomeIngeter() method in stub to return 5
// HOW CAN I? :
// Instruct GetMeAToy(string toyName) method in stub to return
//new Toy() {ToyName = "Gizmo", Code = "0989"}
var five = stub.GetMeSomeInteger();
var gizmo = GetMeAToy("Gizmo");
Assert.IsTrue(DoSomething(five, gizmo) == 100 );
}
Asked
Active
Viewed 225 times
2

pencilCake
- 51,323
- 85
- 226
- 363
1 Answers
4
Scenario 1:
var myInterface = MockRepository.GenerateStub<IMyINterface>();
myInterface.Stub(x => x.GetMeSomeIngeter()).Return(5);
Scenario 2:
var myInterface = MockRepository.GenerateStub<IMyINterface>();
myInterface.Stub(x => x.GetMeAToy("Gizmo")).Return(new Toy() {ToyName = "Gizmo", Code = "0989"});

Samich
- 29,157
- 6
- 68
- 77
-
But I don't need a mock; I need a stub. Besides, do you think we can approach this without using Record; what I mean is by Arrange-Assert-Act approach? – pencilCake Oct 07 '11 at 07:29
-
I described only Arrange step.. You also need to invoke your members (this will be Act) and then check returned values (will be Assert). – Samich Oct 07 '11 at 07:30
-
I've left only latest samples. – Samich Oct 07 '11 at 07:31