.net - RhinoMocks: override a stubbed property -


Unfortunately, the following pattern does not work in rhinomox:

  [setup] Public void Setup () {Obj.Stub (s = & gt; s.Prop). Returns ("a suitable default for all tests"); } [Test] Public Zero VerySpecificTest () {obj.Stub (s => s.Prop). Returns ("Valid values, only valid for a single test"); }  

It also does not make an exception (which is particularly bad), the user does not know why there is no one in the second stub () call Effect anything

However, is there a way to do this work? How to "overwrite" a single property return?

IIRC, the supported way of overriding the behavior that was already entered is either the stub or the duplicate Rhino Max The old API is back: You can use BackToRecord because the stub can forget its previously recorded behavior, then use replay to go back playback Again in the mode again press Enter:

  [setup] Public zero setup () {obj.Stub (s => s.Prop). ("A suitable default test for everyone"); } [Test] Public Zero VerySpecificTest () {// Obj.BackToRecord (); // Clearly recorded expectations and immediately return to game mode again; Obj.Replay (); // Setup now is a new hope Obj.Stub (s = & gt; s.Prop). Returns ("Valid values, only valid for a single test"); }  

For the sake of this method it is that Bacotorker lets the stub forget all the expectations set for it (not only want to override you). There are some harriers that avoid this (e.g., using repeat or using lambda to set the initial stub so that you later return the value For example, for some of these), but there is no supported API for this.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -