Latest news for cialis alternatives

Average Rating: 4.8 out of 5 based on 271 user reviews.

UPDATE: I finally am posting the source !

It has been long enough since I've made my last post, but with the recent posting from about TypeMock on when mocking/testing, I thought I would throw out my solution to this problem for those of us using .

If you're not familiar with mock objects, there is some great content out there, just google it (you didn't think I was actually going to explain them here did you?!)

First off, I love NMock2.   It does what I need and stays out of my way.   The syntax is terse and flows like prose.

On with the content!

Part 1: Ready

It seems obvious to me, that if you're using mock objects, you're most likely going to run across a mock that needs to fire an event.   It's almost like the NMock2 guys completely skipped over this use case (but I'm not knocking them, this is a great product).   After digging around in reflection trying to figure how to do what I wanted and discussing it with a colleague of mine, I was turned on to the idea of using Custom Actions to catch the event add's and remove's [part 1] and store them off for invocation later (when the event is actually fired) [part 2].

Part 2: Aim - Catching the Event Add's and Remove's

The great thing about a custom action (type IAction), is that you get all sorts of information about the thing that actually got invoked.   In our case, the adder or remover of an event.   Similar to properties, the add/remove 'accessors' are compiled into methods just like the get/set accessors.   The naming of these generated methods is also similar.   For a property's get/set, the names look like:

get_<PropertyNameHere>

set_<PropertyNameHere>

Likewise, for the add/remove 'accessors' for an event get names:

add_<EventNameHere>

remove_<EventNameHere>

Armed with this information, we can tell if the method being called is an event adder/remover.   The syntax for catching an event add is as such:

Expect. Once. On(mockButton). EventAdd("Click",

 Is. Anything). Will(Catch. EventAdd);

Similarly, event removal looks like:

Expect. Once. On(mockButton). EventRemove("Click",

 Is. Anything). Will(Catch. EventRemove);

Part 3: Fire!

Great!  We know when events are added!  But wait cialis alternatives, it still seems like we haven't gotten anywhere (but really we have).   The Catch. EventAdd takes the method that got called (add_Click), and grabs the single argument from the method call which happens to be an EventHandler type delegate (in this case), and stores it off to be invoked later when the event gets fired.

Event. Fire("Click"). On(mockButton). With(this,

 EventArgs. Empty);

This call invokes all of the methods that were caught when being added to the mockButton's Click event with the given parameter values.

Often times it is useful for an event to be fired when some other mocked method gets called.   For this case, a custom action should suit just fine; simply pass it into the Will portion of your expectation/stub setup for that particular method.   That means, as soon as the mocked method gets called, the event will fire just as if the above line of code was executed.

Expect. Once. On(mockButton). Method("PerformClick").

Will(Event. Fire("Click", mockButton, this,

  EventArgs. Empty));

Here is a complete example that pulls it all together:

   interface IButton

   {

      event EventHandler Click;

 

      void PerformClick();

   }

 

   class ButtonTester

   {

      private bool clicked;

 

      [SetUp]

      public void Setup()

      {

         clicked = false;

      }

 

      [Test]

      public void TestButtonFire()

      {

         Mockery mocker = new Mockery();

         IButton mockButton = mocker. NewMock(typeof(IButton)) as IButton;

         Expect. Once. On(mockButton). EventAdd("Click", Is. Anything). Will(Catch. EventAdd);

 

         // Normally exercise domain code here,

         // but we'll keep it simple and inline.

         mockButton. Click += delegate(object sender, EventArgs args) { clicked = true; };

 

         Event. Fire("Click"). On(mockButton). With(this, EventArgs. Empty);

 

         Assert. IsTrue(clicked);

         mocker. VerifyAllExpectationsHaveBeenMet();

      }

 

      [Test]

      public void TestPerformClick()

      {

         Mockery mocker = new Mockery();

         IButton mockButton = mocker. NewMock(typeof(IButton)) as IButton;

         Expect. Once. On(mockButton). EventAdd("Click", Is. Anything). Will(Catch. EventAdd);

         Expect. Once. On(mockButton). Method("PerformClick"). Will(Event. Fire("Click", mockButton, this, EventArgs. Empty));

[cialis alternatives]

 

         // Normally exercise domain code here,

         // but we'll keep it simple and inline.

         mockButton. Click += delegate(object sender, EventArgs args) { clicked = true; };

 

cialis alternatives

         mockButton. PerformClick();

 

         Assert. IsTrue(clicked);

         mocker. VerifyAllExpectationsHaveBeenMet();

      }

   }

Thats it.   This stuff is currently unreleased, but feel free to send requests, I'll gladly send a copy.


?? 2008-2016 Legit Express Chemist.