Пример #1
0
        public void AddSqlDbStoredProcedureMonitor_Ok(bool isCritical)
        {
            // ARRANGE
            var options = new MonitoringOptions();
            var dbConnectionProvider = Substitute.For <IDbConnectionProvider>();
            var configuration        = Substitute.For <IResourceMonitorConfiguration>();
            var serviceProvider      = Substitute.For <IServiceProvider>();
            var logger = Substitute.For <ILogger <SqlDbStoredProcedureMonitor> >();

            serviceProvider.GetService(typeof(ILogger <SqlDbStoredProcedureMonitor>)).Returns(logger);

            // ACT
            options.AddSqlDbStoredProcedureMonitor(dbConnectionProvider, "schema", "storedProcedureName", "resource", isCritical, configuration);

            // ASSERT
            var factories = options.Factories.ToList();

            Assert.Single(factories);
            var factory = factories.Single();
            var monitor = factory(configuration, serviceProvider);

            Assert.IsType <SqlDbStoredProcedureMonitor>(monitor);
            var sqlMonitor = (SqlDbStoredProcedureMonitor)monitor;

            Assert.Equal("resource", sqlMonitor.ResourceName);
            Assert.Equal(configuration, sqlMonitor.Configuration);
            Assert.Equal(isCritical, sqlMonitor.IsCritical);
        }
Пример #2
0
        public void AddSqlDbStoredProcedureMonitor2_Ok(bool isCritical)
        {
            // ARRANGE
            var options         = new MonitoringOptions();
            var serviceProvider = Substitute.For <IServiceProvider>();
            var logger          = Substitute.For <ILogger <SqlDbStoredProcedureMonitor> >();

            serviceProvider.GetService(typeof(ILogger <SqlDbStoredProcedureMonitor>)).Returns(logger);

            // ACT
            options.AddSqlDbStoredProcedureMonitor("Application Name=Bar;Data Source=dev-db;Initial Catalog=db_name;UID=baz_user;PWD=123456", "schema", "storedProcedureName", isCritical: isCritical);

            // ASSERT
            var factories = options.Factories.ToList();

            Assert.Single(factories);
            var factory = factories.Single();
            var monitor = factory(options, serviceProvider);

            Assert.IsType <SqlDbStoredProcedureMonitor>(monitor);
            var sqlMonitor = (SqlDbStoredProcedureMonitor)monitor;

            Assert.Equal("db_name.schema", sqlMonitor.ResourceName);
            Assert.Equal(options, sqlMonitor.Configuration);
            Assert.Equal(isCritical, sqlMonitor.IsCritical);
        }
Пример #3
0
 /// <summary>
 /// Adds the SQL database stored procedure monitor to MonitoringOptions
 /// </summary>
 /// <param name="options">The options.</param>
 /// <param name="dbConnectionString">Database connection string.</param>
 /// <param name="schema">DB schema monitored.</param>
 /// <param name="storedProcedureName">Healthcheck stored procedure name (without schema).</param>
 /// <param name="resourceName">Name of the resource.</param>
 /// <param name="isCritical">if set to <c>true</c> [is critical].</param>
 /// <param name="configOverride">The configuration override.</param>
 public static void AddSqlDbStoredProcedureMonitor(
     this MonitoringOptions options,
     string dbConnectionString,
     string schema,
     string storedProcedureName,
     string resourceName = null,
     bool isCritical     = true,
     IResourceMonitorConfiguration configOverride = null)
 {
     options.AddSqlDbStoredProcedureMonitor(
         new DbConnectionProvider(dbConnectionString),
         schema,
         storedProcedureName,
         resourceName ?? DbSchemaResourceName(dbConnectionString, schema),
         isCritical,
         configOverride);
 }