Пример #1
0
        public void MongoCheck()
        {
            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;
            MongoDependencyCheckOptions opt2   = result.GetCheckParameter <MongoDependencyCheckOptions>("mongo");

            var mongoUrl            = new MongoUrl(Configuration.GetConnectionString(opt2.ConnectionStringName));
            var mongoClientSettings = MongoClientSettings.FromUrl(mongoUrl);

            var check = new MongoDependencyChecker(
                new MongoClient(mongoClientSettings), "test", TimeSpan.FromSeconds(10));

            Assert.False(check.Check());
        }
Пример #2
0
        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");
        }