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()); }
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)))); }
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); }