public void Should_Fail_On_Validation() { var host = new HostBuilder() .ConfigureAppConfiguration((hostContext, configApp) => { configApp.SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", false, true) .AddEnvironmentVariables(); }) .ConfigureServices((hostContext, services) => { // Adding configuration and services services.AddTransient <IValidator, ConfigurationsValidator>(); services.AddOptions(); var exporterConf = new ClusterExporterConfiguration() { ClusterName = string.Empty, }; var mockOptions = new Mock <IOptions <ClusterExporterConfiguration> >(); mockOptions.Setup(f => f.Value).Returns(exporterConf); services.AddSingleton <IValidatableConfiguration>(mockOptions.Object.Value); }) .UseConsoleLifetime() .Build(); Func <Task> func = async() => { await host.ValidateConfigurationAsync(); }; func.Should().Throw <Exception>(); }
public LivenessHostedService( IContentProvider contentProvider, IOptions <ClusterExporterConfiguration> clusterExporterConfiguration, IOptions <LivenessConfiguration> configuration, ILogger <LivenessHostedService> logger) { _contentProvider = contentProvider; _clusterExporterConfiguration = clusterExporterConfiguration.Value; _configuration = configuration.Value; _logger = logger; }
public ClusterExporter( IContentProvider contentProvider, IPrometheusUtils prometheusUtils, IOptions <ClusterExporterConfiguration> exporterConfiguration, IOptions <HostExporterConfiguration> hostExporterConfiguration, ILogger <ClusterExporter> logger) : base(contentProvider, prometheusUtils, exporterConfiguration.Value, typeof(ClusterComponent), logger) { _clusterConfiguration = exporterConfiguration.Value; _hostExporter = new HostExporter(contentProvider, prometheusUtils, hostExporterConfiguration, logger); }
public LivenessHostedServiceTests() { _contentProvider = new Mock <IContentProvider>(); var clusterExporterConfiguration = new ClusterExporterConfiguration { AmbariServerUri = string.Empty }; _clusterExporterConfiguration = new Mock <IOptions <ClusterExporterConfiguration> >(); _clusterExporterConfiguration.Setup(f => f.Value).Returns(clusterExporterConfiguration); _logger = new Mock <ILogger <LivenessHostedService> >(); }
public void Validate_Attributes_Should_Pass(ClusterExporterConfiguration conf, bool expectedResult) { try { conf.Validate(); } catch (Exception e) { if (expectedResult) { throw; } e.Should().BeOfType <AggregateException>(); } }