public async Task EventHoldsWeakReference()
        {
            var eventFirer = new EventFirer();

            WeakReference reference;

            {
                var handler = new Handler <EventArgs <string> >();
                reference = new WeakReference(handler);

                eventFirer.MyEvent += handler.HandleEvent;
                eventFirer.OnMyEvent("FooBar");
            }

            var pos = 0;

            while (reference.Target != null && pos < 10)
            {
                await Task.Delay(1000);

                GC.Collect();
                GC.WaitForPendingFinalizers();

                eventFirer.OnMyEvent("HelloWorld");

                pos++;
            }

            reference.Target.Should().BeNull();

            GC.KeepAlive(eventFirer);
        }
        public void FiringEventFiresToHandler()
        {
            string result = null;

            var eventFirer = new EventFirer();

            eventFirer.MyEvent += (s, e) => { result = e.Value; };
            eventFirer.OnMyEvent("FooBar");

            result.Should().Be("FooBar");
        }
        public void FiringRemovedSimpleEventDoesntFireToHandler()
        {
            var fired = false;

            var          eventFirer = new EventFirer();
            EventHandler handler    = (sender, args) => fired = true;

            eventFirer.MySimpleEvent += handler;
            eventFirer.MySimpleEvent -= handler;
            eventFirer.OnMyEvent("FooBar");

            fired.Should().BeFalse();
        }
        public void FiringRemovedEventDoesntFireToHandler()
        {
            string result = null;

            var eventFirer = new EventFirer();
            EventHandler <EventArgs <string> > handler = (sender, args) => result = args.Value;

            eventFirer.MyEvent += handler;
            eventFirer.MyEvent -= handler;
            eventFirer.OnMyEvent("FooBar");

            result.Should().BeNull();
        }
        public void FiringEventFiresToMultipleHandlers()
        {
            string result1 = null;
            string result2 = null;

            var eventFirer = new EventFirer();

            eventFirer.MyEvent += (s, e) => { result1 = e.Value; };
            eventFirer.MyEvent += (s, e) => { result2 = e.Value; };
            eventFirer.OnMyEvent("FooBar");

            result1.Should().Be("FooBar");
            result2.Should().Be("FooBar");
        }