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

kysect / PowerShellRunner / 9758853126

02 Jul 2024 09:56AM UTC coverage: 56.868%. Remained the same
9758853126

push

github

FrediKats
Add IPowerShellObjectMapper

165 of 401 branches covered (41.15%)

Branch coverage included in aggregate %.

12 of 22 new or added lines in 3 files covered. (54.55%)

16 existing lines in 3 files now uncovered.

1222 of 2038 relevant lines covered (59.96%)

3.23 hits per line

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

37.5
/Sources/Kysect.PowerShellRunner/Executions/PowerShellAccessorCmdletExecutionContext.cs
1
using Kysect.PowerShellRunner.Abstractions.Accessors;
2
using Kysect.PowerShellRunner.Abstractions.Cmdlets;
3
using Kysect.PowerShellRunner.Abstractions.Objects;
4
using Kysect.PowerShellRunner.Abstractions.Queries;
5
using Kysect.PowerShellRunner.Abstractions.Variables;
6
using Kysect.PowerShellRunner.Mapping;
7
using Kysect.PowerShellRunner.QueryBuilding;
8

9
namespace Kysect.PowerShellRunner.Executions;
10

11
public class PowerShellAccessorCmdletExecutionContext<T> where T : notnull
12
{
13
    private readonly IPowerShellAccessor _accessor;
14
    private readonly IPowerShellCmdlet<T> _cmdlet;
15
    private readonly List<Func<PowerShellQuery, PowerShellQuery>> _morphisms;
16
    private readonly PowerShellObjectMapper _powerShellObjectMapper;
17

18
    public PowerShellAccessorCmdletExecutionContext(IPowerShellAccessor accessor, IPowerShellCmdlet<T> cmdlet)
19
    {
20
        _cmdlet = cmdlet;
1✔
21
        _accessor = accessor;
1✔
22

23
        _powerShellObjectMapper = PowerShellObjectMapper.Instance;
1✔
24
        _morphisms = new List<Func<PowerShellQuery, PowerShellQuery>>();
1✔
25
    }
1✔
26

27
    public PowerShellAccessorCmdletExecutionContext<T> Continue(Func<PowerShellQuery, PowerShellQuery> morphism)
28
    {
29
        _morphisms.Add(morphism);
×
30
        return this;
×
31
    }
32

33
    public IReadOnlyCollection<T> Execute()
34
    {
35
        PowerShellQuery powerShellQuery = BuildQuery();
1✔
36

37
        return _accessor.ExecuteAndGet(powerShellQuery)
1✔
38
            .Select(_powerShellObjectMapper.Map<T>)
1✔
39
            .ToList();
1✔
40
    }
41

42
    public PowerShellVariable<T> ExecuteAndSetTo(string variableName)
43
    {
44
        var powerShellVariable = new PowerShellVariable(variableName);
×
45
        PowerShellQuery powerShellQuery = BuildQuery();
×
46
        return new PowerShellVariableInitializer(_accessor, powerShellVariable, _powerShellObjectMapper).With<T>(powerShellQuery);
×
47
    }
48

49
    private PowerShellQuery BuildQuery()
50
    {
51
        PowerShellQuery powerShellQuery = _cmdlet.BuildFromCmdlet();
1✔
52
        _morphisms.ForEach(morphism => powerShellQuery = morphism(powerShellQuery));
1✔
53
        return powerShellQuery;
1✔
54
    }
55
}
56

57
public class PowerShellAccessorCmdletExecutionContext
58
{
59
    private readonly IPowerShellAccessor _accessor;
60
    private readonly IPowerShellCmdlet _cmdlet;
61
    private readonly List<Func<PowerShellQuery, PowerShellQuery>> _morphisms;
62
    private readonly PowerShellObjectMapper _powerShellObjectMapper;
63

64
    public PowerShellAccessorCmdletExecutionContext(IPowerShellAccessor accessor, IPowerShellCmdlet cmdlet)
65
    {
UNCOV
66
        _cmdlet = cmdlet;
×
67
        _accessor = accessor;
×
68

69
        _powerShellObjectMapper = PowerShellObjectMapper.Instance;
×
NEW
70
        _morphisms = new List<Func<PowerShellQuery, PowerShellQuery>>();
×
UNCOV
71
    }
×
72

73
    public PowerShellAccessorCmdletExecutionContext Continue(Func<PowerShellQuery, PowerShellQuery> morphism)
74
    {
UNCOV
75
        _morphisms.Add(morphism);
×
UNCOV
76
        return this;
×
77
    }
78

79
    public IReadOnlyCollection<IPowerShellObject> Execute()
80
    {
UNCOV
81
        PowerShellQuery powerShellQuery = BuildQuery();
×
UNCOV
82
        return _accessor.ExecuteAndGet(powerShellQuery);
×
83
    }
84

85
    public PowerShellVariable ExecuteAndSetTo(string variableName)
86
    {
87
        var powerShellVariable = new PowerShellVariable(variableName);
×
UNCOV
88
        PowerShellQuery powerShellQuery = BuildQuery();
×
UNCOV
89
        return new PowerShellVariableInitializer(_accessor, powerShellVariable, _powerShellObjectMapper).With(powerShellQuery);
×
90
    }
91

92
    private PowerShellQuery BuildQuery()
93
    {
94
        PowerShellQuery powerShellQuery = _cmdlet.BuildFromCmdlet();
×
UNCOV
95
        _morphisms.ForEach(morphism => powerShellQuery = morphism(powerShellQuery));
×
UNCOV
96
        return powerShellQuery;
×
97
    }
98
}
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