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

kysect / PowerShellRunner / 9758848204

02 Jul 2024 09:56AM UTC coverage: 56.868% (-0.2%) from 57.061%
9758848204

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%)

50 existing lines in 6 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

0.0
/Sources/Kysect.PowerShellRunner/Accessors/PowerShellAccessor.cs
1
using Kysect.PowerShellRunner.Abstractions.Accessors;
2
using Kysect.PowerShellRunner.Abstractions.Accessors.Results;
3
using Kysect.PowerShellRunner.Abstractions.Queries;
4
using Kysect.PowerShellRunner.Accessors.Models;
5
using System.Collections.ObjectModel;
6
using System.Management.Automation;
7

8
namespace Kysect.PowerShellRunner.Accessors;
9

10
public class PowerShellAccessor(PowerShell powerShellInstance) : IPowerShellAccessor
11
{
12
    public IPowerShellExecutionResult Execute(PowerShellQuery query)
13
    {
UNCOV
14
        string fullCommand = query.Format();
×
15

UNCOV
16
        lock (powerShellInstance)
×
17
        {
UNCOV
18
            powerShellInstance.AddScript(fullCommand);
×
19
            Collection<PSObject> result = powerShellInstance.Invoke();
×
20

UNCOV
21
            IPowerShellExecutionResult methodResult = powerShellInstance.HadErrors
×
UNCOV
22
                ? CreateFailedResult(result)
×
UNCOV
23
                : CreateSuccessResult(result);
×
24

UNCOV
25
            powerShellInstance.Streams.ClearStreams();
×
26
            powerShellInstance.Commands.Clear();
×
UNCOV
27
            return methodResult;
×
28
        }
29
    }
×
30

31
    private PowerShellSuccessExecutionResult CreateSuccessResult(Collection<PSObject> result)
32
    {
33
        var resultItems = result
×
UNCOV
34
            .Where(p => p is not null)
×
35
            .Select(p => new PowerShellObject(p))
×
36
            .ToList();
×
37

UNCOV
38
        return new PowerShellSuccessExecutionResult(resultItems);
×
39
    }
40

41
    private PowerShellFailedExecutionResult CreateFailedResult(Collection<PSObject> result)
42
    {
43
        var errors = powerShellInstance.Streams.Error.ToList();
×
44
        var errorMessages = errors.Select(e => e.ToString()).ToList();
×
45

46
        var failedPowerShellExecutionResult = new PowerShellFailedExecutionResult(errorMessages, result
×
UNCOV
47
            .Where(r => r is not null)
×
48
            .Select(r => r.ToString())
×
UNCOV
49
            .ToList());
×
50

UNCOV
51
        return failedPowerShellExecutionResult;
×
52
    }
53

54
    protected virtual void Dispose(bool disposing)
55
    {
56
        powerShellInstance.Dispose();
×
57
    }
×
58

59
    public void Dispose()
60
    {
61
        Dispose(disposing: true);
×
UNCOV
62
    }
×
63
}
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