Пример #1
0
        public void Execute_OnlyUnsupportedsInPOI_RetentionIsEnabled_SavesFile_ReturnsComplete_UnsupportedsOnly()
        {
            using (ShimsContext.Create())
            {
                List <ScanStatus> scanStatusUnsupported = new List <ScanStatus> {
                    ScanStatus.ScanNotSupported
                };

                ShimSelectAction selectAction = new ShimSelectAction()
                {
                    SetCandidateElementA11yElement = (element) => { },
                    Select = () => true,
                    POIElementContextGet = () => new ElementContext(
                        CreateA11yElement(
                            new List <A11yElement>
                    {
                        CreateA11yElement(new List <A11yElement>(), scanStatusUnsupported)
                    },
                            scanStatusUnsupported))
                };

                InitializeShims(populateLocationHelper: true, enableRetention: true, shimTargetElementLocator: true,
                                selectAction: selectAction, elementBoundExceeded: false, shimUiFramework: true,
                                setTestModeSucceeds: true, shimScreenCapture: true, shimSnapshot: true, shimSarif: true);

                SnapshotCommandResult result = SnapshotCommand.Execute(new Dictionary <string, string>());

                AssertCompleteResult(result, 0, 0, 0, 2);
            }
        }
Пример #2
0
        public void Execute_NoScanResultsInPOI_RetentionIsEnabled_SavesFile_ReturnsCompleteWithNoIssues()
        {
            using (ShimsContext.Create())
            {
                ShimSelectAction selectAction = new ShimSelectAction()
                {
                    SetCandidateElementA11yElement = (element) => { },
                    Select = () => true,
                    POIElementContextGet = () => new ElementContext(
                        new A11yElement
                    {
                        ScanResults = new ScanResults(),
                        Children    = new List <A11yElement>
                        {
                            new A11yElement
                            {
                                ScanResults = new ScanResults(),
                                Children    = new List <A11yElement>(),
                            }
                        }
                    }),
                };

                InitializeShims(populateLocationHelper: true, enableRetention: true, shimTargetElementLocator: true,
                                selectAction: selectAction, elementBoundExceeded: false, shimUiFramework: true,
                                setTestModeSucceeds: true, shimScreenCapture: true, shimSnapshot: true, shimSarif: true);

                SnapshotCommandResult result = SnapshotCommand.Execute(new Dictionary <string, string>());

                AssertCompleteResult(result, 0, 0, 0, 0);
            }
        }
        /// <summary>
        /// Set up all of the shims needed for the unit tests--we make no attempt to
        /// identify a subset of shims to configure
        /// </summary>
        private static void InitializeShims()
        {
            ShimDataManager shimDataManager = new ShimDataManager();

            ShimDataManager.GetDefaultInstance = () => shimDataManager;

            ShimSelectAction shimSelectAction = new ShimSelectAction();

            ShimSelectAction.GetDefaultInstance = () => shimSelectAction;
        }
Пример #4
0
        public void Execute_MixedResultsInPOI_RetentionIsEnabled_SavesFile_ReturnsComplete_CorrectMixedResults()
        {
            using (ShimsContext.Create())
            {
                ShimSelectAction selectAction = new ShimSelectAction()
                {
                    SetCandidateElementA11yElement = (element) => { },
                    Select = () => true,
                    POIElementContextGet = () => new ElementContext(
                        CreateA11yElement(
                            new List <A11yElement>
                    {
                        CreateA11yElement(new List <A11yElement>(), new List <ScanStatus>
                        {
                            ScanStatus.Fail, ScanStatus.Pass           // Will count as failure
                        }),
                        CreateA11yElement(new List <A11yElement>(), new List <ScanStatus>
                        {
                            ScanStatus.Pass          // Will count as pass
                        }),
                        CreateA11yElement(new List <A11yElement>(), new List <ScanStatus>
                        {
                            ScanStatus.Uncertain, ScanStatus.Uncertain, ScanStatus.ScanNotSupported          // Will count as unsupported
                        }),
                        CreateA11yElement(new List <A11yElement>(), new List <ScanStatus>
                        {
                            ScanStatus.Pass, ScanStatus.Uncertain, ScanStatus.NoResult          // Will count as uncertain
                        }),
                        CreateA11yElement(new List <A11yElement>(), new List <ScanStatus>
                        {
                            ScanStatus.Uncertain, ScanStatus.NoResult          // Will count as uncertain
                        }),
                    },
                            new List <ScanStatus>
                    {
                        ScanStatus.Pass          // Will count as pass
                    }))
                };

                InitializeShims(populateLocationHelper: true, enableRetention: true, shimTargetElementLocator: true,
                                selectAction: selectAction, elementBoundExceeded: false, shimUiFramework: true,
                                setTestModeSucceeds: true, shimScreenCapture: true, shimSnapshot: true, shimSarif: true);

                SnapshotCommandResult result = SnapshotCommand.Execute(new Dictionary <string, string>());

                // Note: Results are for each A11yElement, not for each ScanStatus!
                AssertCompleteResult(result, 2, 1, 2, 1);
            }
        }
