Webiant Logo Webiant Logo
  1. No results found.

    Try your search with a different keyword or use * as a wildcard.

TestSmtpBuilder.cs

using MailKit;
using MailKit.Net.Smtp;
using MimeKit;
using Nop.Core.Domain.Messages;
using Nop.Core.Infrastructure;
using Nop.Services.Localization;
using Nop.Services.Messages;

namespace Nop.Tests;

public class TestSmtpBuilder : SmtpBuilder
{
    public TestSmtpBuilder(EmailAccountSettings emailAccountSettings, 
        IEmailAccountService emailAccountService,
        ILocalizationService localizationService,
        INopFileProvider fileProvider) : base(emailAccountSettings, emailAccountService, localizationService, fileProvider)
    {
    }

    public override Task BuildAsync(EmailAccount emailAccount = null)
    {
        return Task.FromResult(new TestSmtpClient());
    }

    public class TestSmtpClient : SmtpClient
    {
        public override Task SendAsync(MimeMessage message,
            CancellationToken cancellationToken = default,
            ITransferProgress progress = null)
        {
            MessageIsSent = true;
            return Task.FromResult(string.Empty);
        }

        public static bool MessageIsSent { get; set; }
    }
}