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

kysect / PowerShellRunner / 9198794632

22 May 2024 09:43PM UTC coverage: 57.061%. Remained the same
9198794632

push

github

FrediKats
Update nugets

165 of 401 branches covered (41.15%)

Branch coverage included in aggregate %.

0 of 2 new or added lines in 1 file covered. (0.0%)

17 existing lines in 2 files now uncovered.

1225 of 2035 relevant lines covered (60.2%)

3.22 hits per line

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

0.0
/Sources/Kysect.PowerShellRunner.CodeGeneration/SdkGenerating/PowerShellSchemaCodeGenerator.cs
1
using Kysect.CommonLib.BaseTypes.Extensions;
2
using Kysect.CommonLib.FileSystem;
3
using Kysect.PowerShellRunner.CodeGeneration.SchemaGenerating;
4
using Kysect.PowerShellRunner.CodeGeneration.UsedModelSearching;
5
using Microsoft.CodeAnalysis;
6
using Microsoft.CodeAnalysis.CSharp.Syntax;
7
using System.IO.Abstractions;
8

9
namespace Kysect.PowerShellRunner.CodeGeneration.SdkGenerating;
10

11
public class PowerShellSchemaCodeGenerator
12
{
13
    private readonly string _outputPath;
14
    private readonly string _namespaceName;
15
    private readonly IPowerShellCodeGeneratorNamespaceProvider _namespaceProvider;
16
    private readonly FileSystem _fileSystem;
17

18
    public PowerShellSchemaCodeGenerator(string outputPath, string namespaceName, IPowerShellCodeGeneratorNamespaceProvider namespaceProvider)
19
    {
UNCOV
20
        _outputPath = outputPath;
×
UNCOV
21
        _namespaceName = namespaceName;
×
22
        _namespaceProvider = namespaceProvider;
×
NEW
23
        _fileSystem = new FileSystem();
×
24
    }
×
25

26
    public void GenerateSdkCode(PowerShellSchemaDto powerShellSchema)
27
    {
UNCOV
28
        powerShellSchema.ThrowIfNull();
×
29

UNCOV
30
        foreach (ModelEnumTypeDescriptor enumTypeDescriptor in powerShellSchema.Enums)
×
31
        {
UNCOV
32
            EnumDeclarationSyntax generateEnumDeclaration = EnumCodeGenerator.GenerateEnumDeclaration(enumTypeDescriptor);
×
33
            string directoryPath = Path.Combine(_outputPath, "Enums");
×
UNCOV
34
            WriteToCsFile(directoryPath, enumTypeDescriptor.Name, generateEnumDeclaration, _namespaceProvider.GetForEnum(enumTypeDescriptor));
×
35
        }
36

37
        foreach (SimpleModelDescriptor simpleModelDescriptor in powerShellSchema.Models)
×
38
        {
UNCOV
39
            var simpleModelGenerator = new SimpleModelGenerator();
×
40
            ClassDeclarationSyntax classDeclarationSyntax = simpleModelGenerator.Generate(simpleModelDescriptor);
×
UNCOV
41
            string directoryPath = Path.Combine(_outputPath, "Models");
×
42
            WriteToCsFile(directoryPath, simpleModelDescriptor.Name, classDeclarationSyntax, _namespaceProvider.GetForModel(simpleModelDescriptor));
×
43
        }
44

45
        foreach (PowerShellCmdletDescriptor cmdletDescriptor in powerShellSchema.CmdletDescriptors)
×
46
        {
UNCOV
47
            var cmdletDescriptorGenerator = new CmdletDescriptorGenerator();
×
48
            ClassDeclarationSyntax cmdletClass = cmdletDescriptorGenerator.Generate(cmdletDescriptor);
×
49

50
            string directoryPath = _outputPath;
×
51
            foreach (string featureName in cmdletDescriptor.Scope)
×
UNCOV
52
                directoryPath = Path.Combine(directoryPath, featureName);
×
53

54
            WriteToCsFile(directoryPath, cmdletDescriptor.CmdletAttributeValues.GetClassName(), cmdletClass, _namespaceProvider.GetForCmdlet(cmdletDescriptor));
×
55
        }
UNCOV
56
    }
×
57

58
    private void WriteToCsFile(string directoryPath, string typeName, MemberDeclarationSyntax declarationSyntax, string[] usingList)
59
    {
NEW
60
        _fileSystem.EnsureDirectoryExists(directoryPath);
×
UNCOV
61
        string fullPath = Path.Combine(directoryPath, $"{typeName}.g.cs");
×
UNCOV
62
        string content = CodeGenerationNamespaceWrapper.Wrap(declarationSyntax, _namespaceName, usingList).NormalizeWhitespace().ToString();
×
63

64
        File.WriteAllText(fullPath, content);
×
65
    }
×
66
}
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