public void StartProduction_ThrowsExceptionWhenPassingNullReferenceArgument() { SmartWarehouse<FormattedText> warehoue = null; PasswordProducer pp = new PasswordProducer(new FormattedText("abc")); Assert.Throws(typeof(NullReferenceException), delegate() { pp.StartProduction(warehoue); }); }
public void StopProduction_SuccessfullyStopsProduction() { SmartWarehouse<FormattedText> warehouse = new SmartWarehouse<FormattedText>(20); PasswordProducer pp = new PasswordProducer(new FormattedText("abc")); Assert.DoesNotThrow(delegate() { pp.StartProduction(warehouse); pp.StopProduction(); }); }
public void ReturnsPasswordProducerObject() { FormattedText alphabet = new FormattedText("abc"); PasswordProducer pp = new PasswordProducer(alphabet); Assert.IsNotNull(pp); PermutationGenerator generator = new PermutationGenerator(alphabet); pp = new PasswordProducer(generator); Assert.IsNotNull(pp); }
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 ThrowsExceptionWhenPassingNullReferenceArgumentToConstructor() { FormattedText alphabet = null; Assert.Throws(typeof(NullReferenceException), delegate() { PasswordProducer pp = new PasswordProducer(alphabet); }); PermutationGenerator generator = null; Assert.Throws(typeof(NullReferenceException), delegate() { PasswordProducer pp = new PasswordProducer(generator); }); }
public void AddProducer(PasswordProducer producer) { if (producer == null) throw new NullReferenceException(); if(producers.Contains(producer)) throw new ArgumentException("Producer is already on list."); producers.Add(producer); lock (synchronizationObject) { if (ProductionStarted) producer.StartProduction(warehouse); } }
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(); }