public void StartDeployment_WhenDeploymentTaskIsNull_ThrowsArgumentNullException()
        {
            var environmentInfoRepositoryFake = new Mock<IEnvironmentInfoRepository>(MockBehavior.Loose);

              var pipeline = new DeploymentPipeline();

              Assert.Throws<ArgumentNullException>(() => pipeline.StartDeployment(null, new DeploymentContext("requester")));
              Assert.Throws<ArgumentNullException>(() => pipeline.StartDeployment(new DummyDeploymentTask(environmentInfoRepositoryFake.Object, "env"), null));
        }
        public void StartDeployment_WhenDeploymentTaskIsNull_ThrowsArgumentNullException()
        {
            var projectInfoRepositoryFake = new Mock<IProjectInfoRepository>(MockBehavior.Loose);
              var environmentInfoRepositoryFake = new Mock<IEnvironmentInfoRepository>(MockBehavior.Loose);

              var pipeline = new DeploymentPipeline();

              var deploymentInfo = DeploymentInfoGenerator.GetNtServiceDeploymentInfo();

              Assert.Throws<ArgumentNullException>(() => pipeline.StartDeployment(null, new DummyDeploymentTask(projectInfoRepositoryFake.Object, environmentInfoRepositoryFake.Object), new DeploymentContext("requester")));
              Assert.Throws<ArgumentNullException>(() => pipeline.StartDeployment(deploymentInfo, null, new DeploymentContext("requester")));
              Assert.Throws<ArgumentNullException>(() => pipeline.StartDeployment(deploymentInfo, new DummyDeploymentTask(projectInfoRepositoryFake.Object, environmentInfoRepositoryFake.Object), null));
        }
        public static void Bootstrap()
        {
            var container = ObjectFactory.Container;

              container.Register(
            Component.For<IApplicationConfiguration>()
              .UsingFactoryMethod(() => new XmlApplicationConfiguration(_ApplicationConfigPath))
              .LifeStyle.Singleton,
            Component.For<IProjectInfoRepository>()
              .UsingFactoryMethod(() => new XmlProjectInfoRepository(_ProjectInfoPath))
              .LifeStyle.Singleton,
            Component.For<IEnvironmentInfoRepository>()
              .UsingFactoryMethod(() => new XmlEnvironmentInfoRepository(_EnvironmentInfoPath))
              .LifeStyle.Singleton);

              container.Register(
            Component.For<IDirectoryAdapter>()
              .ImplementedBy<DirectoryAdapter>()
              .LifeStyle.Is(LifestyleType.Transient));

              container.Register(
            Component.For<ITeamCityClient>()
              .UsingFactoryMethod(
            () =>
              {
                var appConfig = container.Resolve<IApplicationConfiguration>();

                return new TeamCityClient(
                  appConfig.TeamCityHostName,
                  appConfig.TeamCityPort,
                  appConfig.TeamCityUserName,
                  appConfig.TeamCityPassword);
              })
              .LifeStyle.Transient);

              container.Register(
            Component.For<IArtifactsRepository>()
              .UsingFactoryMethod(() => new TeamCityArtifactsRepository(container.Resolve<ITeamCityClient>()))
              .LifeStyle.Transient);

              container.Register(
            Component.For<IDeploymentRequestRepository>()
              .UsingFactoryMethod(() => new NHibernateDeploymentRequestRepository(SessionFactory))
              .LifeStyle.Transient);

              container.Register(
            Component.For<INtServiceManager>()
              .UsingFactoryMethod(
            () =>
              {
                var appConfig = container.Resolve<IApplicationConfiguration>();

                return
                  new ScExeBasedNtServiceManager(
                    appConfig.ScExePath,
                    _NtServiceManagerOperationsTimeout);
              })
              .LifeStyle.Transient);

              container.Register(
            Component.For<ITaskScheduler>()
             .ImplementedBy<TaskScheduler>()
             .LifeStyle.Transient);

              // TODO IMM HI: config?
              container.Register(
            Component.For<IMsDeploy>()
              .UsingFactoryMethod(() => new MsDeploy(Path.Combine(_BaseDirPath, "msdeploy.exe")))
              .LifeStyle.Transient);

              // TODO IMM HI: config?
              container.Register(
            Component.For<IIisManager>()
              .UsingFactoryMethod(() => new MsDeployBasedIisManager(container.Resolve<IMsDeploy>()))
              .LifeStyle.Transient);

              // TODO IMM HI: config?
              container.Register(
            Component.For<IDeploymentPipeline>()
              .UsingFactoryMethod(
            () =>
              {
                var deploymentRequestRepository = container.Resolve<IDeploymentRequestRepository>();
                var auditingModule = new AuditingModule(deploymentRequestRepository);
                var enforceTargetEnvironmentConstraintsModule = new EnforceTargetEnvironmentConstraintsModule();
                var deploymentPipeline = new DeploymentPipeline();

                deploymentPipeline.AddModule(auditingModule);
                deploymentPipeline.AddModule(enforceTargetEnvironmentConstraintsModule);

                return deploymentPipeline;
              })
              .LifeStyle.Transient);

              container.Register(
            Component.For<IDbVersionProvider>()
              .UsingFactoryMethod(
            () =>
              {
                IEnumerable<DbVersionTableInfo> versionTableInfos =
                  new List<DbVersionTableInfo>
                    {
                      new DbVersionTableInfo
                        {
                          TableName = "VERSION",
                          ColumnName = "dbVersion"
                        },
                      new DbVersionTableInfo
                        {
                          TableName = "VERSIONHISTORY",
                          ColumnName = "DBLabel"
                        }
                    };

                return new DbVersionProvider(versionTableInfos);
              })
              .LifeStyle.Transient);

              container.Register(
            Component.For<IProjectMetadataExplorer>()
              .ImplementedBy<ProjectMetadataExplorer>()
              .LifeStyle.Is(LifestyleType.Transient));

              container.Register(
            Component.For<IDirPathParamsResolver>()
              .UsingFactoryMethod(
            () =>
              {
                var appConfig = container.Resolve<IApplicationConfiguration>();
                return new DirPathParamsResolver(appConfig.ManualDeploymentPackageCurrentDateFormat);
              })
              .LifeStyle.Is(LifestyleType.Transient));
        }
        public void AddModule_WhenModuleIsNull_ThrowsArgumentNullException()
        {
            var pipeline = new DeploymentPipeline();

              Assert.Throws<ArgumentNullException>(() => pipeline.AddModule(null));
        }
        public void AddModule_WhenModuleIsNull_ThrowsArgumentNullException()
        {
            var pipeline = new DeploymentPipeline(_applicationConfigurationMock.Object, _objectFactoryMock.Object);

              Assert.Throws<ArgumentNullException>(() => pipeline.AddModule(null));
        }
