Esempio n. 1
0
        public async Task StartAsync_doesnt_throw_when_cancelled()
        {
            var queue     = new BackgroundHandleProxyQueue();
            var processor = new BackgroundHandleProxyProcessor(queue, logger: default);

            CancellationTokenSource cts = new CancellationTokenSource(TimeSpan.Zero);

            Func <Task> startTask = () => processor.StartAsync(cts.Token);

            await startTask.Should().NotThrowAsync <OperationCanceledException>();
        }
Esempio n. 2
0
        public async Task StartAsync_processes_handle_proxy_delegates(int delegatesNumber)
        {
            var queue     = new BackgroundHandleProxyQueue();
            var logger    = Mock.Of <ILogger <BackgroundHandleProxyProcessor> >();
            var processor = new BackgroundHandleProxyProcessor(queue, logger);

            _ = processor.StartAsync(CancellationToken.None);

            AsyncAutoResetEvent resetEvent = new AsyncAutoResetEvent(false);

            Task EnqueueAsyncDelegate(int index) => queue.EnqueueAsync(cancellationToken =>
            {
                logger.LogInformation($"item: {index}");

                if (index == delegatesNumber - 1)
                {
                    resetEvent.Set();
                }

                return(Task.CompletedTask);
            }, default).AsTask();

            Task[] enqueueTasks = Enumerable.Range(0, delegatesNumber).Select(EnqueueAsyncDelegate).ToArray();

            await Task.WhenAll(enqueueTasks);

            await resetEvent.WaitAsync();

            Mock.Get(logger)
            .Verify(
                l => l.Log(
                    It.Is <LogLevel>(l => l == LogLevel.Information),
                    It.IsAny <EventId>(),
                    It.IsAny <It.IsAnyType>(),
                    It.Is <Exception>(e => e == null),
                    It.IsAny <Func <It.IsAnyType, Exception, string> >()),
                Times.Exactly(delegatesNumber));
        }
Esempio n. 3
0
        public void EnqueueAsync_throws_when_handleProxy_null()
        {
            var queue = new BackgroundHandleProxyQueue();

            Func <ValueTask> enqueueTask = () => queue.EnqueueAsync(handleProxy: null, default);