Exemple #1
0
        public void GetHashCode_DifferentInRuleOnly_ReturnsDifferentHashCode()
        {
            IFingerprint fingerprint1 = new ScanResultFingerprint(new A11yElement(), RuleId.BoundingRectangleExists, DefaultScanStatus);
            IFingerprint fingerprint2 = new ScanResultFingerprint(new A11yElement(), RuleId.BoundingRectangleNotNull, DefaultScanStatus);

            Assert.AreNotEqual(fingerprint1.GetHashCode(), fingerprint2.GetHashCode());
        }
        public void DictionaryTest_FingerprintsAreDifferent_TreatsItemsCorrectly()
        {
            using (ShimsContext.Create())
            {
                Dictionary <IFingerprint, int> store = new Dictionary <IFingerprint, int>();

                A11yElement element1 = new ShimA11yElement {
                    NameGet = () => _specialNameValue1
                };
                A11yElement element2 = new ShimA11yElement {
                    NameGet = () => _specialNameValue2
                };
                IFingerprint fingerprint1 = new ScanResultFingerprint(element1, DefaultRule, DefaultScanStatus);
                IFingerprint fingerprint2 = new ScanResultFingerprint(element2, DefaultRule, DefaultScanStatus);

                store.Add(fingerprint1, 1);
                Assert.AreEqual(1, store.Count);
                Assert.IsTrue(store.TryGetValue(fingerprint1, out int value));
                Assert.AreEqual(1, value);
                Assert.IsFalse(store.TryGetValue(fingerprint2, out value));
                store.Add(fingerprint2, 2);
                Assert.AreEqual(2, store.Count);
                Assert.IsTrue(store.TryGetValue(fingerprint2, out value));
                Assert.AreEqual(2, value);
            }
        }
Exemple #3
0
        public void GetHashCode_DifferentInLevelOnly_ReturnsDifferentHashCode()
        {
            IFingerprint fingerprint1 = new ScanResultFingerprint(new A11yElement(), DefaultRule, ScanStatus.Fail);
            IFingerprint fingerprint2 = new ScanResultFingerprint(new A11yElement(), DefaultRule, ScanStatus.Uncertain);

            Assert.AreNotEqual(fingerprint1.GetHashCode(), fingerprint2.GetHashCode());
        }
        public void Equals_OtherHasSameContributionCountAndHashButDifferentContent_ReturnsFalse()
        {
            using (ShimsContext.Create())
            {
                FingerprintContribution fc1 = new FingerprintContribution("Name", _specialNameValue1);
                FingerprintContribution fc2 = new FingerprintContribution("Name", _specialNameValue2);

                Assert.AreEqual(fc1.GetHashCode(), fc2.GetHashCode());

                A11yElement element1 = new ShimA11yElement {
                    NameGet = () => _specialNameValue1
                };
                A11yElement element2 = new ShimA11yElement {
                    NameGet = () => _specialNameValue2
                };
                IFingerprint fingerprint1 = new ScanResultFingerprint(element1, DefaultRule, DefaultScanStatus);
                IFingerprint fingerprint2 = new ScanResultFingerprint(element2, DefaultRule, DefaultScanStatus);

                Assert.AreEqual(fingerprint1.GetHashCode(), fingerprint2.GetHashCode());

                // Ensure that these differ only in specific content
                Assert.AreEqual(0, fingerprint1.CompareTo(fingerprint2));
                Assert.AreEqual(0, fingerprint2.CompareTo(fingerprint1));

                Assert.IsFalse(fingerprint1.Equals(fingerprint2));
                Assert.IsFalse(fingerprint2.Equals(fingerprint1));
            }
        }
Exemple #5
0
        public void CompareTo_ElementsWithSameNumberOfContributions_SortByHashValue()
        {
            var       list = new SortedList <IFingerprint, string>();
            const int max  = 10;

            string elementName = string.Empty;

            for (int loop = 0; loop < max; loop++)
            {
                elementName += "a";
                IA11yElement element     = BuildTestElement(name: elementName);
                IFingerprint fingerprint = new ScanResultFingerprint(element, DefaultRule, DefaultScanStatus);
                list.Add(fingerprint, elementName);
            }

            // If the comparison worked correctly, then the hash codes of the list will be
            // sorted in ascending order
            int oldHashCode = int.MinValue;

            for (int loop = 0; loop < max; loop++)
            {
                int    hashCode    = list.Keys[loop].GetHashCode();
                string description = string.Format("Index {0}: Hash {1} should be less than Hash {2}",
                                                   loop, oldHashCode, hashCode);
                Assert.IsTrue(oldHashCode < hashCode);
                oldHashCode = hashCode;
            }
        }
