public void Execute_WithErrors_CreatesSnapshotAndA11yTestFile()
        {
            _scanToolsMock.Setup(x => x.TargetElementLocator).Returns(_targetElementLocatorMock.Object);
            _scanToolsMock.Setup(x => x.Actions).Returns(_actionsMock.Object);
            _scanToolsMock.Setup(x => x.NativeMethods).Returns(_nativeMethodsMock.Object);
            _scanToolsMock.Setup(x => x.ResultsAssembler).Returns(_resultsAssemblerMock.Object);
            _scanToolsMock.Setup(x => x.OutputFileHelper).Returns(_outputFileHelperMock.Object);

            _targetElementLocatorMock.Setup(x => x.LocateRootElement(It.IsAny <int>())).Returns(new A11yElement());

            var expectedResults = new ScanResults();

            expectedResults.ErrorCount = 75;
            InitResultsCallback(expectedResults);

            var expectedPath = "Test.file";

            _actionsMock.Setup(x => x.CaptureScreenshot(It.IsAny <Guid>()));
            _actionsMock.Setup(x => x.SaveA11yTestFile(expectedPath, It.IsAny <A11yElement>(), It.IsAny <Guid>()));

            _outputFileHelperMock.Setup(m => m.EnsureOutputDirectoryExists());
            _outputFileHelperMock.Setup(x => x.GetNewA11yTestFilePath()).Returns(expectedPath);

            var config = Config.Builder
                         .ForProcessId(-1)
                         .WithOutputFileFormat(OutputFileFormat.A11yTest)
                         .Build();

            var actualResults = SnapshotCommand.Execute(config, _scanToolsMock.Object);

            Assert.AreEqual(75, actualResults.ErrorCount);
            Assert.AreEqual(expectedPath, actualResults.OutputFile.A11yTest);

            _scanToolsMock.VerifyAll();
            _nativeMethodsMock.VerifyAll();
            _targetElementLocatorMock.VerifyAll();
            _actionsMock.VerifyAll();
            _resultsAssemblerMock.VerifyAll();
            _outputFileHelperMock.VerifyAll();
        }
        public void Execute_NullOutputFileHelper_ThrowsException()
        {
            _scanToolsMock.Setup(x => x.TargetElementLocator).Returns(_targetElementLocatorMock.Object);
            _scanToolsMock.Setup(x => x.Actions).Returns(_actionsMock.Object);
            _scanToolsMock.Setup(x => x.NativeMethods).Returns(_nativeMethodsMock.Object);
            _scanToolsMock.Setup(x => x.ResultsAssembler).Returns(_resultsAssemblerMock.Object);
            _scanToolsMock.Setup(x => x.OutputFileHelper).Returns <IOutputFileHelper>(null);
            _targetElementLocatorMock.Setup(x => x.LocateRootElement(It.IsAny <int>())).Returns(new A11yElement());
            var expectedResults = new ScanResults();

            expectedResults.ErrorCount = 1;
            InitResultsCallback(expectedResults);
            var action = new Action(() => SnapshotCommand.Execute(_minimalConfig, _scanToolsMock.Object));
            var ex     = Assert.ThrowsException <ArgumentException>(action);

            Assert.IsTrue(ex.Message.Contains("OutputFileHelper"));
            _scanToolsMock.VerifyAll();
            _nativeMethodsMock.VerifyAll();
            _targetElementLocatorMock.VerifyAll();
            _actionsMock.VerifyAll();
            _resultsAssemblerMock.VerifyAll();
        }
Exemple #3
0
        public void Execute_ReturnsExpectedResults()
        {
            _scanToolsMock.Setup(x => x.TargetElementLocator).Returns(_targetElementLocatorMock.Object);
            _scanToolsMock.Setup(x => x.Actions).Returns(_actionsMock.Object);
            _scanToolsMock.Setup(x => x.NativeMethods).Returns(_nativeMethodsMock.Object);
            _scanToolsMock.Setup(x => x.ResultsAssembler).Returns(_resultsAssemblerMock.Object);

            _targetElementLocatorMock.Setup(x => x.LocateRootElement(It.IsAny <int>())).Returns(new A11yElement());

            var expectedResults = new ScanResults();

            InitResultsCallback(expectedResults);

            var actualResults = SnapshotCommand.Execute(_minimalConfig, _scanToolsMock.Object);

            Assert.AreEqual(expectedResults, actualResults);

            _scanToolsMock.VerifyAll();
            _nativeMethodsMock.VerifyAll();
            _targetElementLocatorMock.VerifyAll();
            _actionsMock.VerifyAll();
            _resultsAssemblerMock.VerifyAll();
        }
