コード例 #1
0
 private void ProcessAll()
 {
     while (_customersQueue.Count > 0)
     {
         var customer = _customersQueue.Dequeue();
         try
         {
             _server.Serve(customer);
             NotifyCustomerServed(customer);
             _customersQueue.Delete(customer);
         }
         catch (Exception ex)
         {
             TryLog(ex, customer);
             Try(() =>
             {
                 if (FailedToServiceCustomer != null)
                 {
                     FailedToServiceCustomer(this, customer);
                 }
             });
         }
     }
     NotifyGoingToSleep();
     _processInProgress = false;
 }
コード例 #2
0
        public void Barber_Process_CustomersQueue_On_CustomerArrived_Event()
        {
            var customer1Mock = Substitute.For <ICustomer>();
            var customer2Mock = Substitute.For <ICustomer>();

            _customersQueue.Dequeue().Returns(customer1Mock, customer2Mock);
            _customersQueue.Count.Returns(2, 1, 0);
            _customersQueue.CustomerArrived += Raise.Event();

            Thread.Sleep(1000);

            Received.InOrder(() =>
            {
                _server.Serve(customer1Mock);
                _customersQueue.Delete(customer1Mock);
                _server.Serve(customer2Mock);
                _customersQueue.Delete(customer2Mock);
            });
        }