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

            var fileSystem = new System.IO.Abstractions.TestingHelpers.MockFileSystem(
                new Dictionary<string, System.IO.Abstractions.TestingHelpers.MockFileData>
                    {
                        { @"c:\d\e\f.ps1", new System.IO.Abstractions.TestingHelpers.MockFileData("throw 'FAIL'") }
                    });

            var sectionBuilder = new Mock<ITestSectionBuilder>();
            var diagnostics = new SystemDiagnostics((p, s) => { }, null);
            var installer = new XCopyDeployTestStepProcessor(
               testFileLocation,
               uploader,
               diagnostics,
               fileSystem,
               sectionBuilder.Object);

            var data = new XCopyTestStep
                {
                    pk_TestStepId = 1,
                    Order = 2,
                    Destination = @"c:\d\e",
                };

            var result = installer.Process(data, new List<InputParameter>());
            Assert.AreEqual(TestExecutionState.Passed, result);
        }
        private XCopyTestStep Patch(XCopyTestStep xcopyTestStep)
        {
            var result = Patch((TestStep)xcopyTestStep) as XCopyTestStep;
            Debug.Assert(result != null, "The test step should be an x-copy test step.");

            return result;
        }
        /// <summary>
        /// Adds a new x-copy test step.
        /// </summary>
        /// <param name="testStep">The test step.</param>
        public void Add(XCopyTestStep testStep)
        {
            VerifySchemaVersion();

            var result = StoredTestSteps.Add(testStep) as XCopyTestStep;
            Debug.Assert(result != null, "The test step should be a x-copy test step.");

            Patch(result);
        }
        private void Update(XCopyTestStep stored, XCopyTestStep changed)
        {
            var shouldPatch = Update(stored as TestStep, changed as TestStep);
            stored.Destination = changed.Destination;

            if (shouldPatch)
            {
                stored.IsPatched = false;
                Patch(stored);
            }
        }
示例#5
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;
        }
        public int RegisterXCopy(int environment, int order, string failureMode, bool shouldIncludeSystemLog, string destination)
        {
            var testStep = new XCopyTestStep
            {
                Order = order,
                TestEnvironmentId = environment,
                FailureMode = (TestStepFailureMode)Enum.Parse(typeof(TestStepFailureMode), failureMode),
                ReportIncludesSystemLog = shouldIncludeSystemLog,
                Destination = destination,
            };

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

                throw;
            }

            return testStep.Id;
        }
        public void Install()
        {
            RetrieveFileDataForTestStep testFileLocation = index => @"c:\a\b";
            UploadReportFilesForTestStep uploader = (index, upload) => { };

            var files = new Dictionary<string, string>
                {
                    {
                        @"c:\a\b\c.ps1", "throw 'FAIL'"
                    },
                    {
                        @"c:\a\b\d\e.ps1", "throw 'FAIL'"
                    },
                    {
                        @"c:\a\b\d\f.ps1", "throw 'FAIL'"
                    },
                    {
                        @"c:\a\b\d\g.ps1", "throw 'FAIL'"
                    },
                };

            var file = new MockFile(files);
            var directory = new MockDirectory(
                new[]
                {
                    @"c:\a\b\d\e.ps1",
                    @"c:\a\b\d\f.ps1",
                    @"c:\a\b\d\g.ps1",
                });
            var fileSystem = new Mock<IFileSystem>();
            {
                fileSystem.Setup(f => f.File)
                    .Returns(file);
                fileSystem.Setup(f => f.Directory)
                    .Returns(directory);
            }

            var sectionBuilder = new Mock<ITestSectionBuilder>();
            var diagnostics = new SystemDiagnostics((p, s) => { }, null);
            var installer = new XCopyDeployTestStepProcessor(
               testFileLocation,
               uploader,
               diagnostics,
               fileSystem.Object,
               sectionBuilder.Object);

            var data = new XCopyTestStep
            {
                pk_TestStepId = 1,
                Order = 2,
                Destination = @"c:\h\i",
            };

            var result = installer.Process(data, new List<InputParameter>());
            Assert.AreEqual(TestExecutionState.Passed, result);
        }