Esempio n. 1
0
        public void AddModule_WhenModuleIsNull_ThrowsArgumentNullException()
        {
            var pipeline = new DeploymentPipeline(_applicationConfigurationMock.Object, _objectFactoryMock.Object);

            Assert.Throws <ArgumentNullException>(() => pipeline.AddModule(null));
        }
Esempio n. 2
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);
        }