public void Equals_OtherHasSameNumberOfContributionsButDifferentHash_ReturnsFalse() { using (ShimsContext.Create()) { A11yElement element1 = new ShimA11yElement { NameGet = () => "a" }; A11yElement element2 = new ShimA11yElement { NameGet = () => "A" }; IFingerprint fingerprint1 = new ScanResultFingerprint(element1, DefaultRule, DefaultScanStatus); IFingerprint fingerprint2 = new ScanResultFingerprint(element2, DefaultRule, DefaultScanStatus); Assert.AreEqual(fingerprint1.Contributions.Count(), fingerprint2.Contributions.Count()); Assert.IsFalse(fingerprint1.Equals(fingerprint2)); Assert.IsFalse(fingerprint2.Equals(fingerprint1)); } }
public void Equals_OtherIsDifferentClass_ReturnsFalse() { const string fileName = @"c:\xyz\abc"; using (ShimsContext.Create()) { ShimFile.ExistsString = (f) => { return(f == fileName ? true : ShimsContext.ExecuteWithoutShims(() => File.Exists(f))); }; A11yElement element = new ShimA11yElement { UniqueIdGet = () => 24680, }; ILocation location = new OutputFileLocation(fileName, element); Assert.IsFalse(location.Equals(new StubILocation())); } }
public void CompareTo_OneElementHasMoreContributions_SortByContributionCount() { using (ShimsContext.Create()) { ShimA11yElement moreContributionsElement = new ShimA11yElement { NameGet = () => "ElementWithTwoContributions", AutomationIdGet = () => "AutomationId", }; ShimA11yElement fewerContributionsElement = new ShimA11yElement { NameGet = () => "ElemetWithOneContribution", }; IFingerprint higherFingerprint = new ScanResultFingerprint(moreContributionsElement, DefaultRule, DefaultScanStatus); IFingerprint lowerFingerprint = new ScanResultFingerprint(fewerContributionsElement, DefaultRule, DefaultScanStatus); Assert.AreEqual(-1, lowerFingerprint.CompareTo(higherFingerprint)); Assert.AreEqual(1, higherFingerprint.CompareTo(lowerFingerprint)); } }
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 Open_ProcessStartThrowsNonEnumeratedException_RethrowsException() { const string fileName = @"c:\xyz\abc"; const int id = 24680; using (ShimsContext.Create()) { ShimFile.ExistsString = (f) => { return((f == fileName) ? true : ShimsContext.ExecuteWithoutShims(() => File.Exists(f))); }; A11yElement element = new ShimA11yElement { UniqueIdGet = () => id, }; ILocation location = new OutputFileLocation(fileName, element, (startInfo) => { throw new OutOfMemoryException(); }); location.Open(); } }
public void UserDisplayInfo_SimpleCase_OutputIsContainsLocationProperties() { const string fileName = "c:\\abc\\xyz"; using (ShimsContext.Create()) { ShimFile.ExistsString = (f) => { return(f == fileName ? true : ShimsContext.ExecuteWithoutShims(() => File.Exists(f))); }; A11yElement element = new ShimA11yElement { UniqueIdGet = () => 13579, }; ILocation location = new OutputFileLocation(fileName, element); string displayInfo = location.UserDisplayInfo; Assert.IsTrue(displayInfo.Contains(location.Source)); Assert.IsTrue(displayInfo.Contains(location.Id)); } }
public void Ctor_SimpleCase_PropertiesAreSetCorrectly() { const string fileName = @"c:\xyz\abc"; using (ShimsContext.Create()) { ShimFile.ExistsString = (f) => { return(f == fileName ? true : ShimsContext.ExecuteWithoutShims(() => File.Exists(f))); }; A11yElement element = new ShimA11yElement { UniqueIdGet = () => 24680, }; ILocation location = new OutputFileLocation(fileName, element); Assert.AreEqual(fileName, location.Source); Assert.AreEqual("24680", location.Id); } }
public void Equals_OtherIsEquivalent_ReturnsTrue() { using (ShimsContext.Create()) { ShimA11yElement element1 = new ShimA11yElement { AutomationIdGet = () => "AutomationId", ControlTypeIdGet = () => 50021, }; ShimA11yElement element2 = new ShimA11yElement { AutomationIdGet = () => "AutomationId", ControlTypeIdGet = () => 50021, }; IFingerprint fingerprint1 = new ScanResultFingerprint(element1, DefaultRule, DefaultScanStatus); IFingerprint fingerprint2 = new ScanResultFingerprint(element2, DefaultRule, DefaultScanStatus); Assert.IsTrue(fingerprint1.Equals(fingerprint2)); Assert.IsTrue(fingerprint2.Equals(fingerprint1)); } }
public void Equals_OtherHasDifferentNumberOfContributions_ReturnsFalse() { using (ShimsContext.Create()) { ShimA11yElement moreContributionsElement = new ShimA11yElement { NameGet = () => "MyTest", AutomationIdGet = () => "AutomationId", }; ShimA11yElement fewerContributionsElement = new ShimA11yElement { NameGet = () => "MyTest", }; IFingerprint fingerprint1 = new ScanResultFingerprint(moreContributionsElement, DefaultRule, DefaultScanStatus); IFingerprint fingerprint2 = new ScanResultFingerprint(fewerContributionsElement, DefaultRule, DefaultScanStatus); Assert.AreNotEqual(fingerprint1.Contributions.Count(), fingerprint2.Contributions.Count()); Assert.IsFalse(fingerprint1.Equals(fingerprint2)); Assert.IsFalse(fingerprint2.Equals(fingerprint1)); } }
public void Ctor_ElementHasClassName_FingerprintIncludesClassName() { using (ShimsContext.Create()) { const string className = "MyClass"; ShimA11yElement element = new ShimA11yElement { PropertiesGet = () => new Dictionary <int, A11yProperty> { { PropertyType.UIA_ClassNamePropertyId, new ShimA11yProperty { TextValueGet = () => className, } }, } }; IFingerprint fingerprint = new ScanResultFingerprint(element, DefaultRule, DefaultScanStatus); ValidateFingerprint(fingerprint, classNameValue: className); } }
public void GetHashCode_DifferentComplexContributions_ReturnsSameHashCode() { using (ShimsContext.Create()) { A11yElement element1 = new ShimA11yElement { NameGet = () => "ElementName", CultureGet = () => "ElementCulture", AutomationIdGet = () => "ElementAutomationId", }; A11yElement element2 = new ShimA11yElement { NameGet = () => " ElementName", CultureGet = () => "ElementCulture", AutomationIdGet = () => "ElementAutomationId", }; IFingerprint fingerprint1 = new ScanResultFingerprint(element1, DefaultRule, DefaultScanStatus); IFingerprint fingerprint2 = new ScanResultFingerprint(element2, DefaultRule, DefaultScanStatus); Assert.AreNotEqual(fingerprint1.GetHashCode(), fingerprint2.GetHashCode()); } }
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); } }
public void Open_ProcessStartThrowsEnumeratedException_ReturnsFalse() { const string fileName = @"c:\xyz\abc"; const int id = 24680; using (ShimsContext.Create()) { ShimFile.ExistsString = (f) => { return((f == fileName) ? true : ShimsContext.ExecuteWithoutShims(() => File.Exists(f))); }; A11yElement element = new ShimA11yElement { UniqueIdGet = () => id, }; List <Exception> enumeratedExceptions = new List <Exception> { new InvalidOperationException(), new ArgumentException(), new ObjectDisposedException("blah", new Exception()), new FileNotFoundException(), new Win32Exception(), }; int exceptionsTested = 0; foreach (Exception e in enumeratedExceptions) { ILocation location = new OutputFileLocation(fileName, element, (startInfo) => { throw e; }); Assert.IsFalse(location.Open(), "Simulated Exception: " + e.ToString()); exceptionsTested++; } Assert.AreEqual(enumeratedExceptions.Count, exceptionsTested); } }
/// <summary> /// Creates and returns list of IA11yElements where /// returnedList[i].BoundingRectangle == boundingRects[i] and /// returnedList[i].UniqueId == i /// returnedList[i].IsOffScreen() == offSCreen[i] /// </summary> /// <returns></returns> private static List <A11yElement> CreateA11yElementsFromBoundingRectangles(List <System.Drawing.Rectangle> boundingRects, List <bool> offScreen) { var elementIndex = 0; ShimA11yElement.Constructor = (@this) => { var shim = new ShimA11yElement(@this); shim.BoundingRectangleGet = () => { return(boundingRects[@this.UniqueId]); }; shim.RuntimeIdGet = () => { return(@this.UniqueId.ToString()); }; elementIndex++; }; ShimExtensionMethods.IsOffScreenA11yElement = (el) => { return(offScreen[el.UniqueId]); }; var elements = new List <A11yElement>(); for (int i = 0; i < boundingRects.Count; i++) { A11yElement element = new A11yElement(); element.UniqueId = i; elements.Add(element); } return(elements); }
public void ExtractIssues_ElementsContainUncertainsWithSameFingerprint_AddsOneUncertainWithTwoLocations() { const ScanStatus scanStatus = ScanStatus.Uncertain; Dictionary <IFingerprint, Issue> store = new Dictionary <IFingerprint, Issue>(); using (ShimsContext.Create()) { List <ILocation> actualLocations = new List <ILocation>(); List <IFingerprint> actualFingerprints = new List <IFingerprint>(); List <string> actualFileNames = new List <string>(); List <ScanStatus> actualStatuses = new List <ScanStatus>(); List <string> actualIssueTypes = new List <string>(); List <RuleId> actualRuleIds = new List <RuleId>(); List <A11yElement> actualElements = new List <A11yElement>(); IFingerprint expectedFingerprint = new StubIFingerprint { EqualsIFingerprint = (f) => true, }; Issue expectedIssue = new ShimIssue { AddLocationILocation = (l) => { actualLocations.Add(l); return(AddResult.ItemAdded); } }; ILocation expectedLocation1 = new StubILocation(); ILocation expectedLocation2 = new StubILocation(); string expectedIssueType = "ChildUniqueNameOrType_Uncertain"; RuleId expectedRuleId = RuleId.ChildUniqueNameOrType; ShimOutputFileIssueStore.BuildFingerprintA11yElementRuleIdScanStatus = (e, r, s) => { actualElements.Add(e); actualRuleIds.Add(r); actualStatuses.Add(s); return(expectedFingerprint); }; List <ILocation> expectedLocations = new List <ILocation> { expectedLocation1, expectedLocation2 }; ShimOutputFileIssueStore.BuildLocationA11yElementString = (e, f) => { actualElements.Add(e); actualFileNames.Add(f); ILocation location = expectedLocations[0]; expectedLocations.RemoveAt(0); return(location); }; ShimOutputFileIssueStore.BuildIssueStringIFingerprint = (i, f) => { actualIssueTypes.Add(i); actualFingerprints.Add(f); return(expectedIssue); }; ScanResults scanResults = new ShimScanResults { StatusGet = () => scanStatus, ItemsGet = () => new List <ScanResult> { new ShimScanResult { ItemsGet = () => new List <RuleResult> { new ShimRuleResult { StatusGet = () => scanStatus, RuleGet = () => expectedRuleId, } } } }, }; A11yElement expectedElement1 = new ShimA11yElement { ScanResultsGet = () => scanResults }; A11yElement expectedElement2 = new ShimA11yElement { ScanResultsGet = () => scanResults }; IEnumerable <A11yElement> elements = new List <A11yElement> { expectedElement1, expectedElement2, }; Assert.IsFalse(store.Any()); OutputFileIssueStore.ExtractIssues(TestFile, elements, store); Assert.AreEqual(0, expectedLocations.Count); Assert.AreEqual(1, store.Count); Assert.AreEqual(4, actualElements.Count); Assert.AreSame(expectedElement1, actualElements[0]); Assert.AreSame(expectedElement1, actualElements[1]); Assert.AreSame(expectedElement2, actualElements[2]); Assert.AreSame(expectedElement2, actualElements[3]); Assert.AreEqual(2, actualFileNames.Count); Assert.AreEqual(TestFile, actualFileNames[0]); Assert.AreEqual(TestFile, actualFileNames[1]); Assert.AreEqual(1, actualFingerprints.Count); Assert.AreSame(expectedFingerprint, actualFingerprints[0]); Assert.AreEqual(2, actualStatuses.Count); Assert.AreEqual(scanStatus, actualStatuses[0]); Assert.AreEqual(scanStatus, actualStatuses[1]); Assert.AreEqual(1, actualIssueTypes.Count); Assert.AreEqual(expectedIssueType, actualIssueTypes[0]); Assert.AreEqual(2, actualLocations.Count); Assert.AreSame(expectedLocation1, actualLocations[0]); Assert.AreSame(expectedLocation2, actualLocations[1]); Assert.AreEqual(2, actualRuleIds.Count); Assert.AreEqual(expectedRuleId, actualRuleIds[0]); Assert.AreEqual(expectedRuleId, actualRuleIds[1]); } }