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

lucaslorentz / auto-compute / 11750234612

08 Nov 2024 10:06PM UTC coverage: 81.44% (-0.9%) from 82.369%
11750234612

push

github

lucaslorentz
Add initial support for computed navigations and observers

151 of 307 new or added lines in 14 files covered. (49.19%)

42 existing lines in 5 files now uncovered.

1448 of 1778 relevant lines covered (81.44%)

116.07 hits per line

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

33.33
/src/LLL.AutoCompute.EFCore/Metadata/Internal/ComputedFactory.cs
1
using System.Linq.Expressions;
2
using LLL.AutoCompute.EFCore.Internal;
3
using Microsoft.EntityFrameworkCore.Metadata;
4

5
namespace LLL.AutoCompute.EFCore.Metadata.Internal;
6

7
public delegate Computed ComputedFactory<TTarget>(
8
    IComputedExpressionAnalyzer<IEFCoreComputedInput> analyzer,
9
    TTarget target);
10

11
public class ComputedFactory
12
{
13
    public static ComputedFactory<IProperty> CreateComputedPropertyFactory<TEntity, TProperty, TValue, TChange>(
14
        Expression<Func<TEntity, TValue>> computedExpression,
15
        IChangeCalculation<TValue, TChange> changeCalculation,
16
        Func<TProperty, TChange, TProperty> applyChange)
17
        where TEntity : class
18
    {
19
        return (analyzer, property) =>
12✔
20
        {
12✔
21
            try
12✔
22
            {
12✔
23
                var changesProvider = analyzer.GetChangesProvider(
18✔
24
                    computedExpression,
18✔
25
                    default,
18✔
26
                    changeCalculation);
18✔
27

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

12✔
31
                return new ComputedProperty<TEntity, TProperty, TChange>(
18✔
32
                    property,
18✔
33
                    changesProvider,
18✔
34
                    computedExpression,
18✔
35
                    applyChange);
18✔
36
            }
12✔
37
            catch (Exception ex)
12✔
38
            {
12✔
39
                throw new InvalidOperationException($"Invalid computed expression for '{property.DeclaringType.ShortName()}.{property.Name}': {ex.Message}", ex);
12✔
40
            }
12✔
41
        };
12✔
42
    }
43

44
    public static ComputedFactory<INavigationBase> CreateComputedNavigationFactory<TEntity, TProperty, TValue, TChange>(
45
        Expression<Func<TEntity, TValue>> computedExpression,
46
        IChangeCalculation<TValue, TChange> changeCalculation,
47
        Func<TProperty, TChange, TProperty> applyChange)
48
        where TEntity : class
49
        where TProperty : class
50
    {
NEW
51
        return (analyzer, navigation) =>
×
NEW
52
        {
×
NEW
53
            try
×
NEW
54
            {
×
NEW
55
                var changesProvider = analyzer.GetChangesProvider(
×
NEW
56
                    computedExpression,
×
NEW
57
                    default,
×
NEW
58
                    changeCalculation);
×
NEW
59

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

×
NEW
63
                return new ComputedNavigation<TEntity, TProperty, TChange>(
×
NEW
64
                    navigation,
×
NEW
65
                    changesProvider,
×
NEW
66
                    computedExpression,
×
NEW
67
                    applyChange);
×
NEW
68
            }
×
NEW
69
            catch (Exception ex)
×
NEW
70
            {
×
NEW
71
                throw new InvalidOperationException($"Invalid computed expression for '{navigation.DeclaringType.ShortName()}.{navigation.Name}': {ex.Message}", ex);
×
NEW
72
            }
×
NEW
73
        };
×
74
    }
75

76
    public static ComputedFactory<IEntityType> CreateComputedObserverFactory<TEntity, TValue, TChange>(
77
        Expression<Func<TEntity, TValue>> computedExpression,
78
        IChangeCalculation<TValue, TChange> changeCalculation,
79
        Func<ComputedChangeEventData<TEntity, TChange>, Task> callback)
80
        where TEntity : class
81
    {
NEW
82
        return (analyzer, entityType) =>
×
NEW
83
        {
×
NEW
84
            try
×
NEW
85
            {
×
NEW
86
                var changesProvider = analyzer.GetChangesProvider(
×
NEW
87
                    computedExpression,
×
NEW
88
                    default,
×
NEW
89
                    changeCalculation);
×
NEW
90

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

×
NEW
94
                return new ComputedObserver<TEntity, TChange>(
×
NEW
95
                    entityType,
×
NEW
96
                    changesProvider,
×
NEW
97
                    computedExpression,
×
NEW
98
                    callback);
×
NEW
99
            }
×
NEW
100
            catch (Exception ex)
×
NEW
101
            {
×
NEW
102
                throw new InvalidOperationException($"Invalid computed expression for reaction in '{entityType.Name}': {ex.Message}", ex);
×
NEW
103
            }
×
NEW
104
        };
×
105
    }
106
}
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