< Summary

Information
Class: MyNet.Mail.MailKit.MailKitSmtpOptionsValidator
Assembly: MyNet.Mail.MailKit
File(s): https://raw.githubusercontent.com/sandre58/MyNet/5aaaab311aa14541478b9e402357d98b657a23e4/src/MyNet.Mail.MailKit/MailKitSmtpOptionsValidator.cs
Tag: 342_31701152804
Line coverage
100%
Covered lines: 15
Uncovered lines: 0
Coverable lines: 15
Total lines: 54
Line coverage: 100%
Branch coverage
94%
Covered branches: 17
Total branches: 18
Branch coverage: 94.4%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Validate(...)94.44%1818100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/5aaaab311aa14541478b9e402357d98b657a23e4/src/MyNet.Mail.MailKit/MailKitSmtpOptionsValidator.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="MailKitSmtpOptionsValidator.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using MyNet.Mail.MailKit.Exceptions;
 9using MyNet.Mail.Smtp;
 10
 11namespace MyNet.Mail.MailKit;
 12
 13/// <summary>
 14/// Validates <see cref="SmtpClientOptions"/> before connecting or sending mail.
 15/// </summary>
 16public static class MailKitSmtpOptionsValidator
 17{
 18    /// <summary>
 19    /// Validates SMTP client options and throws if configuration is invalid.
 20    /// </summary>
 21    public static void Validate(SmtpClientOptions options)
 22    {
 3323        ArgumentNullException.ThrowIfNull(options);
 24
 3325        if (options.UsePickupDirectory)
 26        {
 1827            if (string.IsNullOrWhiteSpace(options.MailPickupDirectory))
 28            {
 329                throw new ArgumentException("Pickup directory must be defined when UsePickupDirectory is enabled.");
 30            }
 31
 1532            return;
 33        }
 34
 1535        if (string.IsNullOrWhiteSpace(options.Server))
 36        {
 337            throw new UndefinedServerException();
 38        }
 39
 1240        if (options.Port is < 1 or > 65535)
 41        {
 342            throw new ArgumentOutOfRangeException(nameof(options), options.Port, "SMTP port must be between 1 and 65535.
 43        }
 44
 945        switch (options.RequiresAuthentication)
 46        {
 947            case true when string.IsNullOrWhiteSpace(options.User):
 348                throw new ArgumentException("SMTP user must be defined when authentication is required.");
 649            case true when options.Password is null:
 350                throw new ArgumentException("SMTP password must be defined when authentication is required.");
 51        }
 352    }
 53}
 54