コード例 #1
0
        public void AddIssue_IssueIsInList_DoesNotAddIssueAndReturnsCorrectResult()
        {
            using (InMemoryIssueStore store = new InMemoryIssueStore())
            {
                using (ShimsContext.Create())
                {
                    IFingerprint actualFingerprint = null;
                    IFingerprint fingerprint       = new StubIFingerprint
                    {
                        EqualsIFingerprint = (f) =>
                        {
                            actualFingerprint = f;
                            return(true);
                        }
                    };

                    Issue issue1 = new ShimIssue
                    {
                        FingerprintGet = () => fingerprint,
                    };
                    Assert.AreEqual(AddResult.ItemAdded, store.AddIssue(issue1));
                    Assert.IsNull(actualFingerprint);

                    Issue issue2 = new ShimIssue
                    {
                        FingerprintGet = () => fingerprint,
                    };
                    Assert.AreEqual(AddResult.ItemAlreadyExists, store.AddIssue(issue2));
                    Assert.AreSame(fingerprint, actualFingerprint);
                    List <Issue> issueList = store.Issues.ToList();
                    Assert.AreEqual(1, issueList.Count);
                    Assert.AreSame(issue1, issueList[0]);
                }
            }
        }
コード例 #2
0
        public void TryFindIssue_FingerprintDoesMatch_ReturnsTrueAndCorrectIssue()
        {
            using (InMemoryIssueStore store = new InMemoryIssueStore())
            {
                using (ShimsContext.Create())
                {
                    IFingerprint actualFingerprint = null;
                    IFingerprint fingerprint       = new StubIFingerprint
                    {
                        EqualsIFingerprint = (f) =>
                        {
                            actualFingerprint = f;
                            return(true);
                        },
                    };

                    Issue issue = new ShimIssue
                    {
                        FingerprintGet = () => fingerprint,
                    };

                    store.AddIssue(issue);
                    Assert.IsTrue(store.TryFindIssue(fingerprint, out Issue actualIssue));
                    Assert.AreSame(fingerprint, actualFingerprint);
                    Assert.AreSame(issue, actualIssue);
                }
            }
        }
コード例 #3
0
        public void TryFindIssue_IssueIsInStore_ReturnsTrueWithCorrectIssue()
        {
            using (ShimsContext.Create())
            {
                IFingerprint actualFingerprint   = null;
                IFingerprint expectedFingerprint = new StubIFingerprint
                {
                    EqualsIFingerprint = (f) => { actualFingerprint = f; return(true); },
                };
                Issue actualIssue   = null;
                Issue expectedIssue = new ShimIssue();

                using (IIssueStore store = new OutputFileIssueStore(TestFile, Enumerable.Empty <A11yElement>(), (f, e, s) =>
                {
                    s.Add(expectedFingerprint, expectedIssue);
                }))
                {
                    Assert.IsNull(actualFingerprint);
                    Assert.IsNull(actualIssue);
                    Assert.IsTrue(store.TryFindIssue(expectedFingerprint, out actualIssue));
                    Assert.AreSame(expectedFingerprint, actualFingerprint);
                    Assert.AreSame(expectedIssue, actualIssue);
                }
            }
        }
コード例 #4
0
        public void AddIssue_IssuesExist_ReturnsCorrectSet()
        {
            using (ShimsContext.Create())
            {
                IFingerprint fingerprint1 = new StubIFingerprint {
                    EqualsIFingerprint = (f) => false
                };
                IFingerprint fingerprint2 = new StubIFingerprint();
                IFingerprint fingerprint3 = new StubIFingerprint();
                Issue        issue1       = new ShimIssue();
                Issue        issue2       = new ShimIssue();
                Issue        issue3       = new ShimIssue();
                using (IIssueStore store = new OutputFileIssueStore(TestFile, Enumerable.Empty <A11yElement>(), (f, e, s) =>
                {
                    s.Add(fingerprint1, issue1);
                    s.Add(fingerprint2, issue2);
                    s.Add(fingerprint3, issue3);
                }))
                {
                    List <Issue> issueList = store.Issues.ToList();

                    // Issues are unsorted!
                    Assert.AreEqual(3, issueList.Count);
                    Assert.IsTrue(issueList.Contains(issue1));
                    Assert.IsTrue(issueList.Contains(issue2));
                    Assert.IsTrue(issueList.Contains(issue3));
                }
            }
        }
