Question

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 );    
}
Was it helpful?

Solution

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"});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top