public void QueenBee_DontProduceBeeBeforeTheTime() { QueenBee bee = new QueenBee(); int children = 0; bee.ActionPerformed += (sender, args) => { if (args.ActionType == BeeActionType.ProduceBee) { Interlocked.Increment(ref children); } }; bee.RequestForBeehiveData += (sender, args) => { }; bee.StartWork(); Task.Delay((int)(this.queenBalance.TimeToProduceBee.TotalMilliseconds / 2)) .GetAwaiter().GetResult(); Assert.AreEqual(0, children); bee.StopWork(); }
public void QueenBee_ProduceBees() { QueenBee bee = new QueenBee(); int children = 0; bee.ActionPerformed += (sender, args) => { if (args.ActionType == BeeActionType.ProduceBee) { Interlocked.Increment(ref children); } }; bee.RequestForBeehiveData += (sender, args) => { }; bee.StartWork(); Task.Delay((int)this.queenBalance.TimeToProduceBee.TotalMilliseconds * 10).GetAwaiter().GetResult(); bee.StopWork(); Assert.IsTrue(Math.Abs(children - 10) <= 10 * QueenBeeTests.Inaccuracy); }