• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lucaslorentz / minicover / #156

pending completion
#156

push

azure-devops

web-flow
Merge 64be0ef38 into c4f476c4c

6 of 6 new or added lines in 1 file covered. (100.0%)

902 of 2589 relevant lines covered (34.84%)

7672.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/MiniCover.Core/Extensions/DocumentExtensions.cs
1
using System.IO;
2
using System.Linq;
3
using System.Security.Cryptography;
4
using Mono.Cecil.Cil;
5

6
namespace MiniCover.Core.Extensions
7
{
8
    public static class DocumentExtensions
9
    {
10
        public static bool FileHasChanged(this Document document)
11
        {
12
            if (!File.Exists(document.Url))
×
13
                return true;
×
14

15
            using (var stream = File.OpenRead(document.Url))
×
16
            {
17
                var hasher = CreateHashAlgorithm(document.HashAlgorithm);
×
18

19
                if (hasher == null)
×
20
                    return false;
×
21

22
                using (hasher)
×
23
                {
24
                    var newHash = hasher.ComputeHash(stream);
×
25
                    return !newHash.SequenceEqual(document.Hash);
×
26
                }
27
            }
28
        }
29

30
        private static HashAlgorithm CreateHashAlgorithm(DocumentHashAlgorithm algorithm)
31
        {
32
            switch (algorithm)
×
33
            {
34
                case DocumentHashAlgorithm.SHA1: return new SHA1Managed();
×
35
                case DocumentHashAlgorithm.SHA256: return new SHA256Managed();
×
36
                case DocumentHashAlgorithm.MD5: return new MD5CryptoServiceProvider();
×
37
                default: return null;
×
38
            }
39
        }
40
    }
41
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc