• 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/PowerShellAccessorLoggingDecorator.cs
1
using Kysect.CommonLib.Exceptions;
2
using Kysect.CommonLib.Logging;
3
using Kysect.PowerShellRunner.Abstractions.Accessors;
4
using Kysect.PowerShellRunner.Abstractions.Accessors.Results;
5
using Kysect.PowerShellRunner.Abstractions.Objects;
6
using Kysect.PowerShellRunner.Abstractions.Queries;
7
using Kysect.PowerShellRunner.Extensions;
8
using Microsoft.Extensions.Logging;
9

10
namespace Kysect.PowerShellRunner.Accessors;
11

12
public class PowerShellAccessorLoggingDecorator(IPowerShellAccessor innerImplementation, ILogger logger)
13
    : IPowerShellAccessor
14
{
15
    public IPowerShellExecutionResult Execute(PowerShellQuery query)
16
    {
UNCOV
17
        if (query.ContainsSensitiveInfo)
×
18
        {
UNCOV
19
            logger.LogDebug("Execute PowerShell command with sensitive data. Query will not be logged.");
×
20
        }
21
        else
22
        {
23
            string executableQuery = query.Format();
×
24
            logger.LogDebug($"Execute PowerShell command: {executableQuery}");
×
25
        }
26

UNCOV
27
        IPowerShellExecutionResult result = innerImplementation.Execute(query);
×
28
        switch (result)
29
        {
30
            case PowerShellFailedExecutionResult failedPowerShellExecutionResult:
UNCOV
31
                logger.LogError("PS command executed failed.");
×
UNCOV
32
                if (failedPowerShellExecutionResult.Errors.Any())
×
33
                {
34
                    logger.LogError("Errors:");
×
35
                    foreach (string error in failedPowerShellExecutionResult.Errors)
×
UNCOV
36
                        logger.LogTabError(1, error);
×
37
                }
38

UNCOV
39
                if (failedPowerShellExecutionResult.OtherMessages.Any())
×
40
                {
UNCOV
41
                    logger.LogError("Other messages:");
×
42
                    foreach (string otherMessage in failedPowerShellExecutionResult.OtherMessages)
×
43
                        logger.LogTabError(1, otherMessage);
×
44
                }
45

46
                break;
47

48
            case PowerShellSuccessExecutionResult successPowerShellExecutionResult:
UNCOV
49
                logger.LogDebug("PS command executed successfully.");
×
50
                foreach (IPowerShellObject powerShellObject in successPowerShellExecutionResult.Output)
×
UNCOV
51
                    logger.LogPowerShellObject(powerShellObject);
×
52
                break;
53

54
            default:
UNCOV
55
                throw SwitchDefaultExceptions.OnUnexpectedType(result);
×
56
        }
57

UNCOV
58
        return result;
×
59
    }
60

61
    protected virtual void Dispose(bool disposing)
62
    {
UNCOV
63
        innerImplementation.Dispose();
×
UNCOV
64
    }
×
65

66
    public void Dispose()
67
    {
UNCOV
68
        Dispose(disposing: true);
×
69
    }
×
70
}
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