public StartupCheckResult Run()
        {
            if (this._mailSettings.SkipTest)
            {
                return(StartupCheckResult.Success("SkipTest is set - mail check is being skipped."));
            }

            if (this._mailSettings == null || this._mailSettings.Port == 0 || string.IsNullOrEmpty(this._mailSettings.FromAddress))
            {
                return(StartupCheckResult.Success("SMTP settings are not set"));
            }

            try
            {
                // Using MailKit we can simple connect and authenticate without sending mail
                using (SmtpClient smtpClient = this.CreateConnectedSmtpClient())
                {
                    smtpClient.NoOp();
                }
            }
            catch (Exception ex)
            {
                return(StartupCheckResult.Failure(
                           $"Unable to connect to SMTP server at {this._mailSettings.Host}:{this._mailSettings.Port}", ex));
            }

            return(StartupCheckResult.Success(
                       $"Connected to SMTP server at {this._mailSettings.Host}:{this._mailSettings.Port}"));
        }
        public override StartupCheckResult Run()
        {
            var connectionString = this.ConnectionString;

            if (string.IsNullOrEmpty(connectionString))
            {
                return(StartupCheckResult.Failure(
                           "Connection string is null or empty. Use configuration path 'Database' to configure the connection string."));
            }

            // Even if the database does not exist, connection to master should always succeed
            var connectionStringBuilder = new SqlConnectionStringBuilder(connectionString);

            var sw = new Stopwatch();

            sw.Start();

            try {
                var requiredPermissions = new HashSet <string>(new[] {
                    "ALTER",
                    "SELECT",
                    "INSERT",
                    "DELETE",
                    "UPDATE",
                    "EXECUTE"
                });

                using (var conn = new SqlConnection(connectionStringBuilder.ToString())) {
                    conn.Open();

                    var q = conn.Query(
                        @"SELECT permission_name AS PermissionName FROM fn_my_permissions(NULL, 'DATABASE') ORDER BY permission_name");
                    foreach (var item in q)
                    {
                        requiredPermissions.Remove(item.PermissionName);
                    }

                    if (requiredPermissions.Count > 0)
                    {
                        return(StartupCheckResult.Failure(
                                   $"Database {connectionStringBuilder.InitialCatalog} on {connectionStringBuilder.DataSource}: Missing permissions [{string.Join(",", requiredPermissions)}]",
                                   null));
                    }

                    conn.Close();
                }
            }
            catch (Exception ex) {
                return(StartupCheckResult.Failure(
                           $"Database does not appear to exist. Unable to connect to database {connectionStringBuilder.InitialCatalog} on {connectionStringBuilder.DataSource} using connection string: [{connectionStringBuilder}]",
                           ex));
            }
            finally {
                sw.Stop();
            }

            return(StartupCheckResult.Success(
                       $"Connected to {connectionStringBuilder.InitialCatalog} on {connectionStringBuilder.DataSource} in {sw.Elapsed:g}"));
        }
        public override StartupCheckResult Run()
        {
            var connectionString = this.ConnectionString;

            if (string.IsNullOrEmpty(connectionString))
            {
                return(StartupCheckResult.Failure(
                           $"Connection string is null or empty. Use configuration path 'Database' to configure the connection string."));
            }

            // Even if the database does not exist, connection to master should always succeed
            SqlConnectionStringBuilder connectionStringBuilder = new SqlConnectionStringBuilder(connectionString);

            connectionStringBuilder.InitialCatalog = "master";

            var sw = new Stopwatch();

            sw.Start();

            try {
                using (var conn = new SqlConnection(connectionStringBuilder.ToString())) {
                    conn.Open();

                    conn.Close();
                }
            }
            catch (Exception ex) {
                return(StartupCheckResult.Failure(
                           $"Unable to connect to database server {connectionStringBuilder.DataSource} using connection string: [{connectionStringBuilder}]",
                           ex));
            }
            finally {
                sw.Stop();
            }

            return(StartupCheckResult.Success($"Connected to {connectionStringBuilder.DataSource} in {sw.Elapsed:g}"));
        }