< Summary

Information
Class: Services.EmailRoutingServices.FileDeduplicationService
Assembly: Services
File(s): /home/runner/work/Studio2Prod/Studio2Prod/AppRepository/EmailRoutingServices/FileDeduplicationService.cs
Line coverage
100%
Covered lines: 15
Uncovered lines: 0
Coverable lines: 15
Total lines: 34
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
ComputeSha256(...)100%11100%
IsDuplicateAsync(...)100%11100%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/AppRepository/EmailRoutingServices/FileDeduplicationService.cs

#LineLine coverage
 1using System.Security.Cryptography;
 2using Microsoft.EntityFrameworkCore;
 3using OzonRepositories.Context;
 4
 5namespace Services.EmailRoutingServices;
 6
 7public class FileDeduplicationService : IFileDeduplicationService
 8{
 9    private readonly ApplicationDbContext _context;
 10
 911    public FileDeduplicationService(ApplicationDbContext context)
 12    {
 913        _context = context;
 914    }
 15
 16    public string ComputeSha256(byte[] bytes)
 17    {
 818        using var sha = SHA256.Create();
 819        var hash = sha.ComputeHash(bytes);
 820        return Convert.ToHexString(hash).ToLowerInvariant();
 821    }
 22
 23    public Task<bool> IsDuplicateAsync(string messageExternalId, string hash, string fileName, long fileSizeBytes)
 24    {
 525        return _context.EmailAttachmentInboxes
 526            .Include(x => x.EmailMessage)
 527            .AnyAsync(x =>
 528                x.EmailMessage != null &&
 529                x.EmailMessage.MessageExternalId == messageExternalId &&
 530                x.Sha256Hash == hash &&
 531                x.FileName == fileName &&
 532                x.FileSizeBytes == fileSizeBytes);
 33    }
 34}