public void StartConsumption_ThrowsExceptionWhenConsumptionAlreadyStarted()
 {
     SmartWarehouse<FormattedText> warehoue = new SmartWarehouse<FormattedText>(20);
     PasswordConsumer consumer = new PasswordConsumer(new FormattedText("abc"));
     consumer.StartConsumption(warehoue);
     Assert.Throws(typeof(InvalidOperationException), delegate()
     {
         consumer.StartConsumption(warehoue);
     });
 }
 public void StartConsumption_ThrowsExceptionWhenPassingNullReferenceArgument()
 {
     SmartWarehouse<FormattedText> warehoue = null;
     PasswordConsumer consumer = new PasswordConsumer(new FormattedText("abc"));
     Assert.Throws(typeof(NullReferenceException), delegate()
     {
         consumer.StartConsumption(warehoue);
     });
 }
        public void AddConsumer(PasswordConsumer consumer)
        {
            if (consumer == null)
                throw new NullReferenceException();
            if(consumers.Contains(consumer))
                throw new ArgumentException("Consumer is already on list.");

            consumers.Add(consumer);
            consumer.OnDesiredPasswordFound += (Action)OnPasswordFoundByConsumer;

            lock (synchronizationObject)
            {
                if (ConsumptionStarted)
                    consumer.StartConsumption(warehouse);
            }
        }