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

loresoft / EntityFrameworkCore.Generator / 15072048022

16 May 2025 03:31PM UTC coverage: 55.392% (-1.4%) from 56.772%
15072048022

push

github

pwelter34
enable nullable support

616 of 1271 branches covered (48.47%)

Branch coverage included in aggregate %.

233 of 397 new or added lines in 61 files covered. (58.69%)

17 existing lines in 11 files now uncovered.

1824 of 3134 relevant lines covered (58.2%)

88.56 hits per line

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

85.51
/src/EntityFrameworkCore.Generator.Core/Parsing/ContextVisitor.cs
1
using System.Collections.Generic;
2
using System.Linq;
3

4
using EntityFrameworkCore.Generator.Extensions;
5
using EntityFrameworkCore.Generator.Metadata.Parsing;
6

7
using Microsoft.CodeAnalysis.CSharp;
8
using Microsoft.CodeAnalysis.CSharp.Syntax;
9

10
namespace EntityFrameworkCore.Generator.Parsing;
11

12
public class ContextVisitor : CSharpSyntaxWalker
13
{
14
    private string? _currentClass;
15

16
    public ContextVisitor()
5✔
17
    {
18
        DataSetTypes = ["DbSet", "IDbSet"];
5✔
19
    }
5✔
20

21
    public HashSet<string> DataSetTypes { get; set; }
45✔
22

23
    public ParsedContext? ParsedContext { get; set; }
89✔
24

25
    public override void VisitClassDeclaration(ClassDeclarationSyntax node)
26
    {
27
        var hasBaseType = node.BaseList
5!
28
            ?.DescendantNodes()
5✔
29
            .OfType<IdentifierNameSyntax>()
5✔
30
            .Any() == true;
5✔
31

32
        if (hasBaseType)
5✔
33
            _currentClass = node.Identifier.Text;
5✔
34

35
        base.VisitClassDeclaration(node);
5✔
36
    }
5✔
37

38
    public override void VisitPropertyDeclaration(PropertyDeclarationSyntax node)
39
    {
40
        ParseProperty(node);
41✔
41
        base.VisitPropertyDeclaration(node);
41✔
42
    }
41✔
43

44
    private void ParseProperty(PropertyDeclarationSyntax node)
45
    {
46
        if (_currentClass.IsNullOrEmpty())
41!
NEW
47
            return;
×
48

49
        var returnType = node.Type
41✔
50
            .DescendantNodesAndSelf()
41✔
51
            .OfType<GenericNameSyntax>()
41✔
52
            .FirstOrDefault();
41✔
53

54
        // expecting generic return type with 1 argument
55
        if (returnType == null || returnType.TypeArgumentList.Arguments.Count != 1)
41✔
56
            return;
1✔
57

58
        var returnName = returnType.Identifier.ValueText;
40✔
59
        if (!DataSetTypes.Contains(returnName))
40!
60
            return;
×
61

62
        var firstArgument = returnType
40✔
63
            .TypeArgumentList
40✔
64
            .Arguments
40✔
65
            .FirstOrDefault();
40✔
66

67
        if (firstArgument == null)
40!
NEW
68
            return;
×
69

70
        // last identifier is class name
71
        var className = firstArgument
40✔
72
            .DescendantNodesAndSelf()
40✔
73
            .OfType<IdentifierNameSyntax>()
40✔
74
            .Select(s => s.Identifier.ValueText)
160✔
75
            .LastOrDefault();
40✔
76

77
        var propertyName = node.Identifier.ValueText;
40✔
78

79
        if (string.IsNullOrEmpty(className) || string.IsNullOrEmpty(propertyName))
40!
80
            return;
×
81

82
        ParsedContext ??= new ParsedContext { ContextClass = _currentClass };
40✔
83

84
        var entitySet = new ParsedEntitySet
40✔
85
        {
40✔
86
            EntityClass = className,
40✔
87
            ContextProperty = propertyName
40✔
88
        };
40✔
89

90
        ParsedContext.Properties.Add(entitySet);
40✔
91
    }
40✔
92
}
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