Esempio n. 1
0
        public async void RequestShouldBeWrittenToQueue()
        {
            var queue          = new ElevatorRequestQueueUsingChannel();
            var actualRequests = new List <ElevatorRequest>();
            var elevatorSystem = new ElevatorSystem(
                new ElevatorRequestHandlerFactory(null, null, queue),
                new WaiterService(),
                queue
                );

            elevatorSystem.AddRequest(new ElevatorRequest());

            await Task.WhenAny(
                elevatorSystem.StartAsync(),
                Task.Run(async() =>
            {
                await Task.Delay(10);
                queue.Complete();
            })
                );

            await foreach (var request in queue.ReadAllAsync())
            {
                actualRequests.Add(request);
            }

            Assert.Single(actualRequests);
        }
Esempio n. 2
0
        public async Task CompletionShouldWaitUntilComplete()
        {
            var queue = new ElevatorRequestQueueUsingChannel();
            var tasks = new[]
            {
                queue.Completion,
                Task.Delay(Timeout.Infinite, CancellationToken.None)
            };

            queue.Complete();

            await Task.Factory.ContinueWhenAny(tasks, t =>
                                               Assert.Equal(Task.CompletedTask.Status, t.Status)
                                               );
        }
Esempio n. 3
0
        public async Task WriteAsyncShouldWriteToQueue()
        {
            var queue          = new ElevatorRequestQueueUsingChannel();
            var actualRequests = new List <ElevatorRequest>();

            await queue.WriteAsync(new ElevatorRequest());

            queue.Complete();
            await foreach (var request in queue.ReadAllAsync())
            {
                actualRequests.Add(request);
            }

            Assert.Single(actualRequests);
        }