Tuesday 15 May 2012

c# - Moq'ing the raising of events multiple times -


In a special unit test, I am trying to increase an event several times and then after the last event a property value I'm trying to increase. has been raised. I have something like this

  public zero turnarite () {var mokfu = new fake & lt; IFoo & gt; (); Some services some service = new service (); SomeService.Foo = Mokfu.Object; Mockfoo.rise (eff = gt; fu vice versa + = faucet, event araz. Empty); Mockfoo.rise (eff = gt; fu vice versa + = faucet, event araz. Empty); Mockfoo.rise (eff = gt; fu vice versa + = faucet, event araz. Empty); Mokfu Verify (foo = & gt; foo.Orientation = Orientation. Vest); }  

Orientation was actually changed only in the past (as I believe the incident is only taking once). Am I doing something wrong? This is the first time that I have used the country, so I am probably missing something.

Cheers J

Edit ... The right code should have been used

  Public ZeroTurnlight () {Var mocfu = new fake & lt; IFoo & gt; (); Some services some service = new service (); SomeService.Foo = Mokfu.Object; Mockfu.setupproperty (foo = & gt; foo.Orientation); Mockfoo.rise (eff = gt; fu vice versa + = faucet, event araz. Empty); Mockfoo.rise (eff = gt; fu vice versa + = faucet, event araz. Empty); Mockfoo.rise (eff = gt; fu vice versa + = faucet, event araz. Empty); Decide. Arequal (Mockfu.Object.orientation, Orientation.South); }  

mockFoo.Raise should be ok, lift up The event three times ... Can you place a breakpoint in the event handler and check how often it is called?

Here is another possible mistake as I can see, that you should first start tracking the Mac before you can verify it (and before you increase the events): all sets / Gets to the property:

  // Start "Tracking" set / this property to Mokfu .Setupproperty (Foo => Foo.Orientation);  

No comments:

Post a Comment