Пример #1
0
        public void WeakEventManager_NullEventManager()
        {
            // Arrange
            WeakEventManager <string>?unassignedEventManager = null;

            // Act

            // Assert
#pragma warning disable CS8602 //Dereference of a possible null reference
            Assert.Throws <NullReferenceException>(() => unassignedEventManager.RaiseEvent(this, string.Empty, nameof(TestEvent)));
#pragma warning restore CS8602
        }
        public void WeakEventManager_UnassignedEventManager()
        {
            // Arrange
            var unassignedEventManager = new WeakEventManager();
            var didEventFire           = false;

            TestEvent += HandleTestEvent;
            void HandleTestEvent(object?sender, EventArgs e) => didEventFire = true;

            // Act
            unassignedEventManager.RaiseEvent(null, null, nameof(TestEvent));

            // Assert
            Assert.False(didEventFire);
            TestEvent -= HandleTestEvent;
        }
Пример #3
0
        public void WeakEventManagerTEventArgs_UnassignedEventManager()
        {
            // Arrange
            var unassignedEventManager = new WeakEventManager <string>();
            var didEventFire           = false;

            TestStringEvent += HandleTestEvent;
            void HandleTestEvent(object?sender, string e) => didEventFire = true;

            // Act
#pragma warning disable CS8625 //Cannot convert null literal to non-nullable reference type
            unassignedEventManager.RaiseEvent(null, null, nameof(TestStringEvent));
#pragma warning restore CS8625

            // Assert
            Assert.False(didEventFire);
            TestStringEvent -= HandleTestEvent;
        }
 protected void OnSourceChanged() =>
 weakEventManager.RaiseEvent(this, EventArgs.Empty, nameof(SourceChanged));
Пример #5
0
 void OnResumed() => resumedEventManager.RaiseEvent(this, System.EventArgs.Empty, nameof(Resumed));
Пример #6
0
 void OnBoxLayoutUpdated(object sender, LayoutEventArgs e) => weakEventManager.RaiseEvent(this, e, nameof(LayoutUpdated));
 public void RaiseEventShouldInvokeAddedHandler()
 {   var raised = false;
     EventHandler handler = ( s, e ) => raised = true;
     var target = new WeakEventManager<EventHandler, EventArgs>();
     target.AddHandler( handler );
     target.RaiseEvent( this, EventArgs.Empty );
     Assert.True( raised );
 }