public void AddProducer_ThrowsExceptionWhenPassingNullReference()
 {
     SmartWarehouse<FormattedText> warehouse = new SmartWarehouse<FormattedText>(20);
     PasswordDistributor distributor = new PasswordDistributor(warehouse);
     Assert.Throws(typeof(NullReferenceException), delegate()
     {
         distributor.AddProducer(null);
     });
 }
 public void AddProducer_ThrowsExceptionWhenPassingSameProducerMoreThanOnce()
 {
     SmartWarehouse<FormattedText> warehouse = new SmartWarehouse<FormattedText>(20);
     PasswordDistributor distributor = new PasswordDistributor(warehouse);
     PasswordProducer producer = new PasswordProducer(new FormattedText("abc"));
     distributor.AddProducer(producer);
     Assert.Throws(typeof(ArgumentException), delegate()
     {
         distributor.AddProducer(producer);
     });
 }
        public void StartConsumption_ThrowsExceptionWhenTryingToCallMethodWhenConsumptionIsNotStopped()
        {
            SmartWarehouse<FormattedText> warehouse = new SmartWarehouse<FormattedText>(20);
            PasswordDistributor distributor = new PasswordDistributor(warehouse);
            PasswordConsumer consumer = new PasswordConsumer(new FormattedText("cba"));
            consumer.PasswordTakingMaximumTime = 20;
            distributor.AddConsumer(consumer);

            distributor.StartConsumption();
            Assert.Throws(typeof(InvalidOperationException), delegate()
            {
                distributor.StartConsumption();
            });
            Thread.Sleep(2);
            consumer.StopConsumption();
        }
        static void Main(string[] args)
        {
            SmartWarehouse<FormattedText> warehouse = new SmartWarehouse<FormattedText>(20);
            PasswordProducer pp = new PasswordProducer(new FormattedText("abc"));
            PasswordConsumer pc = new PasswordConsumer(new FormattedText("cba"));

            PasswordDistributor distributor = new PasswordDistributor(warehouse);
            distributor.AddProducer(pp);
            distributor.AddConsumer(pc);
            distributor.StartConsumption();

            PasswordConsumer consumer = new PasswordConsumer(new FormattedText("bca"));
            distributor.AddConsumer(consumer);

            distributor.StartProduction();

            PasswordProducer producer = new PasswordProducer(new FormattedText("abc"));
            distributor.AddProducer(producer);

            Console.ReadLine();
            Console.WriteLine(warehouse.Count);
        }
        public void StartProduction_ThrowsExceptionWhenTryingToCallMethodWhenProductionIsNotStopped()
        {
            SmartWarehouse<FormattedText> warehouse = new SmartWarehouse<FormattedText>(20);
            PasswordDistributor distributor = new PasswordDistributor(warehouse);
            PasswordProducer producer = new PasswordProducer(new FormattedText("abc"));
            producer.PasswordAdditionMaximumTime = 20;
            distributor.AddProducer(producer);

            distributor.StartProduction();
            Assert.Throws(typeof(InvalidOperationException), delegate()
            {
                distributor.StartProduction();
            });
            producer.StopProduction();
        }
 public void ReturnsPasswordDistributorObject()
 {
     SmartWarehouse<FormattedText> warehouse = new SmartWarehouse<FormattedText>(20);
     PasswordDistributor distributor = new PasswordDistributor(warehouse);
     Assert.IsNotNull(distributor);
 }
 public void ThrowsExceptionWhenPassingNullReferenceToConstructor()
 {
     SmartWarehouse<FormattedText> warehouse = null;
     Assert.Throws(typeof(NullReferenceException), delegate()
     {
         PasswordDistributor distributor = new PasswordDistributor(warehouse);
     });
 }