c# - unit testing/ mocking static event handlers, what are the available options? -


GC is fully aware of "problem" with steady event handlers from perspective, so I'm not looking "for advice" in this situation, it is not a matter of concern.

I have a static class in which declaration is an event

  public static event EventHandler & lt; MyEventArgs & gt; FilePickedUpFromStorage;  

I have a client service that subscribes to this event and to specify / handle the static event with fake MyEventArgs to specify handling tasks specified on the client Want to Straight stuff ... .... The problem I have is that this event is stable on the static class. I am looking for some concrete guidance on the best way to deal with this, if anyone can give support, changing the static event is not an option, wrapping it up or any other magic ...

< P> Thanks!

You can place a steady event for "legacy compatibility" and for the new (and testable) code Can provide better structure.

  // Heritage Public Static Class OldClass {Public Stable Event EventHandler & lt; MyEventArgs & gt; FilePickedUpFromStorage; } // testability new interface for the public interface IBRAVELNewWorld {event EventHandler & lt; MyEventArgs & gt; FilePickedUpFromStorage; } // New implementation public class BraveNewWorld: IBraveNewWorld {Public Event EventHandler & lt; MyEventArgs & gt; FilePickedUpFromStorage; Public BraveNewWorld () {// MyHandler Next Old Cloud Event FilePickedUpFromStorage + = MyHandler; }} // // New Testable User Incident Public Class TestableClass {// Here you are an example of a fake or BraveNewWorld Public TestableClass (IBraveNewWorld x) {}}  
can give

Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -