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);
        }
        public void AddElementAndChildrenIntoList_GeneralCase_BuildsCorrectDictionary()
        {
            using (ShimsContext.Create())
            {
                const int elementCount = 7;

                BoundedCounter counter = new BoundedCounter(100);
                Dictionary <int, A11yElement> elementsOut = new Dictionary <int, A11yElement>();

                // Build our tree
                List <ShimA11yElement> elements = new List <ShimA11yElement>();
                for (int loop = 0; loop < elementCount; loop++)
                {
                    int uniqueId = loop;
                    elements.Add(new ShimA11yElement
                    {
                        UniqueIdGet = () => uniqueId,  // Don't use loop here, since it will get the final value, not the in-loop value
                    });
                }
                elements[0].ChildrenGet = () => new List <A11yElement> {
                    elements[1], elements[2]
                };
                elements[2].ChildrenGet = () => new List <A11yElement> {
                    elements[3]
                };
                elements[3].ChildrenGet = () => new List <A11yElement> {
                    elements[4], elements[5], elements[6]
                };
                elements[6].ChildrenGet = () => new List <A11yElement>();

                CaptureAction.AddElementAndChildrenIntoList(elements[0], elementsOut, counter);

                Assert.AreEqual(elementCount, elementsOut.Count);
                for (int loop = 0; loop < elementCount; loop++)
                {
                    Assert.AreEqual(loop, elementsOut[loop].UniqueId);
                }
            }
        }
        public void AddElementAndChildrenIntoList_GeneralCase_BuildsCorrectDictionary()
        {
            const int elementCount = 7;

            BoundedCounter counter = new BoundedCounter(100);
            Dictionary <int, A11yElement> elementsOut = new Dictionary <int, A11yElement>();

            // Build our tree
            List <A11yElement> elements = new List <A11yElement>();

            for (int loop = 0; loop < elementCount; loop++)
            {
                A11yElement element = new A11yElement
                {
                    UniqueId = loop
                };
                elements.Add(element);
            }

            elements[0].Children = new List <A11yElement> {
                elements[1], elements[2]
            };
            elements[2].Children = new List <A11yElement> {
                elements[3]
            };
            elements[3].Children = new List <A11yElement> {
                elements[4], elements[5], elements[6]
            };
            elements[6].Children = new List <A11yElement>();

            CaptureAction.AddElementAndChildrenIntoList(elements[0], elementsOut, counter);

            Assert.AreEqual(elementCount, elementsOut.Count);
            for (int loop = 0; loop < elementCount; loop++)
            {
                Assert.AreEqual(loop, elementsOut[loop].UniqueId);
            }
        }