Example #1
0
        public void ExtractIssues_ElementsContainOneNotSupported_LeavesStoreUnchanged()
        {
            Dictionary <IFingerprint, Issue> store = new Dictionary <IFingerprint, Issue>();

            using (ShimsContext.Create())
            {
                int         resultsGotten = 0;
                ScanResults scanResults   = new ShimScanResults
                {
                    StatusGet = () => { resultsGotten++; return(ScanStatus.ScanNotSupported); }
                };
                IEnumerable <A11yElement> elements = new List <A11yElement>
                {
                    new ShimA11yElement {
                        ScanResultsGet = () => scanResults
                    },
                    new ShimA11yElement {
                        ScanResultsGet = () => scanResults
                    },
                };

                Assert.IsFalse(store.Any());
                OutputFileIssueStore.ExtractIssues(TestFile, elements, store);
                Assert.IsFalse(store.Any());
                Assert.AreEqual(2, resultsGotten);
            }
        }
Example #2
0
        public void ExtractIssues_ElementSetIsEmpty_LeavesStoreUnchanged()
        {
            Dictionary <IFingerprint, Issue> store = new Dictionary <IFingerprint, Issue>();

            Assert.IsFalse(store.Any());
            OutputFileIssueStore.ExtractIssues(TestFile, Enumerable.Empty <A11yElement>(), store);
            Assert.IsFalse(store.Any());
        }
Example #3
0
        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]);
            }
        }