コード例 #1
0
        public void GuardBee_DontWorkWithoutGuardPostQueue()
        {
            GuardBee bee = new GuardBee();

            int operationsCount = 0;

            bee.ActionPerformed += (sender, args) =>
            {
                Interlocked.Increment(ref operationsCount);
            };

            bee.RequestForBeehiveData += (sender, args) =>
            {
            };

            bee.StartWork();
            Task.Delay(200).GetAwaiter().GetResult();
            bee.StopWork();

            Assert.AreEqual(0, operationsCount);
        }
コード例 #2
0
        public void GuardBee_WorkExpectedTime()
        {
            GuardBee bee = new GuardBee();

            GuardPostQueue queue = new GuardPostQueue();

            for (int i = 0; i < 1000; i++)
            {
                queue.Enqueue(new EmptyBaseBee());
            }

            int operationsCount = 0;

            bee.ActionPerformed += (sender, args) =>
            {
                if (args.ActionType == BeeActionType.AcceptBeeToEnter)
                {
                    Interlocked.Increment(ref operationsCount);
                }
            };

            bee.RequestForBeehiveData += (sender, args) =>
            {
                if (args.RequestType == BeeRequestType.RequestGuardPostQueue)
                {
                    args.Response = queue;
                }

                args.Succeed = true;
            };

            bee.StartWork();

            Task.Delay((int)this.balance.GuardBalance.TimeToCheckOneBee.TotalMilliseconds * 50)
            .GetAwaiter().GetResult();

            bee.StopWork();

            Assert.IsTrue(Math.Abs(50 - operationsCount) <= (50 * GuardBeeTests.Inaccuracy));
        }