Esempio n. 1
0
        public async Task Should_NotInvokeAnyEventHandlers_When_AGlobalRefreshIsScheduled()
        {
            _target = new ProtocolEventDebouncer(new TaskBasedTimerFactory(), TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(20));

            var callbacks = new List <Task>
            {
                _target.HandleEventAsync(CreateProtocolEvent("ks", true), false),
                _target.HandleEventAsync(CreateProtocolEvent("ks2", true), false),
                _target.HandleEventAsync(CreateProtocolEvent("ks", false), false),
                _target.HandleEventAsync(CreateProtocolEvent("ks2", false), false),
                _target.HandleEventAsync(CreateProtocolEvent(), false),
                _target.HandleEventAsync(CreateProtocolEvent(), true),
            };
            var tasks        = _tasks.ToArray();
            var handlerTask1 = tasks[0];
            var handlerTask2 = tasks[1];
            var handlerTask3 = tasks[2];
            var handlerTask4 = tasks[3];
            var handlerTask5 = tasks[4];
            var handlerTask6 = tasks[5];

            await Task.WhenAll(callbacks).ConfigureAwait(false);

            Assert.IsFalse(handlerTask1.IsCompleted);
            Assert.IsFalse(handlerTask2.IsCompleted);
            Assert.IsFalse(handlerTask3.IsCompleted);
            Assert.IsFalse(handlerTask4.IsCompleted);

            // last global event wins
            Assert.IsFalse(handlerTask5.IsCompleted);
            Assert.IsTrue(handlerTask6.IsCompleted);
        }