public void RabbitmqCheck() { IConfigurationRoot Configuration = new ConfigurationBuilder() .AddJsonFile("appsettings.json") .Build(); ServiceCollection sc = new ServiceCollection(); sc.AddSingleton <IConfiguration>(Configuration); sc.AddOptions(); sc.Configure <DependencyCheckerOptions>(Configuration.GetSection("DependencyCheck")); IServiceProvider services = sc.BuildServiceProvider(); IOptions <DependencyCheckerOptions> options = services.GetRequiredService <IOptions <DependencyCheckerOptions> >(); DependencyCheckerOptions result = options.Value; RabbitMqDependencyCheckOptions opt1 = result.GetCheckParameter <RabbitMqDependencyCheckOptions>("rabbit"); var check = new RabbitMqDependencyChecker( new ConnectionFactory() { Uri = new Uri(Configuration.GetConnectionString(opt1.ConnectionStringName)) }, "test", TimeSpan.FromSeconds(10)); Assert.False(check.Check()); }
public void Configuration() { IConfigurationRoot Configuration = new ConfigurationBuilder() .AddJsonFile("appsettings.json") .Build(); ServiceCollection sc = new ServiceCollection(); sc.AddSingleton <IConfiguration>(Configuration); sc.AddOptions(); sc.Configure <DependencyCheckerOptions>(Configuration.GetSection("DependencyCheck")); IServiceProvider services = sc.BuildServiceProvider(); IOptions <DependencyCheckerOptions> options = services.GetRequiredService <IOptions <DependencyCheckerOptions> >(); DependencyCheckerOptions result = options.Value; EFDependencyCheckOptions opt = result.GetCheckParameter <EFDependencyCheckOptions>("test"); RabbitMqDependencyCheckOptions opt1 = result.GetCheckParameter <RabbitMqDependencyCheckOptions>("rabbit"); MongoDependencyCheckOptions opt2 = result.GetCheckParameter <MongoDependencyCheckOptions>("mongo"); }