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

lucaslorentz / auto-compute / 11758703019

09 Nov 2024 07:01PM UTC coverage: 77.208% (-2.7%) from 79.869%
11758703019

push

github

lucaslorentz
Add initial support for computed navigations and observers

160 of 425 new or added lines in 23 files covered. (37.65%)

41 existing lines in 7 files now uncovered.

1460 of 1891 relevant lines covered (77.21%)

109.64 hits per line

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

0.0
/src/LLL.AutoCompute.EFCore/Extensions/NavigationBuilderExtensions.cs
1
using System.Linq.Expressions;
2
using LLL.AutoCompute.EFCore.Metadata.Internal;
3
using Microsoft.EntityFrameworkCore.Metadata.Builders;
4

5
namespace LLL.AutoCompute.EFCore;
6

7
public static class NavigationBuilderExtensions
8
{
9
    public static NavigationBuilder<TEntity, TProperty> AutoCompute<TEntity, TProperty>(
10
        this NavigationBuilder<TEntity, TProperty> navigationBuilder,
11
        Expression<Func<TEntity, TProperty>> computedExpression)
12
        where TEntity : class
13
        where TProperty : class
14
    {
NEW
15
        return navigationBuilder.AutoCompute(computedExpression, static c => c.CurrentValue());
×
16
    }
17

18
    public static NavigationBuilder<TEntity, TProperty> AutoCompute<TEntity, TProperty>(
19
        this NavigationBuilder<TEntity, TProperty> navigationBuilder,
20
        Expression<Func<TEntity, TProperty>> computedExpression,
21
        ChangeCalculationSelector<TProperty, TProperty> calculationSelector)
22
        where TEntity : class
23
        where TProperty : class
24
    {
NEW
25
        var changeCalculation = calculationSelector(ChangeCalculations<TProperty>.Instance);
×
26

NEW
27
        navigationBuilder.Metadata.AddComputedFactory(
×
NEW
28
            ComputedFactory.CreateComputedNavigationFactory(
×
NEW
29
                computedExpression,
×
NEW
30
                changeCalculation));
×
31

NEW
32
        return navigationBuilder;
×
33
    }
34

35
    public static NavigationBuilder<TEntity, TProperty> Reaction<TEntity, TProperty, TValue>(
36
        this NavigationBuilder<TEntity, TProperty> navigationBuilder,
37
        Expression<Func<TEntity, TValue>> computedExpression,
38
        Func<TProperty, TValue, TProperty> mutator)
39
        where TEntity : class
40
        where TProperty : class
41
    {
NEW
42
        return navigationBuilder.Reaction(computedExpression, static c => c.CurrentValue(), mutator);
×
43
    }
44

45
    public static NavigationBuilder<TEntity, TProperty> AutoComputeKey<TEntity, TProperty, TKey>(
46
        this NavigationBuilder<TEntity, TProperty> navigationBuilder,
47
        Expression<Func<TProperty, TKey>> keyExpression,
48
        Expression<Func<TEntity, TKey>> computedExpression)
49
        where TEntity : class
50
        where TProperty : class
51
    {
NEW
52
        return navigationBuilder.AutoComputeKey(keyExpression, computedExpression, static c => c.CurrentValue());
×
53
    }
54

55
    public static NavigationBuilder<TEntity, TProperty> AutoComputeKey<TEntity, TProperty, TKey>(
56
        this NavigationBuilder<TEntity, TProperty> navigationBuilder,
57
        Expression<Func<TProperty, TKey>> keyExpression,
58
        Expression<Func<TEntity, TKey>> computedExpression,
59
        ChangeCalculationSelector<TKey, TKey> calculationSelector)
60
        where TEntity : class
61
        where TProperty : class
62
    {
NEW
63
        var changeCalculation = calculationSelector(ChangeCalculations<TKey>.Instance);
×
64

NEW
65
        navigationBuilder.Metadata.AddComputedFactory(
×
NEW
66
            ComputedFactory.CreateComputedNavigationKeyFactory(
×
NEW
67
                computedExpression,
×
NEW
68
                changeCalculation,
×
NEW
69
                keyExpression));
×
70

NEW
71
        return navigationBuilder;
×
72
    }
73

74
    public static NavigationBuilder<TEntity, TProperty> Reaction<TEntity, TProperty, TValue, TChange>(
75
        this NavigationBuilder<TEntity, TProperty> navigationBuilder,
76
        Expression<Func<TEntity, TValue>> computedExpression,
77
        ChangeCalculationSelector<TValue, TChange> calculationSelector,
78
        Func<TProperty, TChange, TProperty> applyChange)
79
        where TEntity : class
80
        where TProperty : class
81
    {
NEW
82
        var changeCalculation = calculationSelector(ChangeCalculations<TValue>.Instance);
×
83

NEW
84
        navigationBuilder.Metadata.AddComputedFactory(
×
NEW
85
            ComputedFactory.CreateComputedReactionFactory(
×
NEW
86
                computedExpression,
×
NEW
87
                changeCalculation,
×
NEW
88
                applyChange));
×
89

NEW
90
        return navigationBuilder;
×
91
    }
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

© 2025 Coveralls, Inc