< Summary

Information
Class: MyNet.Mail.Mock.MockMailService
Assembly: MyNet.Mail
File(s): https://raw.githubusercontent.com/sandre58/MyNet/5aaaab311aa14541478b9e402357d98b657a23e4/src/MyNet.Mail/Mock/MockMailService.cs
Tag: 342_31701152804
Line coverage
63%
Covered lines: 14
Uncovered lines: 8
Coverable lines: 22
Total lines: 65
Line coverage: 63.6%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
CanConnect()100%11100%
CanConnectAsync()100%11100%
Send(...)0%2260%
SendAsync()0%2260%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/5aaaab311aa14541478b9e402357d98b657a23e4/src/MyNet.Mail/Mock/MockMailService.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="MockMailService.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using System.Threading;
 9using System.Threading.Tasks;
 10using Microsoft.Extensions.Logging;
 11using MyNet.Mail.Models;
 12using MyNet.Primitives;
 13
 14namespace MyNet.Mail.Mock;
 15
 16public partial class MockMailService(ILogger? logger = null) : IMailService
 17{
 18    [LoggerMessage(LogLevel.Information, "Simulate Sending Mail : {email}")]
 19    public static partial void LogSendingMail(ILogger logger, string email);
 20
 321    public bool CanConnect() => true;
 22
 323    public Task<bool> CanConnectAsync() => Task.FromResult(true);
 24
 25    public SendResponse Send(IEmail email, CancellationToken? token = null)
 26    {
 327        var response = new SendResponse();
 28
 29        try
 30        {
 331            Task.Delay(1000, token.GetValueOrDefault()).GetAwaiter().GetResult();
 032        }
 333        catch (OperationCanceledException)
 34        {
 335            response.ErrorMessages.Add("Send canceled.");
 336            return response;
 37        }
 38
 039        if (logger is not null)
 040            LogSendingMail(logger, email.ToString().OrEmpty());
 41
 042        return response;
 343    }
 44
 45    public async Task<SendResponse> SendAsync(IEmail email, CancellationToken? token = null)
 46    {
 347        var response = new SendResponse();
 48
 49        try
 50        {
 351            await Task.Delay(1000, token.GetValueOrDefault()).ConfigureAwait(false);
 052        }
 353        catch (OperationCanceledException)
 54        {
 355            response.ErrorMessages.Add("Send canceled.");
 356            return response;
 57        }
 58
 059        if (logger is not null)
 060            LogSendingMail(logger, email.ToString().OrEmpty());
 61
 062        return response;
 363    }
 64}
 65