예제 #1
0
        public void SusbscribeAndUnsubscribve()
        {
            // prepare
            var expected = new NotificationEvent(null !);
            var mock     = new Mock <INotificationEventObserver>();
            var ses      = new SystemEventSource(null);

            // act
            ses.Subscribe(mock.Object);
            ses.Unsubscribe(mock.Object);
            ses.SendEvent(expected);

            // verify
            mock.AssertNoOtherCalls();
            Assert.Equal(0, ses.GetObserversCount());
        }
예제 #2
0
        public void SubscribeAndSendEvent()
        {
            // prepare
            var expected = new NotificationEvent(null !);
            var mock     = new Mock <INotificationEventObserver>();
            var ses      = new SystemEventSource(null);

            // act
            ses.Subscribe(mock.Object);
            ses.SendEvent(expected);

            // verify
            Assert.Equal(1, ses.GetObserversCount());
            mock.Assert(f => f.OnNotificationReceived(
                            The <NotificationEvent> .Is(ne => ReferenceEquals(expected, ne))));
        }
예제 #3
0
        public void SusbscribeAndGC()
        {
            // prepare
            var expected = new NotificationEvent(null !);
            var ses      = new SystemEventSource(null);
            var wr       = RegisterSomeWeak(ses);

            Assert.Equal(1, ses.GetObserversCount());

            // act
            GC.Collect();
            GC.WaitForPendingFinalizers();
            ses.SendEvent(expected);

            // verify
            Assert.Equal(0, ses.GetObserversCount());
            Assert.Null(wr.Target);
        }