Exemple #6
0
        public void Equals_OtherIsDifferentImplementation_ReturnsFalse()
        {
            IFingerprint fingerprint = new ScanResultFingerprint(new A11yElement(), DefaultRule, DefaultScanStatus);
            IFingerprint other       = new Mock <IFingerprint>().Object;

            Assert.IsFalse(fingerprint.Equals(other));
        }
Exemple #7
0
        public void GetHashCode_EquivalentMinimalContributions_ReturnsSameHashCode()
        {
            IFingerprint fingerprint1 = new ScanResultFingerprint(new A11yElement(), DefaultRule, DefaultScanStatus);
            IFingerprint fingerprint2 = new ScanResultFingerprint(new A11yElement(), DefaultRule, DefaultScanStatus);

            Assert.AreEqual(fingerprint1.GetHashCode(), fingerprint2.GetHashCode());
        }
        public void Ctor_ElementHasOneLevelOfAncestry_FingerprintRemovesTopParentName()
        {
            using (ShimsContext.Create())
            {
                const string elementName = "NameOfElement";
                const string parentName  = "NameOfParent";
                const string desktopName = "NameOfDesktop";

                ShimA11yElement element = new ShimA11yElement
                {
                    ControlTypeIdGet = () => 50033,
                    NameGet          = () => elementName,
                    ParentGet        = () => new ShimA11yElement
                    {
                        ControlTypeIdGet = () => 50031,
                        NameGet          = () => parentName,
                        ParentGet        = () => new ShimA11yElement
                        {
                            NameGet = () => desktopName,
                        }
                    }
                };

                IFingerprint fingerprint = new ScanResultFingerprint(element, DefaultRule, DefaultScanStatus);
                ValidateFingerprint(fingerprint, nameValue: elementName, controlTypeValue: "Pane(50033)|SplitButton(50031)");
            }
        }
Exemple #9
0
 public void Ctor_ScanStatusIsUncertain_FingerprintIncludesCorrectLevel()
 {
     using (A11yElement element = new A11yElement())
     {
         IFingerprint fingerprint = new ScanResultFingerprint(element, DefaultRule, ScanStatus.Uncertain);
         ValidateFingerprint(fingerprint, levelValue: "open");
     }
 }
Exemple #10
0
 public void Ctor_ScanStatusIsScanNotSupported_FingerprintIncludesCorrectLevel()
 {
     using (A11yElement element = new A11yElement())
     {
         IFingerprint fingerprint = new ScanResultFingerprint(element, DefaultRule, ScanStatus.ScanNotSupported);
         ValidateFingerprint(fingerprint, levelValue: "note");
     }
 }
Exemple #11
0
 public void Ctor_ScanStatusIsFail_FingerprintIncludesCorrectLevel()
 {
     using (A11yElement element = new A11yElement())
     {
         IFingerprint fingerprint = new ScanResultFingerprint(element, DefaultRule, ScanStatus.Fail);
         ValidateFingerprint(fingerprint, levelValue: "error");
     }
 }
Exemple #12
0
 public void Ctor_ElementIsTrivial_FingerprintIncludesRuleId()
 {
     using (A11yElement element = new A11yElement())
     {
         IFingerprint fingerprint = new ScanResultFingerprint(element, DefaultRule, DefaultScanStatus);
         ValidateFingerprint(fingerprint);
     }
 }
Exemple #13
0
        public void Ctor_RuleIsContentElementPropertyCorrect_FingerprintIncludesIsContentElement()
        {
            IA11yElement element = BuildTestElement(isContentElement: false);

            IFingerprint fingerprint = new ScanResultFingerprint(element, RuleId.IsContentElementPropertyCorrect, DefaultScanStatus);

            ValidateFingerprint(fingerprint, ruleIdValue: "IsContentElementPropertyCorrect", isContentElementValue: "False");
        }
Exemple #14
0
        public void Ctor_RuleIsKeyboardFocusableBasedOnPatterns_FingerprintIncludesIsKeyboardFocusable()
        {
            IA11yElement element = BuildTestElement();

            IFingerprint fingerprint = new ScanResultFingerprint(element, RuleId.IsKeyboardFocusableBasedOnPatterns, DefaultScanStatus);

            ValidateFingerprint(fingerprint, ruleIdValue: "IsKeyboardFocusableBasedOnPatterns", isKeyboardFocusableValue: "False");
        }
