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

lucaslorentz / minicover / #188

23 Dec 2024 10:05AM UTC coverage: 35.0%. First build
#188

push

azure-devops

lucaslorentz
Instrumentation fix for assemblies with generated code.

0 of 7 new or added lines in 2 files covered. (0.0%)

903 of 2580 relevant lines covered (35.0%)

7699.14 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 (document.Url.EndsWith(".g.cs"))
×
13
                return false;
×
14

15
            if (!File.Exists(document.Url))
×
16
            {
17
                // Ignore not found source generated files because they might be in memory
NEW
18
                if (document.Url.EndsWith(".g.cs"))
×
NEW
19
                    return false;
×
20

21
                return true;
×
22
            }
23

24
            using (var stream = File.OpenRead(document.Url))
×
25
            {
26
                var hasher = CreateHashAlgorithm(document.HashAlgorithm);
×
27

28
                if (hasher == null)
×
29
                    return false;
×
30

31
                using (hasher)
×
32
                {
33
                    var newHash = hasher.ComputeHash(stream);
×
34
                    return !newHash.SequenceEqual(document.Hash);
×
35
                }
36
            }
37
        }
38

39
        private static HashAlgorithm CreateHashAlgorithm(DocumentHashAlgorithm algorithm)
40
        {
41
            switch (algorithm)
×
42
            {
43
                case DocumentHashAlgorithm.SHA1: return new SHA1Managed();
×
44
                case DocumentHashAlgorithm.SHA256: return new SHA256Managed();
×
45
                case DocumentHashAlgorithm.MD5: return new MD5CryptoServiceProvider();
×
46
                default: return null;
×
47
            }
48
        }
49
    }
50
}
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

© 2026 Coveralls, Inc