Exemple #4
0
        public void Execute_NullOutputFilePath_ThrowsException()
        {
            _scanToolsMock.Setup(x => x.TargetElementLocator).Returns(_targetElementLocatorMock.Object);
            _scanToolsMock.Setup(x => x.Actions).Returns(_actionsMock.Object);
            _scanToolsMock.Setup(x => x.NativeMethods).Returns(_nativeMethodsMock.Object);
            _scanToolsMock.Setup(x => x.ResultsAssembler).Returns(_resultsAssemblerMock.Object);
            _scanToolsMock.Setup(x => x.OutputFileHelper).Returns(_outputFileHelperMock.Object);

            _targetElementLocatorMock.Setup(x => x.LocateRootElement(It.IsAny <int>())).Returns(new A11yElement());

            var expectedResults = new ScanResults();

            expectedResults.ErrorCount = 1;
            InitResultsCallback(expectedResults);

            _actionsMock.Setup(x => x.CaptureScreenshot(It.IsAny <Guid>()));

            _outputFileHelperMock.Setup(x => x.GetNewA11yTestFilePath()).Returns <string>(null);

            var config = Config.Builder
                         .ForProcessId(-1)
                         .WithOutputFileFormat(OutputFileFormat.A11yTest)
                         .Build();

            var action = new Action(() => SnapshotCommand.Execute(config, _scanToolsMock.Object));
            var ex     = Assert.ThrowsException <AxeWindowsAutomationException>(action);

            Assert.IsInstanceOfType(ex.InnerException, typeof(InvalidOperationException));
            Assert.IsTrue(ex.Message.Contains("a11yTestOutputFile"));

            _scanToolsMock.VerifyAll();
            _nativeMethodsMock.VerifyAll();
            _targetElementLocatorMock.VerifyAll();
            _actionsMock.VerifyAll();
            _resultsAssemblerMock.VerifyAll();
            _outputFileHelperMock.VerifyAll();
        }
Exemple #5
0
        public void Execute_NullResultsAssembler_ThrowsException()
        {
            _scanToolsMock.Setup(x => x.TargetElementLocator).Returns(_targetElementLocatorMock.Object);
            _scanToolsMock.Setup(x => x.Actions).Returns(_actionsMock.Object);
            _scanToolsMock.Setup(x => x.ResultsAssembler).Returns <IScanResultsAssembler>(null);

            _targetElementLocatorMock.Setup(x => x.LocateRootElement(It.IsAny <int>())).Returns(new A11yElement());

            ScanResults tempResults = null;

            _actionsMock.Setup(x => x.Scan(It.IsAny <A11yElement>(), It.IsAny <ScanActionCallback <ScanResults> >()))
            .Callback <A11yElement, ScanActionCallback <ScanResults> >((e, cb) => tempResults = cb(e, Guid.Empty))
            .Returns(() => tempResults);

            var action = new Action(() => SnapshotCommand.Execute(_minimalConfig, _scanToolsMock.Object));
            var ex     = Assert.ThrowsException <AxeWindowsAutomationException>(action);

            Assert.IsInstanceOfType(ex.InnerException, typeof(ArgumentNullException));
            Assert.IsTrue(ex.Message.Contains("ResultsAssembler"));

            _scanToolsMock.VerifyAll();
            _targetElementLocatorMock.VerifyAll();
            _actionsMock.VerifyAll();
        }
Exemple #6
0
        /// <summary>
        /// This entry point does not ship, but it makes for a quick and easy way to debug through the
        /// automation code. One caveat--we intentionally don't build symbols for this app, so while you
        /// can use it to to debug the automation code, breakpoints set in this class will be ignored.
        /// </summary>
        static void Main(string[] args)
        {
            Dictionary <string, string> parameters = new Dictionary <string, string>();
            string secondaryConfigFile             = string.Empty;

            char[] delimiters = { '=' };

            foreach (string arg in args)
            {
                string[] pieces = arg.Split(delimiters);
                if (pieces.Length == 2)
                {
                    string key   = pieces[0].Trim();
                    string value = pieces[1].Trim();

                    if (!string.IsNullOrWhiteSpace(key) && !string.IsNullOrWhiteSpace(value))
                    {
                        // Special case for SecondaryConfigFile
                        if (key.Equals("SecondaryConfigFile", StringComparison.OrdinalIgnoreCase))
                        {
                            secondaryConfigFile = value;
                        }
                        else
                        {
                            parameters[key] = value;
                        }
                        continue;
                    }
                }

                Console.WriteLine("Ignoring malformed input: {0}", arg);
            }
            ;

            Console.WriteLine(StartCommand.Execute(parameters, secondaryConfigFile).ToString());

            int autoFileId = 0;

            while (true)
            {
                Console.Write("Enter process ID to capture (blank to exit): ");
                string input = Console.ReadLine();

                if (string.IsNullOrEmpty(input))
                {
                    break;
                }

                if (!int.TryParse(input, out int processId))
                {
                    Console.WriteLine("Not a valid int: " + input);
                    continue;
                }

                Dictionary <string, string> snapshotParameters = new Dictionary <string, string>
                {
                    { CommandConstStrings.TargetProcessId, input },
                    { CommandConstStrings.OutputFile, autoFileId++.ToString(CultureInfo.InvariantCulture) },
                };
                Console.WriteLine(SnapshotCommand.Execute(snapshotParameters).ToString());
            }
            Console.WriteLine(StopCommand.Execute().ToString());
        }