Exemple #15
0
        public void Ctor_RuleIsKeyboardFocusable_FingerprintIncludesIsKeyboardFocusable()
        {
            IA11yElement element = BuildTestElement(isKeyboardFocusable: true);

            IFingerprint fingerprint = new ScanResultFingerprint(element, RuleId.IsKeyboardFocusable, DefaultScanStatus);

            ValidateFingerprint(fingerprint, ruleIdValue: "IsKeyboardFocusable", isKeyboardFocusableValue: "True");
        }
Exemple #16
0
        public void CompareTo_OtherIsDifferentImplemention_ThrowsInvalidOperationException()
        {
            IFingerprint fingerprint = new ScanResultFingerprint(BuildTestElement(), DefaultRule, DefaultScanStatus);

            IFingerprint other = new Mock <IFingerprint>().Object;

            fingerprint.CompareTo(other);
        }
 public void Equals_OtherIsDifferentImplementation_ReturnsFalse()
 {
     using (ShimsContext.Create())
     {
         IFingerprint     fingerprint = new ScanResultFingerprint(new A11yElement(), DefaultRule, DefaultScanStatus);
         StubIFingerprint other       = new StubIFingerprint();
         Assert.IsFalse(fingerprint.Equals(other));
     }
 }
Exemple #18
0
        public void Ctor_ElementHasAutomationId_FingerprintIncludesAutomationId()
        {
            const string automationId = "MyAutomationId";

            IA11yElement element = BuildTestElement(automationId: automationId);

            IFingerprint fingerprint = new ScanResultFingerprint(element, DefaultRule, DefaultScanStatus);

            ValidateFingerprint(fingerprint, automationIdValue: automationId);
        }
Exemple #19
0
        public void Ctor_ElementHasLocalizedControlType_FingerprintIncludesLocalizedControlType()
        {
            const string localizedControlType = "MyLocalizedControlType";

            IA11yElement element = BuildTestElement(localizedControlType: localizedControlType);

            IFingerprint fingerprint = new ScanResultFingerprint(element, DefaultRule, DefaultScanStatus);

            ValidateFingerprint(fingerprint, localizedControlTypeValue: localizedControlType);
        }
Exemple #20
0
        public void Ctor_ElementHasUIFramework_FingerprintIncludesFrameworkId()
        {
            const string frameworkId = "MyFrameworkId";

            IA11yElement element = BuildTestElement(framework: frameworkId);

            IFingerprint fingerprint = new ScanResultFingerprint(element, DefaultRule, DefaultScanStatus);

            ValidateFingerprint(fingerprint, frameworkIdValue: frameworkId);
        }
Exemple #21
0
        public void GetHashCode_MinimalContributions_ReturnsSameHashCodeMultipleTimes()
        {
            IFingerprint fingerprint = new ScanResultFingerprint(new A11yElement(), DefaultRule, DefaultScanStatus);

            int hash1 = fingerprint.GetHashCode();

            Assert.AreEqual(hash1, fingerprint.GetHashCode());
            Assert.AreEqual(hash1, fingerprint.GetHashCode());
            Assert.AreEqual(hash1, fingerprint.GetHashCode());
        }
Exemple #22
0
        public void Ctor_ElementHasClassName_FingerprintIncludesClassName()
        {
            const string className = "MyClass";

            IA11yElement element = BuildTestElement(className: className);

            IFingerprint fingerprint = new ScanResultFingerprint(element, DefaultRule, DefaultScanStatus);

            ValidateFingerprint(fingerprint, classNameValue: className);
        }
Exemple #23
0
        public void Ctor_ElementHasAccessKey_FingerprintIncludesAccessKey()
        {
            const string accessKey = "MyAccessKey";

            IA11yElement element = BuildTestElement(accessKey: accessKey);

            IFingerprint fingerprint = new ScanResultFingerprint(element, DefaultRule, DefaultScanStatus);

            ValidateFingerprint(fingerprint, accessKeyValue: accessKey);
        }
        public void CompareTo_OtherIsDifferentImplemention_ThrowsInvalidOperationException()
        {
            using (ShimsContext.Create())
            {
                IFingerprint fingerprint = new ScanResultFingerprint(new A11yElement(), DefaultRule, DefaultScanStatus);

                StubIFingerprint other = new StubIFingerprint();

                fingerprint.CompareTo(other);
            }
        }
Exemple #25
0
        public void CompareTo_OneElementHasMoreContributions_SortByContributionCount()
        {
            IA11yElement moreContributionsElement  = BuildTestElement(name: "ElementWith2Contributions", automationId: "blah");
            IA11yElement fewerContributionsElement = BuildTestElement(name: "ElementWith1Contribution");

            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));
        }
