c# - Rhino Mocks - Raise Event When Property Set -


i want raise event on stub object whenever property set using rhino mocks. e.g.

public interface ifoo {    int currentvalue { get; set; }    event eventhandler currentvaluechanged; } 

setting currentvalue raise currentvaluechanged event

i have tried mystub.expect(x => x.currentvalue).whencalled(y => mystub.raise... doesn't work because property settable , says i'm setting expectations on property defined use propertybehaviour. aware abuse of whencalled i'm none happy about.

what correct way of achieving this?

you created stub, not mock. difference stub has property behavior default.

so full implementation following:

ifoo mock = mockrepository.generatemock<ifoo>(); // variable self-made property behavior int currentvalue;  // setting value:  mock   .stub(x => currentvalue = arg<int>.is.anything)   .whencalled(call =>     {        currentvalue = (int)call.arguments[0];       mystub.raise(/* ...*/);     })  // getting value mock mock   .stub(x => currentvalue)   // return doesn't work, because need specify value @ runtime   // still used make rhinos validation happy   .return(0)   .whencalled(call => call.returnvalue = currentvalue); 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -