Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 17th, 2012  |  syntax: None  |  size: 0.70 KB  |  hits: 22  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Rhino Mocks - Raise Event When Property Set
  2. public interface IFoo
  3. {
  4.    int CurrentValue { get; set; }
  5.    event EventHandler CurrentValueChanged;
  6. }
  7.        
  8. IFoo mock = MockRepository.GenerateMock<IFoo>();
  9. // variable for self-made property behavior
  10. int currentValue;
  11.  
  12. // setting the value:
  13. mock
  14.   .Stub(x => CurrentValue = Arg<int>.Is.Anything)
  15.   .WhenCalled(call =>
  16.     {
  17.       currentValue = (int)call.Arguments[0];
  18.       myStub.Raise(/* ...*/);
  19.     })
  20.  
  21. // getting value from the mock
  22. mock
  23.   .Stub(x => CurrentValue)
  24.   // Return doesn't work, because you need to specify the value at runtime
  25.   // it is still used to make Rhinos validation happy
  26.   .Return(0)
  27.   .WhenCalled(call => call.ReturnValue = currentValue);