Exemple #26
0
        public void Equals_OtherHasSameNumberOfContributionsButDifferentHash_ReturnsFalse()
        {
            IA11yElement element1 = BuildTestElement(name: "a");
            IA11yElement element2 = BuildTestElement(name: "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 Ctor_ElementBasedOnWordNavPane_FingerprintIncludesExpectedFields()
        {
            using (ShimsContext.Create())
            {
                ShimA11yElement element = new ShimA11yElement
                {
                    BoundingRectangleGet    = () => new Rectangle(132, 406, 402 - 132, 1928 - 406),
                    ControlTypeIdGet        = () => 50033,
                    IsKeyboardFocusableGet  = () => true,
                    LocalizedControlTypeGet = () => "pane",
                    NameGet   = () => "Navigation",
                    ParentGet = () => new ShimA11yElement
                    {
                        BoundingRectangleGet    = () => new Rectangle(124, 335, 410 - 124, 1935 - 335),
                        ControlTypeIdGet        = () => 50021,
                        IsKeyboardFocusableGet  = () => false,
                        LocalizedControlTypeGet = () => "tool bar",
                        ParentGet = () => new ShimA11yElement
                        {
                            BoundingRectangleGet    = () => new Rectangle(124, 335, 410 - 124, 1935 - 335),
                            ControlTypeIdGet        = () => 50033,
                            IsKeyboardFocusableGet  = () => true,
                            LocalizedControlTypeGet = () => "pane",
                            NameGet   = () => "MsoDockLeft",
                            ParentGet = () => new ShimA11yElement
                            {
                                BoundingRectangleGet    = () => new Rectangle(111, 13, 3010 - 111, 2013 - 13),
                                ControlTypeIdGet        = () => 50032,
                                IsKeyboardFocusableGet  = () => true,
                                LocalizedControlTypeGet = () => "window",
                                NameGet   = () => "Document 1 - Word",
                                ParentGet = () => new ShimA11yElement
                                {
                                    BoundingRectangleGet    = () => new Rectangle(0, 0, 3000, 2000),
                                    ControlTypeIdGet        = () => 50033,
                                    IsKeyboardFocusableGet  = () => true,
                                    LocalizedControlTypeGet = () => "pane",
                                    NameGet = () => "Desktop 1",
                                }
                            }
                        }
                    }
                };

                IFingerprint fingerprint = new ScanResultFingerprint(element, DefaultRule, DefaultScanStatus);
                ValidateFingerprint(fingerprint,
                                    nameValue: "Navigation||MsoDockLeft",
                                    controlTypeValue: "Pane(50033)|ToolBar(50021)|Pane(50033)|Window(50032)",
                                    localizedControlTypeValue: "pane|tool bar|pane|window"
                                    );
            }
        }
Exemple #28
0
        public void Equals_OtherIsEquivalent_ReturnsTrue()
        {
            const string automationId  = "AutomationId";
            const int    controlTypeId = 50021;
            IA11yElement element1      = BuildTestElement(automationId: automationId, controlTypeId: controlTypeId);
            IA11yElement element2      = BuildTestElement(automationId: automationId, controlTypeId: controlTypeId);

            IFingerprint fingerprint1 = new ScanResultFingerprint(element1, DefaultRule, DefaultScanStatus);
            IFingerprint fingerprint2 = new ScanResultFingerprint(element2, DefaultRule, DefaultScanStatus);

            Assert.IsTrue(fingerprint1.Equals(fingerprint2));
            Assert.IsTrue(fingerprint2.Equals(fingerprint1));
        }
Exemple #29
0
        public void Equals_OtherHasDifferentNumberOfContributions_ReturnsFalse()
        {
            const string name = "MyTest";
            IA11yElement moreContributionsElement  = BuildTestElement(name: name, automationId: "myId");
            IA11yElement fewerContributionsElement = BuildTestElement(name: name);

            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));
        }
Exemple #30
0
        public void GetHashCode_DifferentComplexContributions_ReturnsDifferentHashCode()
        {
            const string name    = "ElementName";
            const string culture = "ElementCulture";

            IA11yElement element1 = BuildTestElement(name: name, culture: culture, automationId: "id1");
            IA11yElement element2 = BuildTestElement(name: name, culture: culture, automationId: "id2");

            IFingerprint fingerprint1 = new ScanResultFingerprint(element1, DefaultRule, DefaultScanStatus);
            IFingerprint fingerprint2 = new ScanResultFingerprint(element2, DefaultRule, DefaultScanStatus);

            Assert.AreNotEqual(fingerprint1.GetHashCode(), fingerprint2.GetHashCode());
        }