internal async Task Generic_Async_Event_Should_Run_Asynchronously()
        {
            var notifier = new GenericNotifier();
            var tcs      = new TaskCompletionSource <object>();
            int?value    = null;

            async Task RespondToSomethingHappening(object sender, ExampleEventArgs eventArgs)
            {
                await tcs.Task;

                value = eventArgs.Value;
            }

            notifier.SomethingHappened += RespondToSomethingHappening;

            var eventTask = notifier.OnSomethingHappening(2);

            await Task.Delay(100);

            value.ShouldBeNull();
            tcs.SetResult(null);

            await eventTask;

            value.ShouldBe(2);
        }
        internal async Task Generic_Synchronous_Event_Handlers_Should_Be_Convertible_To_Equivalent_Asynchronous_Handlers()
        {
            var notifier = new GenericNotifier();
            int?value    = null;

            notifier.SomethingHappened += Async <ExampleEventArgs>((sender, args) => value = args.Value);

            await notifier.OnSomethingHappening(2);

            value.ShouldBe(2);
        }
Exemple #3
0
        internal void Generic_Invoke_Async_Should_Return_Completed_Task_If_No_Handlers_Are_Subscribed()
        {
            var notifier = new GenericNotifier();

            notifier.OnSomethingHappening(3).IsCompleted.ShouldBeTrue();
        }