public void AddConsumer_ThrowsExceptionWhenPassingSameConsumerMoreThanOnce() { SmartWarehouse<FormattedText> warehouse = new SmartWarehouse<FormattedText>(20); PasswordDistributor distributor = new PasswordDistributor(warehouse); PasswordConsumer consumer = new PasswordConsumer(new FormattedText("cba")); distributor.AddConsumer(consumer); Assert.Throws(typeof(ArgumentException), delegate() { distributor.AddConsumer(consumer); }); }
public void AddConsumer_ThrowsExceptionWhenPassingNullReference() { SmartWarehouse<FormattedText> warehouse = new SmartWarehouse<FormattedText>(20); PasswordDistributor distributor = new PasswordDistributor(warehouse); Assert.Throws(typeof(NullReferenceException), delegate() { distributor.AddConsumer(null); }); }
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 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(); }