public CompositionTests() { // Load real configuration _configuration = new ConfigurationBuilder() .SetBasePath(Path.GetDirectoryName(typeof(Program).Assembly.Location)) .AddJsonFile("appsettings.json", false, true) .AddJsonFile("appsettings.Development.json", false, true) .Build(); // Build services var serviceCollection = new ServiceCollection(); var bootstrapperSettings = new BootstrapperSettings { EntryAssembly = typeof(Program).Assembly, EnvironmentName = "", UseDetailedErrors = true }; var hostingEnvironment = new FakeHostingEnvironment(); Composition.ConfigureServices(serviceCollection, hostingEnvironment, _configuration, bootstrapperSettings); // Add registrations that are performed by the WebHostStartup serviceCollection .AddSingleton <IHostingEnvironment>(hostingEnvironment) .AddSingleton(bootstrapperSettings) .AddMvc() .AddApplicationPart(typeof(DefaultController).Assembly) .AddControllersAsServices() .AddApplicationPart(typeof(Controllers.DefaultController).Assembly) .AddControllersAsServices(); // Build service provider _serviceProvider = serviceCollection.BuildServiceProvider(); }
public void BootSettings_DownloadDirFromEnvVars() { // 0. Setup TestLogger logger = new TestLogger(); // 1. Legacy TFS variable will be used if available using (EnvironmentVariableScope scope = new EnvironmentVariableScope()) { scope.SetVariable(BootstrapperSettings.BuildDirectory_Legacy, "legacy tf build"); scope.SetVariable(BootstrapperSettings.BuildDirectory_TFS2015, null); IBootstrapperSettings settings = new BootstrapperSettings(AnalysisPhase.PreProcessing, null, "http://sq", LoggerVerbosity.Debug, logger); AssertExpectedDownloadDir(Path.Combine("legacy tf build", DownloadFolderRelativePath), settings); } // 2. TFS2015 variable will be used if available using (EnvironmentVariableScope scope = new EnvironmentVariableScope()) { scope.SetVariable(BootstrapperSettings.BuildDirectory_Legacy, null); scope.SetVariable(BootstrapperSettings.BuildDirectory_TFS2015, "tfs build"); IBootstrapperSettings settings = new BootstrapperSettings(AnalysisPhase.PreProcessing, null, "http://sq", LoggerVerbosity.Debug, logger); AssertExpectedDownloadDir(Path.Combine("tfs build", DownloadFolderRelativePath), settings); } // 3. CWD has least precedence over env variables using (EnvironmentVariableScope scope = new EnvironmentVariableScope()) { scope.SetVariable(BootstrapperSettings.BuildDirectory_Legacy, null); scope.SetVariable(BootstrapperSettings.BuildDirectory_TFS2015, null); IBootstrapperSettings settings = new BootstrapperSettings(AnalysisPhase.PreProcessing, null, "http://sq", LoggerVerbosity.Debug, logger); AssertExpectedDownloadDir(Path.Combine(Directory.GetCurrentDirectory(), DownloadFolderRelativePath), settings); } }
public void BootSettings_PostProcessorPath() { // Check the default values, and that relative paths are turned into absolute paths // 0. Setup TestLogger logger = new TestLogger(); using (EnvironmentVariableScope envScope = new EnvironmentVariableScope()) { AppConfigWrapper configScope = new AppConfigWrapper(); envScope.SetVariable(BootstrapperSettings.SQAnalysisRootPath, @"c:\temp"); // 1. Default value -> relative to download dir IBootstrapperSettings settings = new BootstrapperSettings(logger, configScope.AppConfig); AssertExpectedPostProcessPath(@"c:\temp\sqtemp\bin\SonarQube.MSBuild.PostProcessor.exe", settings); // 2. Relative exe set in config -> relative to download dir configScope.SetPostProcessExe(@"..\foo\myCustomPreProcessor.exe"); settings = new BootstrapperSettings(logger, configScope.AppConfig); AssertExpectedPostProcessPath(@"c:\temp\sqtemp\foo\myCustomPreProcessor.exe", settings); // 3. Now set the config path to an absolute value configScope.SetPostProcessExe(@"d:\myCustomPostProcessor.exe"); settings = new BootstrapperSettings(logger, configScope.AppConfig); AssertExpectedPostProcessPath(@"d:\myCustomPostProcessor.exe", settings); } }
protected override IWebHostBuilder CreateWebHostBuilder() { var bootstrapperSettings = new BootstrapperSettings { EnvironmentName = EnvironmentName.Development, EntryAssembly = typeof(Bootstrapper).Assembly, UseDetailedErrors = true }; var configuration = Startup.Configuration.BuildConfiguration(bootstrapperSettings, Array.Empty <string>()); return(Bootstrapper.CreateWebHostBuilder(configuration, bootstrapperSettings)); }
public static void Initialize(IWindsorContainer container, BootstrapperSettings settings) { if (settings == null) { settings = new BootstrapperSettings(); } Settings = settings; PreventReInitialize(); Initialized = true; Container = container; switch (Settings.ORMFrameWork) { case ORMFrameWork.EntityFrameWok: { Container .Install(new SubsystemInstaller()) .Install(new DataAccessInstaller(), new ServicesInstaller()) .Register( Component.For <Database>().ImplementedBy(settings.DataBaseImplementation).LifeStyle.Singleton, Component.For <DataContext>().ImplementedBy(settings.EntityFramWorkInstallerImplementation).LifeStyle.Singleton ); } break; case ORMFrameWork.NHibernate: { Container .Install(new SubsystemInstaller()) .Install(new DataAccessInstaller(), new ServicesInstaller()) .AddFacility <AutoTxFacility>() .Register( Component.For <Database>().ImplementedBy(settings.DataBaseImplementation).LifeStyle.Singleton, Component.For <INHibernateInstaller>() .ImplementedBy(settings.NhibernateInstallerImplementation) .LifeStyle.Singleton ) .AddFacility <NHibernateFacility>(x => { x.FlushMode = settings.NHibernateFlushMode; x.DefaultLifeStyle = settings.NHibernateSessionLifeStyle; x.LifeStyleScoped = settings.NHibernateSessionLifeStyleScoped; }); } break; } RowMapper.Init(new InitRowMapParam { MapFileDirectory = PathHelper.BinPath() }); }
public void BootSettings_Properties() { // Check the properties values and that relative paths are turned into absolute paths var logger = new TestLogger(); using var envScope = new EnvironmentVariableScope(); envScope.SetVariable(BootstrapperSettings.BuildDirectory_Legacy, @"c:\temp"); // Default value -> relative to download dir var sut = new BootstrapperSettings(AnalysisPhase.PreProcessing, null, LoggerVerbosity.Debug, logger); sut.TempDirectory.Should().Be(@"c:\temp\.sonarqube"); }
public void BootSettings_Properties() { // Check the properties values and that relative paths are turned into absolute paths // 0. Setup var logger = new TestLogger(); using (var envScope = new EnvironmentVariableScope()) { envScope.SetVariable(BootstrapperSettings.BuildDirectory_Legacy, @"c:\temp"); // 1. Default value -> relative to download dir IBootstrapperSettings settings = new BootstrapperSettings(AnalysisPhase.PreProcessing, null, LoggerVerbosity.Debug, logger); } }
public void BootSettings_Properties() { // Check the properties values and that relative paths are turned into absolute paths // 0. Setup TestLogger logger = new TestLogger(); using (EnvironmentVariableScope envScope = new EnvironmentVariableScope()) { envScope.SetVariable(BootstrapperSettings.BuildDirectory_Legacy, @"c:\temp"); // 1. Default value -> relative to download dir IBootstrapperSettings settings = new BootstrapperSettings(AnalysisPhase.PreProcessing, null, "http://sq", LoggerVerbosity.Debug, logger); AssertExpectedServerUrl("http://sq", settings); AssertExpectedPreProcessPath(Path.Combine(@"c:\temp", DownloadFolderRelativePath, BootstrapperSettings.PreProcessorExeName), settings); AssertExpectedPostProcessPath(Path.Combine(@"c:\temp", DownloadFolderRelativePath, BootstrapperSettings.PostProcessorExeName), settings); } }
public void BootSettings_DownloadConfigOverridesEnvVars() { // 0. Setup TestLogger logger = new TestLogger(); using (EnvironmentVariableScope envScope = new EnvironmentVariableScope()) { AppConfigWrapper configScope = new AppConfigWrapper(); envScope.SetVariable(BootstrapperSettings.SQAnalysisRootPath, "env download dir"); configScope.SetDownloadDir("config download dir"); // 1. Check the config scope takes precedence IBootstrapperSettings settings = new BootstrapperSettings(logger, configScope.AppConfig); AssertExpectedDownloadDir(@"config download dir", settings); // 2. Now clear the config scope and check the env var is used configScope.Reset(); settings = new BootstrapperSettings(logger); AssertExpectedDownloadDir(@"env download dir\sqtemp\bin", settings); } }
public void BootSettings_DownloadDirFromEnvVars() { // 0. Setup TestLogger logger = new TestLogger(); // 1. Legacy TFS variable will be used if available using (EnvironmentVariableScope scope = new EnvironmentVariableScope()) { scope.SetVariable(BootstrapperSettings.SQAnalysisRootPath, null); scope.SetVariable(BootstrapperSettings.BuildDirectory_Legacy, "legacy tf build"); scope.SetVariable(BootstrapperSettings.BuildDirectory_TFS2015, null); IBootstrapperSettings settings = new BootstrapperSettings(logger); AssertExpectedDownloadDir(@"legacy tf build\sqtemp\bin", settings); } // 2. TFS2015 variable will be used if available using (EnvironmentVariableScope scope = new EnvironmentVariableScope()) { scope.SetVariable(BootstrapperSettings.SQAnalysisRootPath, null); scope.SetVariable(BootstrapperSettings.BuildDirectory_Legacy, null); scope.SetVariable(BootstrapperSettings.BuildDirectory_TFS2015, "tfs build"); IBootstrapperSettings settings = new BootstrapperSettings(logger); AssertExpectedDownloadDir(@"tfs build\sqtemp\bin", settings); } // 3. SQ variable takes precedence over the other variables using (EnvironmentVariableScope scope = new EnvironmentVariableScope()) { scope.SetVariable(BootstrapperSettings.SQAnalysisRootPath, "sq build"); scope.SetVariable(BootstrapperSettings.BuildDirectory_Legacy, "legacy tf build"); scope.SetVariable(BootstrapperSettings.BuildDirectory_TFS2015, "tfs build"); IBootstrapperSettings settings = new BootstrapperSettings(logger); AssertExpectedDownloadDir(@"sq build\sqtemp\bin", settings); } }
public void BootSettings_PreProcessorPath() { // 0. Setup TestLogger logger = new TestLogger(); AppConfigWrapper configScope = new AppConfigWrapper(); configScope.SetDownloadDir(@"c:\temp"); // 1. Default value -> relative to download dir IBootstrapperSettings settings = new BootstrapperSettings(logger, configScope.AppConfig); AssertExpectedPreProcessPath(@"c:\temp\SonarQube.MSBuild.PreProcessor.exe", settings); // 2. Relative exe set in config -> relative to download dir configScope.SetPreProcessExe(@"..\myCustomPreProcessor.exe"); settings = new BootstrapperSettings(logger, configScope.AppConfig); AssertExpectedPreProcessPath(@"c:\myCustomPreProcessor.exe", settings); // 3. Now set the config path to an absolute value configScope.SetPreProcessExe(@"d:\myCustomPreProcessor.exe"); settings = new BootstrapperSettings(logger, configScope.AppConfig); AssertExpectedPreProcessPath(@"d:\myCustomPreProcessor.exe", settings); }
public void BootSettings_ConfigOverridesPropertiesFile_Url() { // 0. Setup TestLogger logger = new TestLogger(); using (EnvironmentVariableScope envScope = new EnvironmentVariableScope()) { string runnerBinDir = CreateSonarRunnerFiles("http://envUrl"); envScope.SetPath(runnerBinDir); // so the properties file can be found AppConfigWrapper configScope = new AppConfigWrapper(); configScope.SetSonarQubeUrl("http://configUrl"); // 1. Check the config scope takes precedence IBootstrapperSettings settings = new BootstrapperSettings(logger, configScope.AppConfig); AssertExpectedServerUrl(@"http://configUrl", settings); // 2. Now clear the config scope and check the env var is used configScope.Reset(); settings = new BootstrapperSettings(logger); AssertExpectedServerUrl(@"http://envUrl", settings); } }
public static void Initialize(BootstrapperSettings settings) { Initialize(new WindsorContainer(), settings); }
public static BasedOnDescriptor ApplyLifeStyle(this BasedOnDescriptor lifeStyle, BootstrapperSettings settings) { if (settings.Platform == Platform.Web) { return(lifeStyle.LifestylePerWebRequest()); } return(lifeStyle.LifestyleSingleton()); }