コード例 #1
0
        /// <summary>
        /// Add a health check for network FTP.
        /// </summary>
        /// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param>
        /// <param name="setup">The action to configure the FTP connection parameters.</param>
        /// <param name="name">The health check name. Optional. If <c>null</c> the type name 'ftp' will be used for the name.</param>
        /// <param name="failureStatus">
        /// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then
        /// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported.
        /// </param>
        /// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param>
        /// <returns>The <see cref="IHealthChecksBuilder"/>.</returns></param>
        public static IHealthChecksBuilder AddFtpHealthCheck(this IHealthChecksBuilder builder, Action <FtpHealthCheckOptions> setup, string name = default, HealthStatus?failureStatus = default, IEnumerable <string> tags = default)
        {
            var options = new FtpHealthCheckOptions();

            setup?.Invoke(options);

            return(builder.Add(new HealthCheckRegistration(
                                   name ?? FTP_NAME,
                                   sp => new FtpHealthCheck(options),
                                   failureStatus,
                                   tags)));
        }
        public async Task respect_configured_timeout_and_throw_operation_cancelled_exception()
        {
            var options = new FtpHealthCheckOptions();

            options.AddHost("ftp://invalid:21");
            var ftpHealthCheck = new FtpHealthCheck(options);

            var result = await ftpHealthCheck.CheckHealthAsync(new HealthCheckContext
            {
                Registration = new HealthCheckRegistration("ftp", instance: ftpHealthCheck, failureStatus: HealthStatus.Degraded,
                                                           null, timeout: null)
            }, new CancellationTokenSource(TimeSpan.FromSeconds(2)).Token);

            result.Exception.Should().BeOfType <OperationCanceledException>();
        }