chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
Hi guys, I'm not certain if this is the same issue as shown in this thread (my results are a little different to ramnefors, and additionally I don't recognize that Isolate.Invoke.Event() method signature, but maybe this was the old version or something) so I just wanted to check whether my issues were related:

public class Z
   {
      public event EventHandler a;

      public void RaiseA() { throw new NotImplementedException(); }
   }


If I make a real object and raise the event (either explicitly or through a DoInstead callback) it works fine - this seems to be different to ramnefors experience.
      [Test] [Isolated]
      public void RealEvent()
      {
         var z = new Z();
         z.a += (sender, args) => Console.WriteLine("Event raised!");
         Isolate.Invoke.Event(() => z.a += null, new object[] { null, null });
         Isolate.WhenCalled(() => z.RaiseA())
            .DoInstead(context => Isolate.Invoke.Event(() => z.a += null, new object[] {null, null}));

         z.RaiseA();
      }



However doing the same for a faked object just does nothing (no error/exception thrown.)
      [Test] [Isolated]
      public void Fake()
      {
         var z = Isolate.Fake.Instance<Z>();
         z.a += (sender, args) => Console.WriteLine("Event Raised");
         Isolate.Invoke.Event(() => z.a += null, null);
         Isolate.WhenCalled(() => z.RaiseA())
            .DoInstead(context => Isolate.Invoke.Event(() => z.a += null, new object[] { null, null }));

         z.RaiseA();



Is there a way to implement such behaviour (subscribe to a faked object's event and have them raised)?
asked by adante (1.7k points)

1 Answer

0 votes
Hi,

Interesting. I'm not sure this is possible, because the add_event (the += ) is really faked, therefore you won't get the handler to work anyway.

However, maybe this is not that the best solution for this. I'm guessing you really want to invoke the handler, right?

In that case, why not invoke it directly with Isolate.Invoke.Method on the handler (assuming it's private) or just calling it if public?

Would that help?
answered by gilz (14.5k points)
...