예제 #1
0
        public void TryAdd_ValueToAddIsZero_UpperBoundIsExceeded_ReturnsTrue()
        {
            const int upperBound = 5;

            BoundedCounter counter = new BoundedCounter(upperBound);

            Assert.IsFalse(counter.TryAdd(upperBound + 1));  // Exceed upper bound
            Assert.IsFalse(counter.TryAdd(0));
        }
예제 #2
0
        public void TryAdd_Overflows_ReturnsFalse_Updates_State()
        {
            const int upperBound = int.MaxValue - 5;
            const int valueToAdd = 10;

            BoundedCounter counter = new BoundedCounter(upperBound);

            Assert.IsTrue(counter.TryAdd(upperBound - 2));

            for (int loop = 0; loop < 5; loop++)
            {
                Assert.IsFalse(counter.TryAdd(valueToAdd));
                Assert.AreEqual(int.MaxValue, counter.Attempts);
                Assert.AreEqual(upperBound, counter.Count);
            }
        }
예제 #3
0
        public void TryAdd_UpperBoundExceeded_ReturnsFalse_UpdatesState()
        {
            const int upperBound = 5;
            const int valueToAdd = 3;

            BoundedCounter counter = new BoundedCounter(upperBound);

            counter.TryAdd(valueToAdd);

            for (int loop = 0; loop < upperBound; loop++)
            {
                Assert.IsFalse(counter.TryAdd(valueToAdd));
                Assert.AreEqual(valueToAdd * (loop + 2), counter.Attempts);
                Assert.AreEqual(upperBound, counter.Count);
                Assert.AreEqual(upperBound, counter.UpperBound);
            }
        }
예제 #4
0
        public void TryAdd_ValueToAddIsNegative_ThrowsArgumentException()
        {
            const int upperBound = 5;

            BoundedCounter counter = new BoundedCounter(upperBound);

            counter.TryAdd(-1);
        }
예제 #5
0
        public void AddElementAndChildrenIntoList_CounterIsFull_ReturnsWithoutAdding()
        {
            BoundedCounter counter = new BoundedCounter(1);

            Assert.IsFalse(counter.TryAdd(2));
            Assert.AreEqual(2, counter.Attempts);

            // We intentionally pass in nulls here, since it's an error if they're accessed in any way
            CaptureAction.AddElementAndChildrenIntoList(null, null, counter);

            Assert.AreEqual(3, counter.Attempts);
        }
예제 #6
0
        public void TryAdd_UpperBoundNotExceeded_ReturnsTrue_UpdatesState()
        {
            const int upperBound = 5;
            const int valueToAdd = 3;

            BoundedCounter counter = new BoundedCounter(upperBound);

            Assert.IsTrue(counter.TryAdd(valueToAdd));
            Assert.AreEqual(valueToAdd, counter.Attempts);
            Assert.AreEqual(valueToAdd, counter.Count);
            Assert.AreEqual(upperBound, counter.UpperBound);
        }
예제 #7
0
        /// <summary>
        /// Refresh tree node data with all children at once.
        /// <param name="mode">indicate the mode</param>
        /// </summary>
        public void RefreshTreeData(TreeViewMode mode)
        {
            this.WalkerMode = mode;
            if (this.Elements.Count != 0)
            {
                this.Elements.Clear();
            }

            //Set parent of Root explicitly for testing.
            var ancestry = new DesktopElementAncestry(this.WalkerMode, this.SelectedElement);

            // Pre-count the ancestors in our bounded count, so that our count is accurate
            _elementCounter.TryAdd(ancestry.Items.Count);

            this.TopMostElement = ancestry.First;

            // clear children
            ListHelper.DisposeAllItemsAndClearList(this.SelectedElement.Children);
            this.SelectedElement.UniqueId = 0;

            PopulateChildrenTreeNode(this.SelectedElement, ancestry.Last, ancestry.NextId);

            // do population of ancesters all togather with children
            var list = new List <A11yElement>(this.Elements);

            foreach (var item in ancestry.Items)
            {
                this.Elements.Add(item);
            }

            // populate Elements first
            this.Elements.AsParallel().ForAll(e => e.PopulateAllPropertiesWithLiveData());

            // check whether there is any elements which couldn't be updated in parallel, if so, update it in sequence.
            var nuel = this.Elements.Where(e => e.Properties == null);

            if (nuel.Any())
            {
                nuel.ToList().ForEach(e => e.PopulateAllPropertiesWithLiveData());
            }

            // run tests
            list.AsParallel().ForAll(e =>
            {
                e.ScanResults?.Items.Clear();
                RuleRunner.Run(e);
            });
        }
예제 #8
0
        public void TryIncrement_UpperBoundExceeded_ReturnsFalse_UpdatesState()
        {
            const int      upperBound = 5;
            BoundedCounter counter    = new BoundedCounter(upperBound);

            Assert.IsTrue(counter.TryAdd(upperBound));
            Assert.IsFalse(counter.UpperBoundExceeded);

            // UpperBound has been reached, so all further adds should fail
            for (int loop = 0; loop < upperBound; loop++)
            {
                Assert.AreEqual(upperBound, counter.UpperBound);
                Assert.AreEqual(upperBound, counter.Count);
                Assert.AreEqual(upperBound + loop, counter.Attempts);
                Assert.IsFalse(counter.TryIncrement());
                Assert.IsTrue(counter.UpperBoundExceeded);
            }
        }