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

lucaslorentz / auto-compute / 11744711953

08 Nov 2024 03:11PM UTC coverage: 82.369%. First build
11744711953

push

github

lucaslorentz
Add initial support for computed navigations and observers

185 of 334 new or added lines in 17 files covered. (55.39%)

1509 of 1832 relevant lines covered (82.37%)

116.56 hits per line

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

32.84
/src/LLL.AutoCompute.EFCore/Metadata/Internal/ComputedFactory.cs
1
using System.Linq.Expressions;
2

3
namespace LLL.AutoCompute.EFCore.Metadata.Internal;
4

5
public class ComputedFactory
6
{
7
    public static ComputedPropertyFactory CreateComputedPropertyFactory<TEntity, TProperty, TValue>(
8
        Expression<Func<TEntity, TValue>> computedExpression,
9
        IChangeCalculation<TValue, TProperty> changeCalculation)
10
        where TEntity : class
11
    {
12
        return (analyzer, property) =>
12✔
13
        {
12✔
14
            try
12✔
15
            {
12✔
16
                var changesProvider = analyzer.GetChangesProvider(
18✔
17
                    computedExpression,
18✔
18
                    default,
18✔
19
                    changeCalculation);
18✔
20

12✔
21
                if (!changesProvider.EntityContext.AllAccessedMembers.Any())
18✔
22
                    throw new Exception("Computed expression doesn't have tracked accessed members");
12✔
23

12✔
24
                return new ComputedProperty<TEntity, TProperty>(
18✔
25
                    property,
18✔
26
                    changesProvider,
18✔
27
                    computedExpression);
18✔
28
            }
12✔
29
            catch (Exception ex)
12✔
30
            {
12✔
31
                throw new InvalidOperationException($"Invalid computed expression for '{property.DeclaringType.ShortName()}.{property.Name}': {ex.Message}", ex);
12✔
32
            }
12✔
33
        };
12✔
34
    }
35

36
    public static ComputedNavigationFactory CreateComputedNavigationFactory<TEntity, TProperty, TValue>(
37
        Expression<Func<TEntity, TValue>> computedExpression,
38
        IChangeCalculation<TValue, TProperty> changeCalculation)
39
        where TEntity : class
40
        where TProperty : class
41
    {
NEW
42
        return (analyzer, navigation) =>
×
NEW
43
        {
×
NEW
44
            try
×
NEW
45
            {
×
NEW
46
                var changesProvider = analyzer.GetChangesProvider(
×
NEW
47
                    computedExpression,
×
NEW
48
                    default,
×
NEW
49
                    changeCalculation);
×
NEW
50

×
NEW
51
                if (!changesProvider.EntityContext.AllAccessedMembers.Any())
×
NEW
52
                    throw new Exception("Computed expression doesn't have tracked accessed members");
×
NEW
53

×
NEW
54
                return new ComputedNavigation<TEntity, TProperty>(
×
NEW
55
                    navigation,
×
NEW
56
                    changesProvider,
×
NEW
57
                    computedExpression);
×
NEW
58
            }
×
NEW
59
            catch (Exception ex)
×
NEW
60
            {
×
NEW
61
                throw new InvalidOperationException($"Invalid computed expression for '{navigation.DeclaringType.ShortName()}.{navigation.Name}': {ex.Message}", ex);
×
NEW
62
            }
×
NEW
63
        };
×
64
    }
65

66
    public static ComputedObserverFactory CreateComputedObserverFactory<TEntity, TValue, TChange>(
67
        Expression<Func<TEntity, TValue>> computedExpression,
68
        IChangeCalculation<TValue, TChange> changeCalculation,
69
        Func<ComputedChangeEventData<TEntity, TChange>, Task> callback)
70
        where TEntity : class
71
    {
NEW
72
        return (analyzer, entityType) =>
×
NEW
73
        {
×
NEW
74
            try
×
NEW
75
            {
×
NEW
76
                var changesProvider = analyzer.GetChangesProvider(
×
NEW
77
                    computedExpression,
×
NEW
78
                    default,
×
NEW
79
                    changeCalculation);
×
NEW
80

×
NEW
81
                if (!changesProvider.EntityContext.AllAccessedMembers.Any())
×
NEW
82
                    throw new Exception("Computed expression doesn't have tracked accessed members");
×
NEW
83

×
NEW
84
                return new ComputedObserver<TEntity, TChange>(
×
NEW
85
                    entityType,
×
NEW
86
                    changesProvider,
×
NEW
87
                    computedExpression,
×
NEW
88
                    callback);
×
NEW
89
            }
×
NEW
90
            catch (Exception ex)
×
NEW
91
            {
×
NEW
92
                throw new InvalidOperationException($"Invalid computed expression for reaction in '{entityType.Name}': {ex.Message}", ex);
×
NEW
93
            }
×
NEW
94
        };
×
95
    }
96
}
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