public void When_monitoring_an_object_it_should_monitor_all_the_events_it_exposes()
        {
            // Arrange
            var eventSource = new ClassThatRaisesEventsItself();

            using (var eventMonitor = eventSource.Monitor())
            {
                // Act
                EventMetadata[] metadata = eventMonitor.MonitoredEvents;

                // Assert
                metadata.Should().BeEquivalentTo(new[]
                {
                    new
                    {
                        EventName   = nameof(ClassThatRaisesEventsItself.InterfaceEvent),
                        HandlerType = typeof(EventHandler)
                    },
                    new
                    {
                        EventName   = nameof(ClassThatRaisesEventsItself.PropertyChanged),
                        HandlerType = typeof(PropertyChangedEventHandler)
                    }
                });
            }
        }
コード例 #2
0
        public void When_event_exists_on_class_but_not_on_monitored_interface_it_should_not_allow_monitoring_it()
        {
            // Arrange
            var eventSource = new ClassThatRaisesEventsItself();

            using var eventMonitor = eventSource.Monitor <IEventRaisingInterface>();

            // Act
            Action action = () => eventMonitor.GetRecordingFor("PropertyChanged");

            // Assert
            action.Should().Throw <InvalidOperationException>()
            .WithMessage("Not monitoring any events named \"PropertyChanged\".");
        }
コード例 #3
0
        public void When_monitoring_an_object_through_an_interface_it_should_monitor_only_the_events_it_exposes()
        {
            // Arrange
            var eventSource = new ClassThatRaisesEventsItself();

            using var monitor = eventSource.Monitor <IEventRaisingInterface>();

            // Act
            EventMetadata[] metadata = monitor.MonitoredEvents;

            // Assert
            metadata.Should().BeEquivalentTo(new[]
            {
                new
                {
                    EventName   = nameof(IEventRaisingInterface.InterfaceEvent),
                    HandlerType = typeof(EventHandler)
                }
            });
        }