public void AddLocation_LocationIsInList_IsNotAddedToLocations()
        {
            using (ShimsContext.Create())
            {
                IFingerprint fingerprint = new StubIFingerprint();

                Issue     issue          = new Issue(fingerprint, IssueType);
                ILocation actualLocation = null;
                ILocation location       = new StubILocation
                {
                    EqualsILocation = (l) => { actualLocation = l; return(true); }
                };

                Assert.AreEqual(AddResult.ItemAdded, issue.AddLocation(location));

                List <ILocation> locationList = issue.Locations.ToList();

                Assert.AreEqual(1, locationList.Count);
                Assert.AreSame(location, locationList[0]);
                Assert.IsNull(actualLocation);

                Assert.AreEqual(AddResult.ItemAlreadyExists, issue.AddLocation(location));
                Assert.AreEqual(1, issue.Locations.Count());
                Assert.AreSame(location, actualLocation);
            }
        }
Beispiel #2
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);
                    }
            }
        }
        public void AddLocation_LocationIsNotInList_IsAddedToLocations()
        {
            using (ShimsContext.Create())
            {
                IFingerprint fingerprint = new StubIFingerprint();

                Issue issue = new Issue(fingerprint, IssueType);

                ILocation location = new StubILocation();

                Assert.AreEqual(AddResult.ItemAdded, issue.AddLocation(location));

                List <ILocation> locationList = issue.Locations.ToList();

                Assert.AreEqual(1, locationList.Count);
                Assert.AreSame(location, locationList[0]);
            }
        }
Beispiel #4
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]);
            }
        }