public async Task InvokeAsync_DerivedEventArgsWithFaultedBackgroundTasks_ShouldCompleteFaulted()
        {
            // Arrange.
            var error = new Exception();

            DerivedEvent += (sender, e) => e.RegisterBackgroundTask(Task.CompletedTask);
            DerivedEvent += (sender, e) => e.RegisterBackgroundTask(async cancellationToken =>
            {
                await Task.Yield();

                cancellationToken.ThrowIfCancellationRequested();
            });
            DerivedEvent += (sender, e) => e.RegisterBackgroundTask(async cancellationToken =>
            {
                await Task.Yield();

                throw error;
            });

            using (var cancellationSource = new CancellationTokenSource())
            {
                cancellationSource.Cancel();

                // Act.
                var args   = new DerivedEventArgs(cancellationSource.Token);
                var thrown = await Assert.ThrowsAsync <Exception>(() => DerivedEvent.InvokeAsync(this, args));

                // Assert.
                Assert.Equal(error, thrown);
            }
        }
        public async Task InvokeAsync_DerivedEventArgsWithSucceededBackgroundTasks_ShouldCompleteSucceeded()
        {
            // Arrange.
            DerivedEvent += (sender, e) => e.RegisterBackgroundTask(Task.CompletedTask);

            // Act.
            var args = new DerivedEventArgs(CancellationToken.None);
            await DerivedEvent.InvokeAsync(this, args);
        }
Esempio n. 3
0
            public void can_listen_to_base_events()
            {
                var host = new EventHost();

                host.Listen <BaseEvent>(typeof(BaseEventHandler));

                var @event = new DerivedEvent();

                host.Raise(@event, null);

                Assert.Equal(1, @event.Value);
            }
Esempio n. 4
0
            public void can_listen_to_event_interfaces()
            {
                var host = new EventHost();

                host.Listen <IEvent>(typeof(AllEventHandler));

                var @event = new BaseEvent();

                host.Raise(@event, null);
                Assert.Equal(5, @event.Value);

                @event = new DerivedEvent();

                host.Raise(@event, null);
                Assert.Equal(5, @event.Value);
            }
Esempio n. 5
0
 public void FireDerivedEvent1()
 {
     DerivedEvent?.Invoke(this, EventArgs.Empty);
 }
Esempio n. 6
0
 public void Handle(DerivedEvent eventInfo)
 {
     DerivedHandleCount++;
 }
        public void InvokeAsync_DerivedEventArgsWithNoSubscribers_ShouldReturnCompletedTask()
        {
            var task = DerivedEvent.InvokeAsync(this, new DerivedEventArgs(CancellationToken.None));

            Assert.Same(Task.CompletedTask, task);
        }