コード例 #5
0
        public void MergeIssuesFromStore_SourceIssueIsInTarget_AddsLocationToIssue_AddSucceeds_ReturnsOne()
        {
            using (ShimsContext.Create())
            {
                IFingerprint actualFingerprint   = null;
                ILocation    actualLocation      = null;
                IFingerprint expectedFingerprint = new StubIFingerprint();
                ILocation    expectedLocation    = new StubILocation();
                Issue        expectedIssue       = new ShimIssue
                {
                    FingerprintGet = () => expectedFingerprint,
                    LocationsGet   = () => new List <ILocation> {
                        expectedLocation
                    },
                    AddLocationILocation = (l) =>
                    {
                        actualLocation = l;
                        return(AddResult.ExistingItemUpdated);
                    },
                };

                using (IIssueStore sourceStore = new StubIIssueStore
                {
                    IsEnumerableGet = () => true,
                    IssuesGet = () => new List <Issue> {
                        expectedIssue
                    },
                })
                    using (IIssueStore targetStore = new StubIIssueStore
                    {
                        IsUpdatableGet = () => true,
                        TryFindIssueIFingerprintIssueOut = (IFingerprint f, out Issue i) =>
                        {
                            actualFingerprint = f;
                            i = expectedIssue;
                            return(true);
                        },
                    })
                    {
                        Assert.IsNull(actualFingerprint);
                        Assert.IsNull(actualLocation);
                        Assert.AreEqual(1, targetStore.MergeIssuesFromStore(sourceStore));
                        Assert.AreSame(expectedFingerprint, actualFingerprint);
                        Assert.AreSame(expectedLocation, actualLocation);
                    }
            }
        }
コード例 #6
0
        public void AddIssue_IssueIsNotInList_AddsIssueAndReturnsCorrectResult()
        {
            using (InMemoryIssueStore store = new InMemoryIssueStore())
            {
                using (ShimsContext.Create())
                {
                    Issue issue = new ShimIssue
                    {
                        FingerprintGet = () => new StubIFingerprint(),
                    };
                    Assert.AreEqual(AddResult.ItemAdded, store.AddIssue(issue));

                    List <Issue> issueList = store.Issues.ToList();
                    Assert.AreEqual(1, issueList.Count);
                    Assert.AreSame(issue, issueList[0]);
                }
            }
        }
コード例 #7
0
        public void MergeIssuesFromStore_SourceIssueIsNotInTarget_AddsIssueToTarget_AddSucceeds_ReturnsOne()
        {
            using (ShimsContext.Create())
            {
                IFingerprint actualFingerprint   = null;
                Issue        actualIssue         = null;
                IFingerprint expectedFingerprint = new StubIFingerprint();
                Issue        expectedIssue       = new ShimIssue
                {
                    FingerprintGet = () => expectedFingerprint,
                };

                using (IIssueStore sourceStore = new StubIIssueStore
                {
                    IsEnumerableGet = () => true,
                    IssuesGet = () => new List <Issue> {
                        expectedIssue
                    },
                })
                    using (IIssueStore targetStore = new StubIIssueStore
                    {
                        IsUpdatableGet = () => true,
                        TryFindIssueIFingerprintIssueOut = (IFingerprint f, out Issue i) =>
                        {
                            actualFingerprint = f;
                            i = null;
                            return(false);
                        },
                        AddIssueIssue = (i) =>
                        {
                            actualIssue = i;
                            return(AddResult.ItemAdded);
                        },
                    })
                    {
                        Assert.IsNull(actualFingerprint);
                        Assert.IsNull(actualIssue);
                        Assert.AreEqual(1, targetStore.MergeIssuesFromStore(sourceStore));
                        Assert.AreSame(expectedFingerprint, actualFingerprint);
                        Assert.AreSame(expectedIssue, actualIssue);
                    }
            }
        }
コード例 #8
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]);
            }
        }