2

For the given mock object below, how can I check if the WashCar(ICar car) method is setting the TiresWashed property?

public interface ICar 
{
    string Model {get;set;}
    bool TiresWashed {get; set;}
    bool WindowsWashed {get; set; }
}

    [TestMethod]
    public vouid MyUnitTest()
    {
    ICar mockCar = MockRepository.GenerateMock<ICar>();
    CarServiceUtility.WashCar(mockCar);

    //Assert if PrepareCar method is called: (this is why I had mock)
    mockCar.AssertWasCalled(c=>c.PrepareCar());

    //TODO 
    // Assert if mockCar.TiresWashed is set with any value
    }
Amittai Shapira
  • 3,749
  • 1
  • 30
  • 54
pencilCake
  • 51,323
  • 85
  • 226
  • 363
  • 3
    possible duplicate: http://stackoverflow.com/questions/729267/rhino-mocks-assertwascalled-multiple-times-on-property-getter-using-aaa – albertjan Oct 11 '11 at 12:09
  • It is a good hint there but cannot exactly find my answer. But +1 for the link. Thx. – pencilCake Oct 11 '11 at 12:25

2 Answers2

8

From Here:

mock.AssertWasCalled(x => x.Name ="Bob");

or

mock.AssertWasCalled(x => x.Name =Arg.Is("Bob"));

or

mock.AssertWasCalled(x => x.Name =Arg<string>.Is.NotNull);
Amittai Shapira
  • 3,749
  • 1
  • 30
  • 54
0

How I managed to do it after the_ajp's link is:

mockCar.AssertWasCalled(car => { var dummy = car.TiresWashed; }, options 
 => options.SetPropertyWithArgument(Arg<object>.Is.Anything));
pencilCake
  • 51,323
  • 85
  • 226
  • 363