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