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]); } } }
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); } } }
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); } } }
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); } }
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)); } } }
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)); } }
public void CompareTo_OtherIsDifferentImplemention_ThrowsInvalidOperationException() { using (ShimsContext.Create()) { IFingerprint fingerprint = new ScanResultFingerprint(new A11yElement(), DefaultRule, DefaultScanStatus); StubIFingerprint other = new StubIFingerprint(); fingerprint.CompareTo(other); } }
public void TryFindIssue_FingerprintDoesNotMatch_ReturnsFalse() { using (InMemoryIssueStore store = new InMemoryIssueStore()) { using (ShimsContext.Create()) { IFingerprint fingerprint = new StubIFingerprint(); Assert.IsFalse(store.TryFindIssue(fingerprint, out Issue issue)); Assert.IsNull(issue); } } }
public void Ctor_FingerprintIsValid_SetsInitialProperties() { using (ShimsContext.Create()) { IFingerprint fingerprint = new StubIFingerprint(); Issue issue = new Issue(fingerprint, IssueType); Assert.AreEqual(IssueType, issue.IssueType); Assert.AreSame(fingerprint, issue.Fingerprint); Assert.IsFalse(issue.Locations.Any()); } }
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]); } }
public void AddLocation_LocationIsNull_ThrowsArgumentNullException() { using (ShimsContext.Create()) { IFingerprint fingerprint = new StubIFingerprint(); Issue issue = new Issue(fingerprint, IssueType); try { issue.AddLocation(null); } catch (ArgumentNullException e) { Assert.AreEqual("location", e.ParamName); throw; } } }
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); } } }
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]); } }