public virtual void SetUp() { _msDeploy = new Mock <IMsDeploy>(); _artifactsRepository = new Mock <IArtifactsRepository>(); _projectInfoRepositoryFake = new Mock <IProjectInfoRepository>(MockBehavior.Loose); _environmentInfoRepositoryFake = new Mock <IEnvironmentInfoRepository>(); _iisManager = new Mock <IIisManager>(); _fileAdapterFake = new Mock <IFileAdapter>(MockBehavior.Loose); _zipFileAdapterFake = new Mock <IZipFileAdapter>(MockBehavior.Loose); _applicationConfigurationFake = new Mock <IApplicationConfiguration>(); _directoryAdapterFake = new Mock <IDirectoryAdapter>(); _projectInfo = ProjectInfoGenerator.GetWebAppProjectInfo(); _environmentInfo = DeploymentDataGenerator.GetEnvironmentInfo(); _deployWebAppDeploymentTask = new DeployWebAppDeploymentTask( _projectInfoRepositoryFake.Object, _environmentInfoRepositoryFake.Object, _msDeploy.Object, _artifactsRepository.Object, _iisManager.Object, _fileAdapterFake.Object, _zipFileAdapterFake.Object, _applicationConfigurationFake.Object, _directoryAdapterFake.Object); _deployWebAppDeploymentTask.Initialize(DeploymentInfoGenerator.GetWebAppDeploymentInfo()); _projectInfoRepositoryFake.Setup(x => x.FindByName(It.IsAny <string>())) .Returns(_projectInfo); _environmentInfoRepositoryFake.Setup(x => x.FindByName(It.IsAny <string>())) .Returns(_environmentInfo); }
private void btn_openWebApp_Click(object sender, EventArgs e) { if (dgv_projectInfos.SelectedRows.Count == 0) { AppUtils.NotifyUserInvalidOperation("No project is selected."); return; } if (cbx_targetEnvironment.SelectedItem == null) { AppUtils.NotifyUserInvalidOperation("No target environment is selected."); return; } ProjectInfo projectInfo = GetSelectedProjectInfo(); WebAppProjectInfo webAppProjectInfo = projectInfo as WebAppProjectInfo; if (webAppProjectInfo == null) { AppUtils.NotifyUserInvalidOperation("Selected project is not a web application."); return; } EnvironmentInfo environmentInfo = GetSelectedEnvironment(); OpenWebApp(webAppProjectInfo, environmentInfo); }
public void Test_GetTargetUrls_RunsProperly_WhenAllIsWell() { string machine = Environment.MachineName; const string baseDirPath = "c:\\basedir"; var envInfo = new EnvironmentInfo( "name", true, "templates", machine, "failover", new[] { "webmachine" }, "terminalmachine", new[] { "schedulerServerTasksMachineName1", "schedulerServerTasksMachineName2", }, new[] { "schedulerServerBinariesMachineName1", "schedulerServerBinariesMachineName2", }, baseDirPath, "webbasedir", "c:\\scheduler", "terminal", false, TestData.EnvironmentUsers, TestData.AppPoolInfos, TestData.DatabaseServers, TestData.ProjectToFailoverClusterGroupMappings, TestData.WebAppProjectConfigurationOverrides, TestData.DbProjectConfigurationOverrides, "terminalAppsShortcutFolder", "artifactsDeploymentDirPath", "domain-name", TestData.CustomEnvMachines); var projectInfo = new WebAppProjectInfo( _Name, _ArtifactsRepositoryName, _AllowedEnvironmentNames, _ArtifactsRepositoryDirName, _ArtifactsAreNotEnvironmentSpecific, _AppPoolId, _WebSiteName, _WebAppDirName, _WebAppName); List <string> targetUrls = projectInfo.GetTargetUrls(envInfo) .ToList(); Assert.IsNotNull(targetUrls); Assert.AreEqual(1, targetUrls.Count); Assert.AreEqual("http://webmachine/" + "webapp", targetUrls[0]); }
private void OpenWebApp(WebAppProjectInfo webAppProjectInfo, EnvironmentInfo environmentInfo) { List <string> targetUrls = _agentService.GetWebAppProjectTargetUrls( webAppProjectInfo.Name, environmentInfo.Name); if (targetUrls.Count == 1) { Process.Start(targetUrls[0]); } else { new OpenTargetUrlsForm(targetUrls) .ShowDialog(); } }
public void Test_GetTargetFolders_RunsProperly_WhenAllIsWell() { string machine = Environment.MachineName; var envInfo = new EnvironmentInfo( "name", true, "templates", machine, "failover", new[] { "webmachine" }, "terminalmachine", new[] { "schedulerServerTasksMachineName1", "schedulerServerTasksMachineName2", }, new[] { "schedulerServerBinariesMachineName1", "schedulerServerBinariesMachineName2", }, "C:\\basedir", "C:\\basedir", "c:\\scheduler", "terminal", false, TestData.EnvironmentUsers, TestData.AppPoolInfos, TestData.DatabaseServers, TestData.ProjectToFailoverClusterGroupMappings, TestData.WebAppProjectConfigurationOverrides, TestData.DbProjectConfigurationOverrides, "terminalAppsShortcutFolder", "artifactsDeploymentDirPath", "domain-name", TestData.CustomEnvMachines); var projectInfo = new WebAppProjectInfo( _Name, _ArtifactsRepositoryName, _AllowedEnvironmentNames, _ArtifactsRepositoryDirName, false, _AppPoolId, _WebSiteName, _WebAppDirName, _WebAppName); Assert.IsNotNullOrEmpty(projectInfo.GetTargetFolders(_objectFactoryFake.Object, envInfo).FirstOrDefault()); }
public void Prepare_should_throw_exception_when_web_appplication_name_is_empty_and_web_site_has_more_than_one_application() { // arrange const string webSiteName = "webSiteName"; _projectInfo = GetWebProjectInfoWithEmptyAppName(webSiteName); _projectInfoRepositoryFake.Setup(x => x.FindByName(It.IsAny <string>())) .Returns(_projectInfo); _projectInfoRepositoryFake.Setup(x => x.GetAll()) .Returns(new List <WebAppProjectInfo> { GetWebProjectInfoWithEmptyAppName(webSiteName), GetWebProjectInfoWithEmptyAppName(webSiteName) }); // act assert Assert.Throws <DeploymentTaskException>(() => _deployWebAppDeploymentTask.Prepare()); }
public void Test_CreateDeployemntTask_RunsProperly_WhenAllIsWell() { var objectFactory = new Mock <IObjectFactory>(MockBehavior.Strict); var prjInfoRepository = new Mock <IProjectInfoRepository>(MockBehavior.Strict); var envInfoRepository = new Mock <IEnvironmentInfoRepository>(MockBehavior.Strict); var artifactsRepository = new Mock <IArtifactsRepository>(MockBehavior.Strict); var taskScheduler = new Mock <ITaskScheduler>(MockBehavior.Strict); var imsDeploy = new Mock <IMsDeploy>(MockBehavior.Strict); var iisManager = new Mock <IIisManager>(MockBehavior.Strict); var fileAdapter = new Mock <IFileAdapter>(MockBehavior.Loose); var zipFileAdapter = new Mock <IZipFileAdapter>(MockBehavior.Loose); var applicationConfiguration = new Mock <IApplicationConfiguration>(MockBehavior.Loose); var directoryAdapter = new Mock <IDirectoryAdapter>(MockBehavior.Loose); var projectInfo = new WebAppProjectInfo( _Name, _ArtifactsRepositoryName, _AllowedEnvironmentNames, _ArtifactsRepositoryDirName, _ArtifactsAreNotEnvironmentSpecific, _AppPoolId, _WebSiteName, _WebAppDirName, _WebAppName); objectFactory.Setup(o => o.CreateProjectInfoRepository()).Returns(prjInfoRepository.Object); objectFactory.Setup(o => o.CreateEnvironmentInfoRepository()).Returns(envInfoRepository.Object); objectFactory.Setup(o => o.CreateArtifactsRepository()).Returns(artifactsRepository.Object); objectFactory.Setup(o => o.CreateTaskScheduler()).Returns(taskScheduler.Object); objectFactory.Setup(o => o.CreateIMsDeploy()).Returns(imsDeploy.Object); objectFactory.Setup(o => o.CreateIIisManager()).Returns(iisManager.Object); objectFactory.Setup(o => o.CreateFileAdapter()).Returns(fileAdapter.Object); objectFactory.Setup(o => o.CreateZipFileAdapter()).Returns(zipFileAdapter.Object); objectFactory.Setup(o => o.CreateApplicationConfiguration()).Returns(applicationConfiguration.Object); objectFactory.Setup(o => o.CreateDirectoryAdapter()).Returns(directoryAdapter.Object); projectInfo.CreateDeploymentTask(objectFactory.Object); }
protected override void DoPrepare() { EnvironmentInfo environmentInfo = GetEnvironmentInfo(); WebAppProjectInfo projectInfo = GetProjectInfo <WebAppProjectInfo>(); WebAppInputParams inputParams = (WebAppInputParams)DeploymentInfo.InputParams; if (inputParams.OnlyIncludedWebMachines != null) { if (!inputParams.OnlyIncludedWebMachines.Any()) { throw new DeploymentTaskException("If inputParams OnlyIncludedWebMachines has been specified, it must contain at least one web machine."); } string[] invalidMachineNames = inputParams.OnlyIncludedWebMachines .Except(environmentInfo.WebServerMachineNames) .ToArray(); if (invalidMachineNames.Any()) { throw new DeploymentTaskException(string.Format("Invalid web machines '{0}' have been specified.", string.Join(",", invalidMachineNames))); } } if (projectInfo == null) { throw new InvalidOperationException(string.Format("Project info must be of type '{0}'.", typeof(WebAppProjectInfo).FullName)); } // 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); } WebAppProjectConfiguration configuration = environmentInfo.GetWebAppProjectConfiguration(projectInfo); CheckConfiguration(configuration); string webSiteName = configuration.WebSiteName; string webAppName = configuration.WebAppName; IisAppPoolInfo appPoolInfo = environmentInfo.GetAppPoolInfo(configuration.AppPoolId); IEnumerable <string> webMachinesToDeployTo = (inputParams.OnlyIncludedWebMachines ?? environmentInfo.WebServerMachineNames) .Distinct(); foreach (string webServerMachineName in webMachinesToDeployTo) { /* // TODO IMM HI: xxx we don't need this for now - should we parameterize this somehow? * string webApplicationPhysicalPath = * _iisManager.GetWebApplicationPath( * webServerMachineName, * string.Format("{0}/{1}", webSiteName, webAppName)); * * if (!string.IsNullOrEmpty(webApplicationPhysicalPath)) * { * string webApplicationNetworkPath = * string.Format( * "\\\\{0}\\{1}${2}", * webServerMachineName, * webApplicationPhysicalPath[0], * webApplicationPhysicalPath.Substring(2)); * * if (Directory.Exists(webApplicationNetworkPath)) * { * var backupFilesDeploymentStep = * new BackupFilesDeploymentStep( * webApplicationNetworkPath); * * AddSubTask(backupFilesDeploymentStep); * } * } */ // create a step for creating a WebDeploy package // TODO IMM HI: add possibility to specify physical path on the target machine var createWebDeployPackageDeploymentStep = new CreateWebDeployPackageDeploymentStep( _msDeploy, new Lazy <string>(() => extractArtifactsDeploymentStep.BinariesDirPath), webSiteName, webAppName); AddSubTask(createWebDeployPackageDeploymentStep); // create a step for deploying the WebDeploy package to the target machine var deployWebDeployPackageDeploymentStep = new DeployWebDeployPackageDeploymentStep( _msDeploy, webServerMachineName, new Lazy <string>(() => createWebDeployPackageDeploymentStep.PackageFilePath)); AddSubTask(deployWebDeployPackageDeploymentStep); // check if the app pool exists on the target machine if (_applicationConfiguration.CheckIfAppPoolExists && !_iisManager.AppPoolExists(webServerMachineName, appPoolInfo.Name)) { // create a step for creating a new app pool var createAppPoolDeploymentStep = new CreateAppPoolDeploymentStep( _iisManager, webServerMachineName, appPoolInfo); AddSubTask(createAppPoolDeploymentStep); // create a step for assigning the app pool to the web application var setAppPoolDeploymentStep = new SetAppPoolDeploymentStep( _iisManager, webServerMachineName, webSiteName, appPoolInfo, webAppName); AddSubTask(setAppPoolDeploymentStep); } } }