Example #1
0
        /// <summary>
        /// Add a health check for network IMAP connections.
        /// </summary>
        /// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param>
        /// <param name="setup">The action to configure IMAP connection parameters.</param>
        /// <param name="name">The health check name. Optional. If <c>null</c> the type name 'imap' 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 AddImapHealthCheck(this IHealthChecksBuilder builder, Action <ImapHealthCheckOptions> setup, string name = default, HealthStatus?failureStatus = default, IEnumerable <string> tags = default)
        {
            var options = new ImapHealthCheckOptions();

            setup?.Invoke(options);

            return(builder.Add(new HealthCheckRegistration(
                                   name ?? IMAP_NAME,
                                   sp => new ImapHealthCheck(options),
                                   failureStatus,
                                   tags)));
        }
        public async Task respect_configured_timeout_and_throw_operation_cancelled_exception()
        {
            var options = new ImapHealthCheckOptions()
            {
                Host = "invalid", Port = 993
            };

            options.LoginWith("user", "pass");

            var imapHealthCheck = new ImapHealthCheck(options);

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

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