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); }
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) ); }
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); }