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); } }
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); } }
public void SetTestModeDataContext_OldContextIsNull_CreatesElementDataContext_ChainsToPopulateData_CorrectParameters() { using (ShimsContext.Create()) { ElementDataContext dataContext = null; ElementContext elementContext = new ShimElementContext { DataContextGet = () => dataContext, DataContextSetElementDataContext = (dcNew) => { dataContext = dcNew; }, }; ShimDataManager.GetDefaultInstance = () => new ShimDataManager { GetElementContextGuid = (_) => elementContext, }; ElementDataContext actualContext = null; DataContextMode? actualMode = null; TreeViewMode? actualTreeViewMode = null; ShimCaptureAction.PopulateDataElementDataContextDataContextModeTreeViewMode = (dc, dcMode, tm) => { actualContext = dc; actualMode = dcMode; actualTreeViewMode = tm; }; Assert.IsTrue(CaptureAction.SetTestModeDataContext(Guid.Empty, DataContextMode.Test, TreeViewMode.Content)); Assert.IsNotNull(dataContext); Assert.AreEqual(0, dataContext.ElementCounter.Count); Assert.AreEqual(20000, dataContext.ElementCounter.UpperBound); Assert.AreSame(dataContext, actualContext); Assert.AreEqual(DataContextMode.Test, actualMode); Assert.AreEqual(TreeViewMode.Content, actualTreeViewMode); } }
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); } }