Ejemplo n.º 1
0
        public void Test_copying_all_files_when_dst_exists()
        {
            const string srcDirPath = "Core\\TestData\\TestSrcDir";
            const string dstDirPath = "Core\\TestData\\TestDstDir";

            try
            {
                Directory.CreateDirectory(dstDirPath);

                var copyFilesDeploymentStep =
                    new CopyFilesDeploymentStep(
                        _directoryAdapter,
                        new Lazy <string>(() => srcDirPath),
                        new Lazy <string>(() => dstDirPath));

                copyFilesDeploymentStep.PrepareAndExecute();

                Assert.IsTrue(Directory.Exists(dstDirPath));

                Assert.AreEqual(
                    Directory.GetFiles(srcDirPath, "*.*", SearchOption.AllDirectories).Length,
                    Directory.GetFiles(dstDirPath, "*.*", SearchOption.AllDirectories).Length);
            }
            finally
            {
                if (Directory.Exists(dstDirPath))
                {
                    Directory.Delete(dstDirPath, true);
                }
            }
        }
Ejemplo n.º 2
0
        public void Test_copying_all_files_throws_when_no_src()
        {
            const string srcDirPath = "Core\\TestData\\aoisdiasyd";
            const string dstDirPath = "Core\\TestData\\TestDstDir";

            try
            {
                var copyFilesDeploymentStep =
                    new CopyFilesDeploymentStep(
                        _directoryAdapter,
                        new Lazy <string>(() => srcDirPath),
                        new Lazy <string>(() => dstDirPath));

                Assert.Throws <DeploymentTaskException>(() => copyFilesDeploymentStep.PrepareAndExecute());
            }
            finally
            {
                if (Directory.Exists(dstDirPath))
                {
                    Directory.Delete(dstDirPath, true);
                }
            }
        }
        protected override void DoPrepare()
        {
            EnvironmentInfo environmentInfo = GetEnvironmentInfo();

            _projectInfo = GetProjectInfo <PowerShellScriptProjectInfo>();

            IEnumerable <string> targetMachineNames = _projectInfo.GetTargetMachines(environmentInfo);

            // create a step for downloading the artifacts
            var downloadArtifactsDeploymentStep =
                new DownloadArtifactsDeploymentStep(
                    _projectInfo,
                    DeploymentInfo,
                    GetTempDirPath(),
                    _artifactsRepository);

            AddSubTask(downloadArtifactsDeploymentStep);

            // create a step for extracting the artifacts
            var extractArtifactsDeploymentStep =
                new ExtractArtifactsDeploymentStep(
                    _projectInfo,
                    environmentInfo,
                    DeploymentInfo,
                    downloadArtifactsDeploymentStep.ArtifactsFilePath,
                    GetTempDirPath(),
                    _fileAdapter,
                    _directoryAdapter,
                    _zipFileAdapter);

            AddSubTask(extractArtifactsDeploymentStep);

            if (_projectInfo.ArtifactsAreEnvironmentSpecific)
            {
                var binariesConfiguratorStep =
                    new ConfigureBinariesStep(
                        environmentInfo.ConfigurationTemplateName,
                        GetTempDirPath());

                AddSubTask(binariesConfiguratorStep);
            }

            if (_projectInfo.IsRemote == false)
            {
                // Run powershell script
                var runPowerShellScriptStep =
                    new RunPowerShellScriptStep(
                        _projectInfo.IsRemote,
                        null,
                        new Lazy <string>(() => extractArtifactsDeploymentStep.BinariesDirPath),
                        _projectInfo.ScriptName);

                AddSubTask(runPowerShellScriptStep);

                return;
            }

            foreach (var targetMachineName in targetMachineNames)
            {
                // Create temp dir on remote machine
                var createRemoteTempDirStep = new CreateRemoteTempDirStep(targetMachineName);

                AddSubTask(createRemoteTempDirStep);

                // Copy files to remote machine
                string machineName = targetMachineName;

                var copyFilesDeploymentStep = new CopyFilesDeploymentStep(
                    _directoryAdapter,
                    srcDirPathProvider: new Lazy <string>(() => extractArtifactsDeploymentStep.BinariesDirPath),
                    dstDirPath: new Lazy <string>(() => EnvironmentInfo.GetNetworkPath(machineName, createRemoteTempDirStep.RemoteTempDirPath)));

                AddSubTask(copyFilesDeploymentStep);

                // Run powershell script
                var runPowerShellScriptStep =
                    new RunPowerShellScriptStep(
                        _projectInfo.IsRemote,
                        targetMachineName,
                        new Lazy <string>(() => createRemoteTempDirStep.RemoteTempDirPath),
                        _projectInfo.ScriptName);

                AddSubTask(runPowerShellScriptStep);

                // Delete remote temp dir
                var removeRemoteDirectory = new RemoveRemoteDirectoryStep(
                    targetMachineName,
                    new Lazy <string>(() => createRemoteTempDirStep.RemoteTempDirPath));

                AddSubTask(removeRemoteDirectory);
            }
        }