/// <summary>
        /// Adds a new console execute test step.
        /// </summary>
        /// <param name="testStep">The test step.</param>
        public void Add(ConsoleExecuteTestStep testStep)
        {
            VerifySchemaVersion();
            var result = StoredTestSteps.Add(testStep) as ConsoleExecuteTestStep;
            Debug.Assert(result != null, "The test step should be a console execute test step.");

            Patch(result);
        }
        public void Execute()
        {
            RetrieveFileDataForTestStep testFileLocation = index => @"c:\a\b";
            UploadReportFilesForTestStep uploader = (index, upload) => { };

            var runner = new Mock<IRunConsoleApplications>();
            {
                runner.Setup(r => r.Run(It.IsAny<string>(), It.IsAny<string[]>()))
                    .Callback(() => runner.Raise(r => r.OnConsoleOutput += null, new ProcessOutputEventArgs("foo")))
                    .Returns(0);
            }

            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>());
            var sectionBuilder = new Mock<ITestSectionBuilder>();
            var diagnostics = new SystemDiagnostics((p, s) => { }, null);
            var executor = new ConsoleExecuteTestStepProcessor(
                testFileLocation,
                uploader,
                diagnostics,
                runner.Object,
                fileSystem,
                sectionBuilder.Object);

            var parameters = new List<TestStepParameter>
                {
                    new TestStepParameter
                        {
                            Key = "0",
                            Value = "Value",
                        },
                };

            var data = new ConsoleExecuteTestStep
            {
                pk_TestStepId = 1,
                Order = 2,
                TestStepParameters = parameters,
                ExecutableFilePath = @"c:\c\o\n\sole.exe"
            };

            var result = executor.Process(data, new List<InputParameter>());
            Assert.AreEqual(TestExecutionState.Passed, result);
        }
        public void ExecuteWithExceptionInConsoleRunner()
        {
            RetrieveFileDataForTestStep testFileLocation = index => @"c:\a\b";
            UploadReportFilesForTestStep uploader = (index, upload) => { };

            var runner = new Mock<IRunConsoleApplications>();
            {
                runner.Setup(r => r.Run(It.IsAny<string>(), It.IsAny<string[]>()))
                    .Throws<NotImplementedException>();
            }

            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>());
            var sectionBuilder = new Mock<ITestSectionBuilder>();
            var diagnostics = new SystemDiagnostics((p, s) => { }, null);

            var executor = new ConsoleExecuteTestStepProcessor(
                testFileLocation,
                uploader,
                diagnostics,
                runner.Object,
                fileSystem,
                sectionBuilder.Object);

            var data = new ConsoleExecuteTestStep
            {
                pk_TestStepId = 1,
                Order = 2,
                ExecutableFilePath = @"c:\c\o\n\sole.exe"
            };

            var result = executor.Process(data, new List<InputParameter>());
            Assert.AreEqual(TestExecutionState.Failed, result);
        }
        private ConsoleExecuteTestStep Patch(ConsoleExecuteTestStep consoleTestStep)
        {
            var result = Patch((TestStep)consoleTestStep) as ConsoleExecuteTestStep;
            Debug.Assert(result != null, "The test step should be an console execute test step.");

            return result;
        }
        private void Update(ConsoleExecuteTestStep stored, ConsoleExecuteTestStep changed)
        {
            var shouldPatch = Update(stored as TestStep, changed as TestStep);
            stored.ExecutableFilePath = changed.ExecutableFilePath;

            if (shouldPatch)
            {
                stored.IsPatched = false;
                Patch(stored);
            }
        }
Ejemplo n.º 6
0
        private static TestStep CopyStepAndStripNonEssentialInformation(TestStep step)
        {
            var parameters = new List<TestStepParameter>();
            foreach (var parameter in step.Parameters)
            {
                parameters.Add(
                    new TestStepParameter
                    {
                        Key = parameter.Key,
                        Value = parameter.Value,
                    });
            }

            var reportDirectories = new List<TestStepReportDirectory>();
            foreach (var directory in step.ReportDirectories)
            {
                reportDirectories.Add(
                    new TestStepReportDirectory
                    {
                        Path = directory.Path,
                    });
            }

            var reportFiles = new List<TestStepReportFile>();
            foreach (var file in step.ReportFiles)
            {
                reportFiles.Add(
                    new TestStepReportFile
                    {
                        Path = file.Path,
                    });
            }

            TestStep result = null;
            var consoleStep = step as ConsoleExecuteTestStep;
            if (consoleStep != null)
            {
                var newStep = new ConsoleExecuteTestStep
                {
                    Order = step.Order,
                    FailureMode = step.FailureMode,
                    ReportIncludesSystemLog = step.ReportIncludesSystemLog,
                    ExecutableFilePath = consoleStep.ExecutableFilePath,
                };

                result = newStep;
            }

            var msiStep = step as MsiInstallTestStep;
            if (msiStep != null)
            {
                var newStep = new MsiInstallTestStep
                {
                    Order = step.Order,
                    FailureMode = step.FailureMode,
                    ReportIncludesSystemLog = step.ReportIncludesSystemLog,
                };

                result = newStep;
            }

            var scriptStep = step as ScriptExecuteTestStep;
            if (scriptStep != null)
            {
                var newStep = new ScriptExecuteTestStep
                {
                    Order = step.Order,
                    FailureMode = step.FailureMode,
                    ReportIncludesSystemLog = step.ReportIncludesSystemLog,
                    ScriptLanguage = scriptStep.ScriptLanguage,
                };

                result = newStep;
            }

            var xcopyStep = step as XCopyTestStep;
            if (xcopyStep != null)
            {
                var newStep = new XCopyTestStep
                {
                    Order = step.Order,
                    FailureMode = step.FailureMode,
                    ReportIncludesSystemLog = step.ReportIncludesSystemLog,
                    Destination = xcopyStep.Destination,
                };

                result = newStep;
            }

            result.Parameters = parameters;
            result.ReportDirectories = reportDirectories;
            result.ReportFiles = reportFiles;
            return result;
        }
Ejemplo n.º 7
0
        public int RegisterConsole(
            int environment,
            int order,
            string failureMode,
            bool shouldIncludeSystemLog,
            string executablePath)
        {
            var testStep = new ConsoleExecuteTestStep
            {
                Order = order,
                TestEnvironmentId = environment,
                FailureMode = (TestStepFailureMode)Enum.Parse(typeof(TestStepFailureMode), failureMode),
                ReportIncludesSystemLog = shouldIncludeSystemLog,
                ExecutableFilePath = executablePath,
            };

            try
            {
                m_Context.Add(testStep);
                m_Context.StoreChanges();
            }
            catch (Exception e)
            {
                m_Diagnostics.Log(
                    LevelToLog.Error,
                    WebApiConstants.LogPrefix,
                    string.Format(
                        CultureInfo.InvariantCulture,
                        "Registering the console test step failed with error: {0}",
                        e));

                throw;
            }

            return testStep.Id;
        }