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

samsmithnz / DotNetCensus / 19020512321

03 Nov 2025 12:31AM UTC coverage: 81.387% (+0.04%) from 81.347%
19020512321

push

github

web-flow
Merge pull request #197 from samsmithnz/FixToDotNet10Tests

Fix to tests

488 of 622 branches covered (78.46%)

Branch coverage included in aggregate %.

1038 of 1253 relevant lines covered (82.84%)

1147.23 hits per line

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

97.77
/src/DotNetCensus.Core/Projects/ProjectClassification.cs
1
using System.Text;
2

3
namespace DotNetCensus.Core.Projects;
4

5
public static class ProjectClassification
6
{
7
    public static bool IsProjectFile(string fileName, bool primaryScan = true)
8
    {
15,081✔
9
        if (primaryScan)
15,081✔
10
        {
10,666✔
11
            switch (new FileInfo(fileName).Extension.ToLower())
10,666✔
12
            {
13
                case ".csproj":
14
                case ".sqlproj":
15
                case ".vbproj":
16
                case ".fsproj":
17
                case ".vbp":
18
                    return true;
1,670✔
19
            }
20
        }
8,996✔
21
        else
22
        {
4,415✔
23
            switch (fileName.ToLower())
4,415✔
24
            {
25
                case "project.json":
26
                case "web.config":
27
                    return true;
78✔
28
            }
29
        }
4,337✔
30
        return false;
13,333✔
31
    }
15,081✔
32

33
    public static string GetFrameworkFamily(string frameworkCode)
34
    {
2,371✔
35
        if (string.IsNullOrEmpty(frameworkCode))
2,371✔
36
        {
72✔
37
            return "(Unknown)";
72✔
38
        }
39
        else if (frameworkCode.StartsWith("netstandard"))
2,299✔
40
        {
377✔
41
            return ".NET Standard";
377✔
42
        }
43
        else if (frameworkCode.StartsWith("v1.") ||
1,922✔
44
                 frameworkCode.StartsWith("v2.") ||
1,922✔
45
                 frameworkCode.StartsWith("v3.") ||
1,922✔
46
                 frameworkCode.StartsWith("v4.") ||
1,922✔
47
                 frameworkCode.StartsWith("net3") ||
1,922✔
48
                 frameworkCode.StartsWith("net4") ||
1,922✔
49
                 frameworkCode.StartsWith("Unity"))
1,922✔
50
        {
751✔
51
            return ".NET Framework";
751✔
52
        }
53
        else if (frameworkCode.StartsWith("netcoreapp"))
1,171✔
54
        {
335✔
55
            return ".NET Core";
335✔
56
        }
57
        else if (frameworkCode.StartsWith("net")) //net5.0, net6.0, etc)
836✔
58
        {
793✔
59
            return ".NET";
793✔
60
        }
61
        else if (frameworkCode.StartsWith("vb6"))
43✔
62
        {
38✔
63
            return "Visual Basic 6";
38✔
64
        }
65
        else
66
        {
5✔
67
            return "(Unknown)";
5✔
68
        }
69
    }
2,371✔
70

71
    public static string GetFriendlyName(string frameworkCode, string family)
72
    {
1,487✔
73
        if (string.IsNullOrEmpty(frameworkCode))
1,487✔
74
        {
45✔
75
            return "(Unknown)";
45✔
76
        }
77
        else if (frameworkCode.StartsWith("netstandard"))
1,442✔
78
        {
238✔
79
            return family + " " + frameworkCode.Replace("netstandard", "");
238✔
80
        }
81
        else if (frameworkCode.StartsWith("v1.") ||
1,204✔
82
                 frameworkCode.StartsWith("v2.") ||
1,204✔
83
                 frameworkCode.StartsWith("v3.") ||
1,204✔
84
                 frameworkCode.StartsWith("v4."))
1,204✔
85
        {
364✔
86
            //Drop the v from the version string. (e.g. v3.0 becomes 3.0)
87
            return family + " " + frameworkCode.Replace("v", "");
364✔
88
        }
89
        else if (frameworkCode == "net40-client")
840✔
90
        {
22✔
91
            return family + " 4.0";
22✔
92
        }
93
        else if (frameworkCode.StartsWith("net3") ||
818✔
94
            frameworkCode.StartsWith("net4"))
818✔
95
        {
87✔
96
            string number = frameworkCode.Replace("net", "");
87✔
97
            StringBuilder formattedNumber = new();
87✔
98
            formattedNumber.Append(family);
87✔
99
            formattedNumber.Append(' ');
87✔
100
            //Add .'s between each number. Gross. (e.g. net462 becomes 4.6.2)
101
            for (int i = 0; i < number.Length; i++)
650✔
102
            {
238✔
103
                formattedNumber.Append(number[i]);
238✔
104
                if (i < number.Length - 1)
238✔
105
                {
151✔
106
                    formattedNumber.Append('.');
151✔
107
                }
151✔
108
            }
238✔
109
            return formattedNumber.ToString();
87✔
110
        }
111
        else if (frameworkCode.StartsWith("netcoreapp"))
731✔
112
        {
212✔
113
            return family + " " + frameworkCode.Replace("netcoreapp", "");
212✔
114
        }
115
        else if (frameworkCode.StartsWith("net")) //net5.0, net6.0, etc)
519✔
116
        {
494✔
117
            return family + " " + frameworkCode.Replace("net", "");
494✔
118
        }
119
        else if (frameworkCode.StartsWith("vb6"))
25✔
120
        {
23✔
121
            return "Visual Basic 6";
23✔
122
        }
123
        else
124
        {
2✔
125
            return "(Unknown)";
2✔
126
        }
127
    }
1,487✔
128

129
    public static string GetHistoricalFrameworkVersion(string line)
130
    {
233✔
131
        string productVersion = line.Replace("<ProductVersion>", "").Replace("</ProductVersion>", "").Replace("ProductVersion = ", "").Replace("\"", "").Trim();
233✔
132
        //https://en.wikipedia.org/wiki/Microsoft_Visual_Studio#History
133
        //+---------------------------+---------------+-----------+----------------+
134
        //|       Product name        |   Codename    | Version # | .NET Framework | 
135
        //+---------------------------+---------------+-----------+----------------+
136
        //| Visual Studio .NET (2002) | Rainier       | 7.0.*     | 1              |
137
        //| Visual Studio .NET 2003   | Everett       | 7.1.*     | 1.1            |
138
        //| Visual Studio 2005        | Whidbey       | 8.0.*     | 2.0, 3.0       |
139
        //| Visual Studio 2008        | Orcas         | 9.0.*     | 2.0, 3.0, 3.5  |
140
        //| Visual Studio 2010        | Dev10/Rosario | 10.0.*    | 2.0 – 4.0      |
141
        //| Visual Studio 2012        | Dev11         | 11.0.*    | 2.0 – 4.5.2    |
142
        //| Visual Studio 2013        | Dev12         | 12.0.*    | 2.0 – 4.5.2    |
143
        //| Visual Studio 2015        | Dev14         | 14.0.*    | 2.0 – 4.6      |
144
        //+---------------------------+---------------+-----------+----------------+
145

146
        //Only process the earliest Visual Studio's, as the later versions should be picked up by the product version
147
        //Note that this may not be entirely accurate - for example, VS2008 could ignore a .NET 3 version, but these should be pretty rare - even if it misidentifies .NET framework 1/2/3 - the story is the same - these are wildly obsolete and need to be resolved.
148
        if (productVersion.StartsWith("7.0"))
233✔
149
        {
21✔
150
            return "v1.0";
21✔
151
        }
152
        else if (productVersion.StartsWith("7.1"))
212✔
153
        {
21✔
154
            return "v1.1";
21✔
155
        }
156
        else if (productVersion.StartsWith("8.0"))
191✔
157
        {
105✔
158
            return "v2.0";
105✔
159
        }
160
        else
161
        {
86✔
162
            return "";
86✔
163
        }
164
    }
233✔
165

166
    //public static string GetUnityFrameworkVersion(string line)
167
    //{
168
    //    //An example of what to expect:
169
    //    //m_EditorVersion: 2020.3.12f1
170
    //    //m_EditorVersionWithRevision: 2020.3.12f1(b3b2c6512326)
171
    //    string fullVersion = line.Replace("m_EditorVersion:", "").Trim();
172
    //    string[] splitVersion = fullVersion.Split('.');
173
    //    string unityVersion = "";
174
    //    if (splitVersion.Length >= 2)
175
    //    {
176
    //        unityVersion = "Unity3d v" + splitVersion[0] + "." + splitVersion[1];
177
    //    }
178

179
    //    return unityVersion;
180
    //}
181

182
    // get a color to represent the support. Highlights old deprecated, soon to be out of support, and current versions.
183
    public static string? GetStatus(string? framework)
184
    {
2,027✔
185
        if (framework == null)
2,027!
186
        {
×
187
            //Unknown/gray
188
            return "unknown";
×
189
        }
190
        else if (framework == "vb6" ||
2,027✔
191
            framework.Contains("v1") ||
2,027✔
192
            framework.Contains("v2") ||
2,027✔
193
            framework.Contains("v3.0") ||
2,027✔
194
            framework.Contains("v4.0") ||
2,027✔
195
            framework.Contains("v4.1") ||
2,027✔
196
            framework.Contains("v4.2") ||
2,027✔
197
            framework.Contains("v4.3") ||
2,027✔
198
            framework.Contains("v4.4") ||
2,027✔
199
            framework.Contains("v4.5") ||
2,027✔
200
            framework.Contains("net40") ||
2,027✔
201
            framework.Contains("net45") || //Unclear if this should be net45 or v4.5 - I've seen both in wild
2,027✔
202
            framework == "v4.6" || //Unclear if these should be net46 or v4.6 - I've seen both samples in the wild
2,027✔
203
            framework == "v4.6.1" || 
2,027✔
204
            framework == "net46" ||
2,027✔
205
            framework == "net461" ||
2,027✔
206
            framework.Contains("netcoreapp1") ||
2,027✔
207
            framework.Contains("netcoreapp2") ||
2,027✔
208
            framework.Contains("netcoreapp3") ||
2,027✔
209
            framework.Contains("netcoreapp5") || //details about netcoreapp5 are unclear, but this scenario was mentioned as supported here: https://github.com/dotnet/designs/blob/main/accepted/2020/net5/net5.md
2,027✔
210
            framework.Contains("net5.0") ||
2,027✔
211
            framework.Contains("net6.0") ||
2,027✔
212
            framework.Contains("net7.0"))
2,027✔
213
        {
1,004✔
214
            //Unsupported/End of life/red
215
            return "deprecated";
1,004✔
216
        }
217
        else if (framework == "net462" ||
1,023✔
218
            framework == "v4.6.2")
1,023✔
219
        {
33✔
220
            //Supported, but old/orange
221
            return "EOL: 12-Jan-2027";
33✔
222
        }
223
        else if (framework.Contains("v3.5") ||
990✔
224
            framework == "net35")
990✔
225
        {
76✔
226
            //Supported, but old/orange
227
            return "EOL: 9-Jan-2029";
76✔
228
        }
229
        else if (
914✔
230
            framework.Contains("net10.0") || //EOL: Nov ??, 2028
914✔
231
            framework.Contains("net9.0") || //EOL: Nov 10, 2026
914✔
232
            framework.Contains("net8.0") || //EOL: Nov 10, 2026
914✔
233
            framework.Contains("netstandard") ||
914✔
234
            framework.Contains("net47") ||
914✔
235
            framework.Contains("v4.7") ||
914✔
236
            framework.Contains("net48") ||
914✔
237
            framework.Contains("v4.8"))
914✔
238
        {
825✔
239
            //Supported/Ok/blue
240
            return "supported";
825✔
241
        }
242
        else if (framework.Contains("net11.0"))
89✔
243
        {
33✔
244
            return "in preview";
33✔
245
        }
246
        else
247
        {
56✔
248
            //Unknown/gray
249
            return "unknown";
56✔
250
        }
251
    }
2,027✔
252

253
    public static string GetLanguage(string directory)
254
    {
85✔
255
        string language;
256
        //Check to see if it's a VB.NET or C# project
257
        int csFiles = new DirectoryInfo(directory).GetFiles("*.cs", SearchOption.AllDirectories).Length;
85✔
258
        int vbFiles = new DirectoryInfo(directory).GetFiles("*.vb", SearchOption.AllDirectories).Length;
85✔
259
        if (csFiles >= vbFiles)
85!
260
        {
85✔
261
            language = "csharp";
85✔
262
        }
85✔
263
        else
264
        {
×
265
            language = "vb.net";
×
266
        }
×
267
        return language;
85✔
268
    }
85✔
269
}
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