public void RemoveFromFront()
        {
            _customerLine.Dequeue();

            if (_customerLine.Count == 0)
            {
                _lastCustomer = null;
            }
        }
 public void RegisterShouldNotHaveCustomersWhenSufficientTimeHasPassedToProcessItem()
 {
     Register register = new Register(1);
     Customer customer = new Customer(new ShorterLineStrategy(), Customer.TypeAPriorityLevel, 1, 1);
     register.AddCustomerToLine(customer);
     Assert.IsTrue(register.HasCustomers);
     register.ProcessOneMinute();
     Assert.IsFalse(register.HasCustomers);
 }
        public void SecondRegisterShouldBeBetterWhenItsLastCustomerHasFewerItems()
        {
            Customer customerWithOneItem = new Customer(null, Customer.TypeAPriorityLevel, 1, 1);
            Customer customerWithTwoItems = new Customer(null, Customer.TypeAPriorityLevel, 1, 2);

            _register1.AddCustomerToLine(customerWithTwoItems);
            _register2.AddCustomerToLine(customerWithOneItem);

            Assert.AreEqual(_register2, _strategy.GetBetterRegister(_register1, _register2));
        }
 public void LastRegisterShouldUseBeginnerTimeToProcessItemWhenThereIsOnlyOneRegister()
 {
     IList<Register> registers = _factory.GetRegisters(1);
     Customer customer = new Customer(null, Customer.TypeAPriorityLevel, 1, 1);
     Register beginnerRegister = registers[0];
     beginnerRegister.AddCustomerToLine(customer);
     Assert.IsTrue(beginnerRegister.HasCustomers);
     beginnerRegister.ProcessOneMinute();
     Assert.IsTrue(beginnerRegister.HasCustomers);
     beginnerRegister.ProcessOneMinute();
     Assert.IsFalse(beginnerRegister.HasCustomers);
 }
        public void LastCustomerInLineShouldReturnTheMostRecentCustomerAdded()
        {
            Register register = new Register(1);
            Customer customer1 = new Customer(new ShorterLineStrategy(), Customer.TypeAPriorityLevel, 1, 1);
            Customer customer2 = new Customer(new ShorterLineStrategy(), Customer.TypeAPriorityLevel, 1, 1);

            register.AddCustomerToLine(customer1);

            Assert.AreEqual(customer1, register.LastCustomerInLine);

            register.AddCustomerToLine(customer2);

            Assert.AreEqual(customer2, register.LastCustomerInLine);
        }
        public static int CompareCustomers(Customer customer1, Customer customer2)
        {
            const int customer1GoesFirst = -1;
            const int customer2GoesFirst = 1;

            if (customer1.NumberOfItems < customer2.NumberOfItems) return customer1GoesFirst;
            if (customer2.NumberOfItems < customer1.NumberOfItems) return customer2GoesFirst;

            //lower number priorities are higher priority as in 1=first, 2=second
            if (customer1.PriorityLevel < customer2.PriorityLevel) return customer1GoesFirst;
            if (customer2.PriorityLevel < customer1.PriorityLevel) return customer2GoesFirst;

            return 0;
        }
        public void PriorityCustomersShouldGoFirstWhenCustomersHaveTheSameNumberOfItems()
        {
            Customer priorityCustomerWithOneItem = new Customer(null, Customer.TypeAPriorityLevel, 1, 1);
            Customer customerWithOneItem = new Customer(null, Customer.TypeBPriorityLevel, 1, 1);
            Customer priorityCustomerWithTwoItems = new Customer(null, Customer.TypeAPriorityLevel, 1, 2);
            Customer customerWithTwoItems = new Customer(null, Customer.TypeBPriorityLevel, 1, 2);

            _customers.Add(customerWithTwoItems);
            _customers.Add(customerWithOneItem);
            _customers.Add(priorityCustomerWithOneItem);
            _customers.Add(priorityCustomerWithTwoItems);

            _customers.Sort(CustomerComparer.CompareCustomers);

            Assert.AreEqual(_customers[0], priorityCustomerWithOneItem);
            Assert.AreEqual(_customers[1], customerWithOneItem);
            Assert.AreEqual(_customers[2], priorityCustomerWithTwoItems);
            Assert.AreEqual(_customers[3], customerWithTwoItems);
        }
        public void CustomersWithFewerItemsShouldGoFirst()
        {
            Customer customerWithOneItem = new Customer(null, Customer.TypeBPriorityLevel, 1, 1);
            Customer customerWithTwoItems = new Customer(null, Customer.TypeAPriorityLevel, 1, 2);
            Customer customerWithThreeItems = new Customer(null, Customer.TypeBPriorityLevel, 1, 3);
            Customer customerWithFourItems = new Customer(null, Customer.TypeAPriorityLevel, 1, 4);

            _customers.Add(customerWithTwoItems);
            _customers.Add(customerWithOneItem);
            _customers.Add(customerWithFourItems);
            _customers.Add(customerWithThreeItems);

            _customers.Sort(CustomerComparer.CompareCustomers);

            Assert.AreEqual(_customers[0], customerWithOneItem);
            Assert.AreEqual(_customers[1], customerWithTwoItems);
            Assert.AreEqual(_customers[2], customerWithThreeItems);
            Assert.AreEqual(_customers[3], customerWithFourItems);
        }
        public void RegistersThatAreNotLastShouldUseStandardItemProcessingTime()
        {
            IList<Register> registers = _factory.GetRegisters(3);
            Customer customer1 = new Customer(null, Customer.TypeAPriorityLevel, 1, 1);
            Customer customer2 = new Customer(null, Customer.TypeAPriorityLevel, 1, 1);

            Register standardRegister1 = registers[0];
            Register standardRegister2 = registers[1];

            standardRegister1.AddCustomerToLine(customer1);
            Assert.IsTrue(standardRegister1.HasCustomers);
            standardRegister1.ProcessOneMinute();
            Assert.IsFalse(standardRegister1.HasCustomers);

            standardRegister2.AddCustomerToLine(customer2);
            Assert.IsTrue(standardRegister2.HasCustomers);
            standardRegister2.ProcessOneMinute();
            Assert.IsFalse(standardRegister2.HasCustomers);
        }
 public void ShouldThrowExceptionWhenDecrementIsCalledAndThereAreNoItems()
 {
     _customer = _testHelper.GetDefaultCustomer(0);
     Assert.Throws(typeof(ApplicationException), () => _customer.DecrementItems());
 }
 public void NumberShouldDecreaseByOneWhenDecrementIsCalled()
 {
     _customer = _testHelper.GetDefaultCustomer(5);
     _customer.DecrementItems();
     Assert.AreEqual(4, _customer.NumberOfItems);
 }
        public void HasItemsShouldBeTrueWhenNumberOfItemsIsGreaterThanZero()
        {
            _customer = _testHelper.GetDefaultCustomer(1);

            Assert.IsTrue(_customer.HasItems);
        }
        public void HasItemsShouldBeFalseWhenNumberOfItemsIsZero()
        {
            _customer = _testHelper.GetDefaultCustomer(0);

            Assert.IsFalse(_customer.HasItems);
        }
 public void AddToEnd(Customer customer)
 {
     _lastCustomer = customer;
     _customerLine.Enqueue(customer);
 }
 public void AddCustomerToLine(Customer customer)
 {
     _customerLine.AddToEnd(customer);
 }