示例#6
0
        public static void Bootstrap(bool mockTeamCity = false)
        {
            var container = ObjectFactory.Container;

              container.Register(
            Component.For<IApplicationConfigurationRepository>()
              .UsingFactoryMethod(() => new XmlApplicationConfigurationRepository(_ApplicationConfigPath))
              .LifeStyle.Transient,

            Component.For<IApplicationConfiguration>()
              .UsingFactoryMethod((kernel) => kernel.Resolve<IApplicationConfigurationRepository>().LoadConfiguration())
              .LifeStyle.Singleton,

            Component.For<IProjectInfoRepository>()
              .UsingFactoryMethod(() => new XmlProjectInfoRepository(_ProjectInfosFilePath))
              .LifeStyle.Singleton,

            Component.For<IEnvironmentInfoRepository>()
              .UsingFactoryMethod(() => new XmlEnvironmentInfoRepository(_EnvironmentInfosDirPath))
              .LifeStyle.Singleton,

            Component.For<IEnvironmentDeployInfoRepository>()
              .UsingFactoryMethod(() => new JsonEnvironmentDeployInfoRepository(_EnvironmentDeployInfosDirPath))
              .LifeStyle.Singleton);

              container.Register(
            Component.For<IDirectoryAdapter>()
              .ImplementedBy<DirectoryAdapter>()
              .LifeStyle.Is(LifestyleType.Transient));

              container.Register(
            Component.For<ITeamCityClient>()
              .UsingFactoryMethod(
            () =>
            {
              var appConfig = container.Resolve<IApplicationConfiguration>();

              var client = new TeamCityClient(
                appConfig.TeamCityHostName,
                appConfig.TeamCityPort,
                appConfig.TeamCityUserName,
                appConfig.TeamCityPassword);

              container.Release(appConfig);

              return client;
            })
              .LifeStyle.Transient);

              container.Register(
            Component.For<ITeamCityRestClient>()
              .UsingFactoryMethod(
            () =>
            {
              var appConfig = container.Resolve<IApplicationConfiguration>();

              ITeamCityRestClient restClient;
              if (mockTeamCity)
              {
                restClient = new MockedTeamCityRestClient();
              }
              else
              {
                restClient = new TeamCityRestClient(
                  new Uri(string.Format("http://{0}:{1}", appConfig.TeamCityHostName, appConfig.TeamCityPort)),
                  appConfig.TeamCityUserName,
                  appConfig.TeamCityPassword);
              }

              container.Release(appConfig);

              return restClient;
            })
              .LifeStyle.Transient);

              container.Register(
            Component.For<IArtifactsRepository>().ImplementedBy<TeamCityArtifactsRepository>()
              .LifeStyle.Transient);

              container.Register(
            Component.For<IDeploymentRequestRepository>()
              .UsingFactoryMethod(() => new NHibernateDeploymentRequestRepository(SessionFactory))
              .LifeStyle.Transient);

              container.Register(
            Component.For<INtServiceManager>()
              .UsingFactoryMethod(
            () =>
            {
              var appConfig = container.Resolve<IApplicationConfiguration>();

              return
                new ScExeBasedNtServiceManager(
                  appConfig.ScExePath,
                  _NtServiceManagerOperationsTimeout);
            })
              .LifeStyle.Transient);

              container.Register(
            Component.For<ITaskScheduler>()
             .ImplementedBy<TaskScheduler>()
             .LifeStyle.Transient);

              // TODO IMM HI: config?
              container.Register(
            Component.For<IMsDeploy>()
              .UsingFactoryMethod(() => new MsDeploy(Path.Combine(_BaseDirPath, "msdeploy.exe")))
              .LifeStyle.Transient);

              // TODO IMM HI: config?
              container.Register(
            Component.For<IIisManager>()
              .UsingFactoryMethod(() => new MsDeployBasedIisManager(container.Resolve<IMsDeploy>()))
              .LifeStyle.Transient);

              // TODO IMM HI: config?
              container.Register(
            Component.For<IDeploymentPipeline>()
              .UsingFactoryMethod(
            () =>
            {
              var deploymentRequestRepository = container.Resolve<IDeploymentRequestRepository>();
              var applicationConfiguration = container.Resolve<IApplicationConfiguration>();
              var auditingModule = new AuditingModule(deploymentRequestRepository);
              var enforceTargetEnvironmentConstraintsModule = new EnforceTargetEnvironmentConstraintsModule();
              var deploymentPipeline = new DeploymentPipeline(applicationConfiguration, ObjectFactory.Instance);

              deploymentPipeline.AddModule(auditingModule);
              deploymentPipeline.AddModule(enforceTargetEnvironmentConstraintsModule);

              return deploymentPipeline;
            })
              .LifeStyle.Transient);

              container.Register(
            Component.For<IEnvDeploymentPipeline>()
              .ImplementedBy<EnvDeploymentPipeline>()
              .LifeStyle.Transient);

              container.Register(
            Component.For<IDbManagerFactory>()
              .ImplementedBy<MsSqlDbManagerFactory>()
              .LifeStyle.Transient);

              container.Register(
            Component.For<IMsSqlDatabasePublisher>()
              .UsingFactoryMethod(
            kernel =>
            {
              var applicationConfiguration = kernel.Resolve<IApplicationConfiguration>();
              var cmdExecutor = kernel.Resolve<ICmdExecutor>();

              return new MsSqlDatabasePublisher(cmdExecutor, applicationConfiguration.SqlPackageDirPath);
            })
              .LifeStyle.Transient);

              container.Register(
            Component.For<ICmdExecutor>()
              .ImplementedBy<CmdExecutor>()
              .LifeStyle.Transient);

              container.Register(
            Component.For<IDbVersionProvider>()
              .UsingFactoryMethod(
            () =>
            {
              // order is important - from more specific to less
              IEnumerable<DbVersionTableInfo> versionTableInfos =
                new List<DbVersionTableInfo>
                    {
                      new DbVersionTableInfo
                        {
                          TableName = "VERSION",
                          VersionColumnName = "dbVersion",
                          MigrationColumnName = "migrated"
                        },
                      new DbVersionTableInfo
                        {
                          TableName = "VERSION",
                          VersionColumnName = "dbVersion"
                        },
                      new DbVersionTableInfo
                        {
                          TableName = "VERSIONHISTORY",
                          VersionColumnName = "DBLabel"
                        }
                    };

              return new DbVersionProvider(versionTableInfos);
            })
              .LifeStyle.Transient);

              container.Register(
            Component.For<IProjectMetadataExplorer>()
              .ImplementedBy<ProjectMetadataExplorer>()
              .LifeStyle.Is(LifestyleType.Transient));

              container.Register(
            Component.For<IDirPathParamsResolver>()
              .UsingFactoryMethod(
            () =>
            {
              var appConfig = container.Resolve<IApplicationConfiguration>();
              return new DirPathParamsResolver(appConfig.ManualDeploymentPackageCurrentDateFormat);
            })
              .LifeStyle.Is(LifestyleType.Transient));

              container.Register(
            Component.For<IDbScriptRunnerFactory>()
              .ImplementedBy<MsSqlDbScriptRunnerFactory>()
              .LifeStyle.Is(LifestyleType.Transient));

              container.Register(
            Component.For<IUserNameNormalizer>()
              .ImplementedBy<UserNameNormalizer>()
              .LifeStyle.Transient);
        }