Пример #5
0
        public void Execute_UnableToSelectCandidateElement_ReturnsIncomplete_ErrorAutomation008()
        {
            using (ShimsContext.Create())
            {
                ShimSelectAction selectAction = new ShimSelectAction()
                {
                    SetCandidateElementA11yElement = (element) => { },
                    Select = () => false,
                };

                InitializeShims(selectAction: selectAction, populateLocationHelper: false, enableRetention: true, shimTargetElementLocator: true);

                SnapshotCommandResult result = SnapshotCommand.Execute(new Dictionary <string, string>());

                AssertIncompleteResult(result, " Automation008:", false);
            }
        }
Пример #6
0
        public void Execute_UnableToSetTestModeDataContext_ReturnsIncomplete_ErrorAutomation008()
        {
            using (ShimsContext.Create())
            {
                ShimSelectAction selectAction = new ShimSelectAction()
                {
                    SetCandidateElementA11yElement = (element) => { },
                    Select = () => true,
                    POIElementContextGet = () => new ElementContext(CreateA11yElement()),
                };

                InitializeShims(populateLocationHelper: false, enableRetention: true, shimTargetElementLocator: true,
                                shimUiFramework: true, setTestModeSucceeds: false);

                SnapshotCommandResult result = SnapshotCommand.Execute(new Dictionary <string, string>());

                AssertIncompleteResult(result, " Automation008:", false);
            }
        }
Пример #7
0
        private static void InitializeShims(
            bool?populateLocationHelper   = null,
            bool?enableRetention          = null,
            bool shimTargetElementLocator = false,
            bool?elementBoundExceeded     = null,
            bool shimUiFramework          = false,
            bool?setTestModeSucceeds      = null,
            bool shimScreenCapture        = false,
            bool shimSnapshot             = false,
            bool shimSarif = false,
            ShimSelectAction selectAction = null)
        {
            if (enableRetention.HasValue)
            {
                ShimAutomationSession.Instance = () =>
                {
                    return(new ShimAutomationSession()
                    {
                        SessionParametersGet = () => new CommandParameters(enableRetention.Value ? TestParameters : TestParametersNoRetention, string.Empty)
                    });
                };
            }

            if (shimTargetElementLocator)
            {
                ShimTargetElementLocator.LocateElementCommandParameters = (commandParameters) =>
                {
                    return(new ElementContext(CreateA11yElement()));
                };
            }

            if (populateLocationHelper.HasValue)
            {
                ShimLocationHelper.ConstructorCommandParameters = (locationHelper, parameters) => CreateShimLocationHelper(locationHelper, populateLocationHelper.Value);
            }

            if (selectAction != null)
            {
                ShimSelectAction.GetDefaultInstance = () => selectAction;
            }

            if (elementBoundExceeded.HasValue)
            {
                SetElementDataContext(elementBoundExceeded.Value);
            }

            if (shimUiFramework)
            {
                ShimGetDataAction.GetProcessAndUIFrameworkOfElementContextGuid = (_) => new Tuple <string, string>("one", "two");
            }

            if (setTestModeSucceeds.HasValue)
            {
                ShimCaptureAction.SetTestModeDataContextGuidDataContextModeTreeViewModeBoolean = (_, __, ___, _____)
                                                                                                 => setTestModeSucceeds.Value;
            }

            if (shimScreenCapture)
            {
                ShimScreenShotAction.CaptureScreenShotGuid = (_) => { };
            }

            if (shimSnapshot)
            {
                ShimSaveAction.SaveSnapshotZipStringGuidNullableOfInt32A11yFileModeDictionaryOfSnapshotMetaPropertyNameObjectCompletenessMode = (_, __, ___, ____, _____, ______) => { };
            }

            if (shimSarif)
            {
                ShimSaveAction.SaveSarifFileStringGuidBoolean = (_, __, ___) => { };
            }
        }