示例#1
0
        private static void SetElementDataContext(bool upperBoundExceeded)
        {
            BoundedCounter counter = new BoundedCounter(1);

            counter.TryIncrement();

            if (upperBoundExceeded)  // if true, we're 1 over capacity. if false, we're exactly at capacity
            {
                counter.TryIncrement();
            }

            ShimElementDataContext dc = new ShimElementDataContext
            {
                ElementCounterGet = () => counter
            };

            ShimGetDataAction.GetElementDataContextGuid = (_) => dc;
        }
示例#2
0
        public void CaptureScreenShot_ElementWithBoundingRectangle_ScreenShotCreated()
        {
            using (ShimsContext.Create())
            {
                bool bitmapsetcalled = false;

                //  bounding rectangle exists.
                A11yElement element = new ShimA11yElement
                {
                    ParentGet            = () => null,
                    BoundingRectangleGet = () => new Rectangle(0, 0, 10, 10),
                    UniqueIdGet          = () => 1,
                };

                ElementDataContext dc = new ShimElementDataContext()
                {
                    ScreenshotSetBitmap = (_) => bitmapsetcalled = true,
                };

                ElementContext elementContext = new ShimElementContext
                {
                    ElementGet     = () => element,
                    DataContextGet = () => dc,
                };

                ShimDataManager.GetDefaultInstance = () => new ShimDataManager
                {
                    GetElementContextGuid = (_) => elementContext,
                };

                Graphics g = new ShimGraphics();

                ShimGraphics.FromImageImage = (_) => g;

                ScreenShotAction.CaptureScreenShot(Guid.NewGuid());

                // bitmap is set
                Assert.IsTrue(bitmapsetcalled);
            }
        }
示例#3
0
        public void CaptureScreenShotOnWCOS_ElementWithBoundingRectangle_NoScreenShot()
        {
            using (ShimsContext.Create())
            {
                bool bitmapsetcalled = false;

                //  bounding rectangle exists.
                A11yElement element = new ShimA11yElement
                {
                    ParentGet            = () => null,
                    BoundingRectangleGet = () => new Rectangle(0, 0, 10, 10),
                    UniqueIdGet          = () => 1,
                };

                ElementDataContext dc = new ShimElementDataContext()
                {
                    ScreenshotSetBitmap = (_) => bitmapsetcalled = true,
                };

                ElementContext elementContext = new ShimElementContext
                {
                    ElementGet     = () => element,
                    DataContextGet = () => dc,
                };

                ShimDataManager.GetDefaultInstance = () => new ShimDataManager
                {
                    GetElementContextGuid = (_) => elementContext,
                };

                ShimBitmap.ConstructorInt32Int32 = (_, w, h) => throw new TypeInitializationException("Bitmap", null);

                ScreenShotAction.CaptureScreenShot(Guid.NewGuid());

                // screenshot is not set(null)
                Assert.IsNull(dc.Screenshot);
                // ScreenShotSet was not called.
                Assert.IsFalse(bitmapsetcalled);
            }
        }
示例#4
0
        public void CaptureScreenShot_ElementWithoutBoundingRectangle_NoScreenShot()
        {
            using (ShimsContext.Create())
            {
                bool bitmapsetcalled = false;

                // no bounding rectangle.
                A11yElement element = new ShimA11yElement
                {
                    ParentGet            = () => null,
                    BoundingRectangleGet = () => Rectangle.Empty,
                };

                ElementDataContext dc = new ShimElementDataContext()
                {
                    ScreenshotSetBitmap = (_) => bitmapsetcalled = true,
                };

                ElementContext elementContext = new ShimElementContext
                {
                    ElementGet     = () => element,
                    DataContextGet = () => dc,
                };

                ShimDataManager.GetDefaultInstance = () => new ShimDataManager
                {
                    GetElementContextGuid = (_) => elementContext,
                };

                ScreenShotAction.CaptureScreenShot(Guid.NewGuid());

                // screenshot is not set(null)
                Assert.IsNull(dc.Screenshot);
                // ScreenShotSet was not called.
                Assert.IsFalse(bitmapsetcalled);
            }
        }